Decoding 30001 port to get alarms/logs

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:



I am using this Python code sample:

#!/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!

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

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!

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/

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/

1 Like

Hello,

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

#!/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

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

#!/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

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 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!

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.

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.

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.