# Decoding 30001 port to get alarms/logs

**URL:** <https://forum.universal-robots.com/t/decoding-30001-port-to-get-alarms-logs/17746>\
**Category:** Technical Questions\
**Created:** [November 22, 2021, 12:54pm UTC](https://forum.universal-robots.com/t/decoding-30001-port-to-get-alarms-logs/17746 "2021-11-22T12:54:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon42518650](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@anon42518650](https://forum.universal-robots.com/u/anon42518650)\
**Post date:** [November 22, 2021, 12:54pm UTC](https://forum.universal-robots.com/t/decoding-30001-port-to-get-alarms-logs/17746/1 "2021-11-22T12:54:32Z")

</div>

Hello,

I want to get the alarms/logs from the UR robot, to have something similar to the log\_history.txt, but in real time. In the RTDE communication I haven’t found something related to this events, so I have started using 30001 port. My version is URSoftware 5.11.1.108318.

In some other posts, I have read that the interesting subpackages of this communication are SafetyModeMessage (subpackage = 5, RobotCommMessage (subpackage = 6) and RuntimeExceptionMessage (subpackage = 10) from Robot Message (message\_type = 20).

I am trying to decode this messages, but I don’t get to decode correctly. These are some examples about what I am receiving in message\_type = 20:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/7/76c036d72738df34e6b9afc6603dc3ce61c059b6.png)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/8/87768ddcb5bef49d504a3bdcef230d8cf4db2262.png)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/9/9f10ba050fef815207aa448ea27827a5db2dadd9.png)

I am using this Python code sample:

```auto
#!/usr/bin/env python
# encoding: utf=8

""" 
#UR Controller Client Interface Datastream Reader
# For software version 3.x
#
# Datastream info found here: https://s3-eu-west-1.amazonaws.com/ur-support-site/16496/Client_Interface.xlsx
# Struct library used to extract data, info found here: https://docs.python.org/2/library/struct.html
"""

import socket, struct

def main():

	#Establish connection to controller
	HOST = '192.168.1.10'
	PORT = 30001

	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
	s.connect((HOST, PORT))

	while 1:
		#Loop forever, receive 4096 bytes of data (enough to store any packet)
		data = s.recv(4096)
		#initialise i to keep track of position in packet
		i = 0
		if data:
			#Print title to screen
			#extract packet length, timestamp and packet type from start of packet and print to screen
			packlen = (struct.unpack('!i', data[0:4]))[0]
			print 'packet length: ' + str(packlen)
			packtype = (struct.unpack('!b', data[4]))[0]
			print 'packet type: ' + str(packtype)
			if packlen < 20:
				continue

			timestamp = (struct.unpack('!Q', data[10:18]))[0]
			print 'timestamp: ' + str(timestamp)

			if packtype == 20:
				print(data)

if __name__ == ' __main__':
	import sys
	main()

```

Can someone help me?

Thanks!

---

<div class="post-metadata">

**Author:** ![moliveira](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@moliveira](https://forum.universal-robots.com/u/moliveira)\
**Post date:** [November 22, 2021, 2:54pm UTC](https://forum.universal-robots.com/t/decoding-30001-port-to-get-alarms-logs/17746/2 "2021-11-22T14:54:14Z")

</div>

Here is an example to get the safety status, you can change the line safe= int(number[139]) to get the values you need.

def getSocket():  
global s  
s = socket.socket(socket.AF\_INET, socket.SOCK\_STREAM)  
s.connect((HOST, PORT))

def getSafe():  
global s  
getSocket()  
data = s.recv(1116)  
number = struct.unpack(’!i139d’, data)   
safe = int(number[139])  
#print(repr(new))  
return safe

---

<div class="post-metadata">

**Author:** ![anon42518650](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@anon42518650](https://forum.universal-robots.com/u/anon42518650)\
**Post date:** [November 22, 2021, 3:16pm UTC](https://forum.universal-robots.com/t/decoding-30001-port-to-get-alarms-logs/17746/3 "2021-11-22T15:16:29Z")

</div>

Hello,

I don’t understand very well the relation between safety status and the value 139. Is there a table with the variable relationships?

Thank you!

---

<div class="post-metadata">

**Author:** ![moliveira](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@moliveira](https://forum.universal-robots.com/u/moliveira)\
**Post date:** [November 22, 2021, 3:25pm UTC](https://forum.universal-robots.com/t/decoding-30001-port-to-get-alarms-logs/17746/4 "2021-11-22T15:25:26Z")

</div>

Yes, there is a table lookup.  
you can find more information in here:

[https://www.universal-robots.com/articles/ur/interface-communication/overview-of-client-interfaces/](https://www.universal-robots.com/articles/ur/interface-communication/overview-of-client-interfaces/)

Download the file Client\_interfaces\_1.1.3 here, the info you want is located on the last few excel pages:  
[https://www.universal-robots.com/articles/ur/interface-communication/remote-control-via-tcpip/](https://www.universal-robots.com/articles/ur/interface-communication/remote-control-via-tcpip/)

---

<div class="post-metadata">

**Author:** ![anon42518650](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@anon42518650](https://forum.universal-robots.com/u/anon42518650)\
**Post date:** [November 23, 2021, 12:59pm UTC](https://forum.universal-robots.com/t/decoding-30001-port-to-get-alarms-logs/17746/5 "2021-11-23T12:59:38Z")

</div>

Hello,

Thank you for your help, but your code doesn’t work for me. As you told me, I have used this code sample:

```auto
#!/usr/bin/env python
# encoding: utf=8

import socket, struct

HOST = '192.168.1.10'
PORT = 30001

def getSocket():
	global s
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.connect((HOST, PORT))

def getSafe():
	global s
	getSocket()
	data = s.recv(1116)
	number = struct.unpack('!i139d', data)
	safe = int(number[139])
	#print(repr(new))
	return safe

a = getSafe()
print(a)

```

But I have received this error message:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/c/c0c01b0dbc7b826403101daa232362103b0efcdf.png)

Then I have tried with this code to detect messages with packtype = 20:

```auto
#!/usr/bin/env python
# encoding: utf=8

import socket, struct

def main():
	HOST = '192.168.1.10'
	PORT = 30001

	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
	s.connect((HOST, PORT))

	while 1:
		data = s.recv(4096)
		if data:
			packlen = (struct.unpack('!i', data[0:4]))[0]
			packtype = (struct.unpack('!b', data[4]))[0]
			if packtype == 20:
				print 'packet length: ' + str(packlen)
				print 'packet type: ' + str(packtype)
				message_type = (struct.unpack('!b', data[14]))[0]
				print 'message_type: ' + str(message_type) + "\n"

if __name__ == ' __main__':
	import sys
	main()

```

I have received this result:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/7/730432da0f9e94206326d11e41e8a7c9e9dfe214.png)

I have received only two messages with packtype = 20, and they have been at the start of the script (in the following minutes they haven’t appeared).

The first message has message\_type = 3. As I can read in [https://s3-eu-west-1.amazonaws.com/ur-support-site/16496/ClientInterfaces\_Primary.pdf](https://s3-eu-west-1.amazonaws.com/ur-support-site/16496/ClientInterfaces_Primary.pdf) is **3.1.16. Version Message (sent only once)**. This is the first package sent on both the primary and secondary client interfaces. This package it is not part of the robot state message.

Then I have received a message\_type = 12 and in the documentation I don’t find any message with this robotMessageType.

I don’t understand why I’m not receiving other Robot Messages, such as, Safety Mode Message (robotMessageType=5), Robot Comm Message (robotMessageType=6)… I have tried with both 30001 and 30011 ports. I am running this python code in a Linux computer connected with the controller via Ethernet cable.

Thanks!

---

<div class="post-metadata">

**Author:** ![moliveira](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@moliveira](https://forum.universal-robots.com/u/moliveira)\
**Post date:** [November 23, 2021, 2:10pm UTC](https://forum.universal-robots.com/t/decoding-30001-port-to-get-alarms-logs/17746/6 "2021-11-23T14:10:49Z")

</div>

My example is using the RTDE ports, and if you are doing anything that requires fast communications or at least faster than 10Hz or 0.1s, I strongly suggest using RTDE with the update rate of 500 Hz or 0.002s.

For the primary it seems that you packet length should be data[0:3], data[4] is your message type, and data[14] could be content or length of subpackage.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/1/1c6debd46bd4a17fcb24ada7443885a688e89e44.png)

---

<div class="post-metadata">

**Author:** ![anon42518650](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@anon42518650](https://forum.universal-robots.com/u/anon42518650)\
**Post date:** [November 23, 2021, 2:27pm UTC](https://forum.universal-robots.com/t/decoding-30001-port-to-get-alarms-logs/17746/7 "2021-11-23T14:27:33Z")

</div>

I started using 30001 port because I haven’t found any way to read logs/alarms via RTDE.  
My goal is to have events from log\_history.txt read in real time.

---

<div class="post-metadata">

**Author:** ![anon75712119](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@anon75712119](https://forum.universal-robots.com/u/anon75712119)\
**Post date:** [November 25, 2021, 6:04am UTC](https://forum.universal-robots.com/t/decoding-30001-port-to-get-alarms-logs/17746/8 "2021-11-25T06:04:51Z")

</div>

If you want to receive Safety Mode Message by Pressing Emergency Button but that also not gives proper data like mentioned in that document. message type 20 will only receive if any specific condition met After first two packages.
