How to process package recieved from port 30002 in Python

HI!

I’ve recently been trying to receive robot readings from port 30002 using Sockets in Python. I’ve looked into how to process the package received in this thread here:

But the code examples posted are outdated and leaves me with errors.
I’ve also looked into the client_Interfaces.xlsx, but it seems to be outdated perhaps too?

Anyways, i am trying to receive readings on the Robot mode data, more specifically to check for protective stop.
How would i go about processing the package with the Struct librabry in python 3?
Or if someone could explain to me how to unpack the data stream from port 30002 that would be of great help too!

I have Solved the issue. If anyone stumbles upon the same problem, i would gladly share my implementation

Great to hear you’ve resolved it. Was it just a case of updating the indices to reflect the current data structure?

Yes that was exactly the problem.

Hi, could you share it? I have been going through the same issue and I updated some indices, but it still does not work for me.
A link to a repository in GitHub or similar would be great :smile:

It’s around 3 months since i’ve last used the script, so i quiet frankly don’t remember how exactly i got it to work. I don’t have an active repo with the code, but here is the code snippet.

As far as i can remember,it prints the 3 states; is_program_running, is_protective_stopped, is_robot_on.

    while cycles > count:
                print('\n')
                data = self.SOCKET.recv(4096)
                # size = sys.getsizeof(data)
                # print(size)
                i = 0
                package_length = (struct.unpack('!i', data[0:4]))[0]
                package_type = (struct.unpack('!B', data[4:5]))[0]
    
                if package_type == 16:
                    while i + 5 < package_length:
                        message_length = (struct.unpack('!i', data[5 + i:9 + i]))[0]
                        message_type = (struct.unpack('!B', data[9:10]))[0]
    
                        if message_type == 0:
                            sub_package = data[5:i + message_length]
                            is_program_running = struct.unpack('!?', sub_package[18:19])[0]
                            is_protective_stop = struct.unpack('!?', sub_package[17:18])[0]
                            is_robot_on = struct.unpack('!?', sub_package[15:16])[0]
    
                            print('Is robot on: ' + str(is_robot_on) + '\n' +
                                  'Is protective stopped: ' + str(is_protective_stop) + '\n' +
                                  'is program running: ' + str(is_program_running) + '\n' +
                                  'Count: ' + str(count) + '\n')
                            time.sleep(0.1)
                            count += 1
                            break
                        i = message_length + i
1 Like