Communication with an external device via Ethernet on URCap

The original idea was to to transfer data, (simple Coil and Registers) with ModbusTCP from the urcap to establish communication with the Arduino and this was initially successful but

Problem with Modbus TCP / IP communication between URCap and Arduino (a library on Arduino that enables ModbusTCP over Ethernet). Communication is established and the code works for some time say 50 cycles of repetition and then it happens to stop:

a similar problem is described in the commentary of this post - MiR and UR Communications - Modbus TCP - #5 by torrey.bievenour

but no one has written a possible reason:
“sometime ur will pop up an error ‘modbus signal disconnect with the device’,I must refresh the ur modbus button and can run the program again”

So I’m thinking of some other kind of communication, let’s say:
Is it possible that the Python Daemon in URCap not only communicates with the Controller via XML-RPC but also communicates with an external device via Ethernet communication?

Example: the user in URCap enters some values ​​in the fields, it is sent to Python Damen via XML-RPC and then in the background Python sends a message via Ethernet to another device (in my case it is Arduino with Ethernet Shield)

or there is some other easier option?

1 Like

Well yes, there is no reason why not. I have recently worked on project where with comms " robot runtime → daemon → tcp/ip socket" .

In my case i wrote script to exchange predefined data payload with external device (64bytes) and access it sort of like modbus registers via xml-rpc.

i got something like this in daemon:

def socket_comm():

global data_for_plc
global data_from_plc
global plc_connected
global plc_buffer
plc_connected = False
while True:
    if (plc_ip != "") and (plc_port != 0):
        if not plc_connected:
            try:
                plc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                plc_socket.settimeout(5)
                plc_socket.connect((plc_ip, plc_port))
                plc_connected = True
            except:
                pass
            time.sleep(0.2)
        else:
            try:
                rcv_data = plc_socket.recv(64)
                plc_buffer = bytearray(rcv_data)
                send_data = create_bytes(data_for_plc)
                plc_socket.send(send_data)
                if len(plc_buffer) == 64:
                    data_from_plc = decode_bytes(plc_buffer)
                    machine_io()
                time.sleep(0.01)
            except:
                plc_connected = False
                time.sleep(0.1)
                pass

other side just listens for client connection and basicly does the same

1 Like

Hi,

It should be noted that MODBUS/TCP has strict timing deadlines, e.g. requires clients to respond within a max of 100msec to any information exchange. Failing to do so is treated as an error and the connection will be shut down by the server, as per standard.

Make sure your client can meet this deadline (typically 10Hz or 100msec) or this behaviour will occur.

2 Likes

Hi @martin.korbel, I have a question, which port did you use, since my application freezes after trying to communicate with external device, so i want to eliminate all possible errors?

and whether it was necessary to add a socket library in a folder?