1. Home
  2. Knowledge Base
  3. MODBUS registers and nodes

MODBUS registers and nodes.

Application Description:

This example shows the use of internal MODBUS registers on the Universal-Robots and also using external MODBUS nodes.

The application uses the MODBUS server running at port 502 on the Universal-Robots. The MODBUS server has a range of register available with dedicated content and register 128 to 255 is for general purpose use.

A list of the MODBUS and register can be found at this link UR Modbus page

The commands are send from a external host with Python code.

Function description:

The nodes used are Beckhoff model

BK 9050 = Modbus Controller with Ethernet port for IP configuration.
KL 1408 = Modbus 8 port input module.
KL 2408 = Modbus 8 port output module.
KL 9010 = Modbus End terminator.

universal-robots-zacobria-modbus-nodes-4

The IP address of the Modbus node has to be defined in the Robot configuration.

universal-robots-zacobria-modbus-registers-configuration-5
universal-robots-zacobria-modbus-registers-configuration-6

I/O table Inputs:

Variable Table:
var_1 = Modbus signal from external Modbus node (bit 0)
var_2 = Value of register 128 (set by remote host)

Electrical diagrams.

Program description:
As this program is for testing the MODBUS interface the robot program has only one waypoint.

Then the status of MODBUS node input 0 is read into variable var_1. Followed by reading the value register 128.

Then register 129 is toggled between the value 05 and value 00 with a 1 sec interval.

In parallel program Thread_1 the MODBUS output 0 is toggled between 1 and 0.

In parallel program Thread_2 the MODBUS output 4 is set same value as MODBUS input 0.

Program code:

universal-robots-zacobria-modbus-registers-urp-program-1

Host program in Python code.

universal-robots-zacobria-modbus-registers-host-program-2
universal-robots-zacobria-modbus-registers-host-program-3

 

# Echo client program
import socket
import time

HOST = "192.168.0.9" # The remote host
PORT_502 = 502
PORT_29999 = 29999
PORT_30002 = 30002 # The same port as used by the server

print "Starting Program"

count = 0
home_status = 0
program_run = 0

while (True):

 if 1 == 1:
 
 if program_run == 0:
 try:
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.settimeout(10)
 s.connect((HOST, PORT_502))
 time.sleep(0.05)
 print ""
 print "Modbus set reg 128 to 01"
 print "Sending: x00 x01 x00 x00 x00 x06 x00 x06 x00 x80 x00 x01"
 s.send ("\x00\x01\x00\x00\x00\x06\x00\x06\x00\x80\x00\x01") #sets register 128 to 1
 time.sleep(1.00)
 print ""
 print "Modbus set reg 128 to 00"
 print "Sending: x00 x01 x00 x00 x00 x06 x00 x06 x00 x80 x00 x00"
 s.send ("\x00\x01\x00\x00\x00\x06\x00\x06\x00\x80\x00\x00") #sets register 128 to 0
 time.sleep(1.00)
 s.close() #clear buffer
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.settimeout(10)
 s.connect((HOST, PORT_502))
 time.sleep(0.05)
 print ""
 print "Request reg 129"
 print "Sending: x00 x04 x00 x00 x00 x06 x00 x03 x00 x81 x00 x01"
 msg = ""
 s.send ("\x00\x04\x00\x00\x00\x06\x00\x03\x00\x81\x00\x01") #request data from register 128-133 (cartisian data)
 print "Modbus command send to read reg 129"
 time.sleep(0.75)
 print "Received"
 msg = s.recv(1024)
 print repr(msg) #Print the receive data in \x hex notation (notice that data above 32 hex will berepresented at the ascii code e.g. 50 will show P
 print ""
 msg = msg.encode("hex") #convert the data from \x hex notation to plain hex
 print msg
 print ""
 home_status = 1
 program_run = 0
 s.close()
 except socket.error as socketerror:
 print("Error: ", socketerror)
print "Program finish"

Program run:

The var_1 is getting the value of True and False according to the settings of input 0 on the external MODBUS node.

universal-robots-zacobria-modbus-registers-program-run-7

universal-robots-zacobria-modbus-registers-program-run-8

The MODBUS output 0 is toggleing between True and False with a 1 second interval as controlled by Thread_1

universal-robots-zacobria-modbus-registers-program-run-9

 

universal-robots-zacobria-modbus-registers-program-run-10

Data received on the external host with description below.

universal-robots-zacobria-modbus-registers-host-program-run-11

Notes:
Data exchange using the Python program:

Modbus Data send to UR to write UR register.

First request to write.

Data send
\x00\x01\x00\x00\x00\x06\x00\x06\x00\x80\x00\x01

Which is the same as
00 01 00 00 00 06 00 06 00 80 00 01

Meaning:
00 01 is the sequence number Modbus TCP follows (Sequence no = Transaction identifier (serial no)
00 00 is protocol indentifier
00 06 messages length – means 6 bytes will follow
00 Unit identifier – or slave address
06 is the function code for write
00 80 The address of the first register to set                         (register 80hex = 128 dec).
00 01 The value to set into register 128                                  (set value to 1)

Second request to write.

Data send.
\x00\x01\x00\x00\x00\x06\x00\x06\x00\x80\x00\x00

Which is the same as
00 01 00 00 00 06 00 06 00 80 00 00

Meaning:
00 01 is the sequence number Modbus TCP follows (Sequence no = Transaction identifier (serial no)
00 00 is protocol indentifier
00 06 messages length – means 6 bytes will follow
00 Unit identifier – or slave address
06 is the function code for write
00 80 The address of the first register to set                               (register 80hex = 128 dec).
00 00 The value to set into register 128                                        (set value to 0)

Modbus Data send to UR to read UR register.

\x00\x04\x00\x00\x00\x06\x00\x03\x00\x81\x00\x01

Which is the same as
00 04 00 00 00 06 00 03 00 81 00 01

Meaning:
00 04 is the sequence number Modbus TCP follows (Sequence no = Transaction identifier (serial no)
00 00 is protocol indentifier
00 06 messages length – means 6 bytes will follow
00 Unit identifier – or slave address
03 is the function code for read
00 81 The data address of the first register requested                 (register 81hex = 129 dec).
00 01 The total number of register requested

Data received from UR

First poll received:

0004000000050003020000

Meaning:
00 04 is the sequence number that Modbus TCP follow (same as in the request send i.e. replied to)
00 00 Protocol identifier
00 05 messages length – means 5 bytes will follow
03 was the function code requested
02 registeres are read
00 00 is data value received.

Another pool received.

0004000000050003020005

Meaning:
00 04 is the sequence number that Modbus TCP follow (same as in the request send i.e. replied to)
00 00 Protocol identifier
00 05 messages length – means 5 bytes will follow
03 was the function code requested
02 registeres are read
00 05 is data value received.

universal-robots-zacobria-modbus-registers-host-program-run-14

 

universal-robots-zacobria-modbus-registers-host-program-run-13

 

Disclaimer: While the Zacobria Pte. Ltd. believes that information and guidance provided is correct, parties must rely upon their skill and judgement when making use of them. Zacobria Pte. Ltd. assumes no liability for loss or damage caused by error or omission, whether such an error or omission is the result of negligence or any other cause. Where reference is made to legislation it is not to be considered as legal advice. Any and all such liability is disclaimed.

If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.

Author:
By Zacobria Lars Skovsgaard
Accredited Universal Robots support Centre and Forum.

Also check out the CB3 forum



Was this article helpful?

5 comments

  1. Hello,

    first of all, I find your articles very helpful!
    My question is:
    The picture showing the overview of all Modbus DIs and DOs tells me to use modbus addresses from 0 to 7 for both inputs and outputs. However, we use more than just one output module. Do we need to continue the modbus addresses with 8 to 15 and so on?

    Thanks for your help.
    Jannis

    1. Hello Jannis

      Thanks for the question.

      The register address will depend on the vendor of the nodes and also the function and configuration of the nodes. You might need to consult the vendor of the node modules.

      Because the nodes can also be mixed as Digital Input nodes – Digital Output nodes – Analogue Input nodes – Analogue output nodes – and also the number of ports on each node used in the actual situation will have a role.

      In one situation for example with a 4 port Analogue Input node – a 8 port Digital Input node – a 8 port Digital Output node and a 4 port Analogue Output node – it could look something like this below, but it might be different in other cases depending of type and brand of nodes used.

      Register Address:
      0000 = Analogue Input to be read
      0008 = Digital Input
      2056 = Digital Output
      2048 = Analogue Output

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum



      1. Thank you for your fast reply.

        We are using exactly the same nodes from Beckhoff.
        1x BK 9050 = Modbus Controller with Ethernet port for IP configuration.
        1x KL 1408 = Modbus 8 port input module.
        4x KL 2408 = Modbus 8 port output module.
        1x KL 9010 = Modbus End terminator.

        I will check the manual.

  2. Hi everybody,

    I would appreciate if someone could tell me with which version of URControl the MODBUS-Server on Port 502 was introduced? I’m working on an UR5 with URControl 1.5.7849 and successfully transmitted some URScript-commands to the robot from a laptop via socket connection at port 30002. After that I tried to establish a socket connection to port 502 to read some register values but the robot denied connection every time I tried. This was when I began to think that the MODBUS-Server wasn’t build in at earlier versions of URControl but I can find no information about that.

    I’m looking forward to hearing from you.

    Regards
    Mathias

    1. Hi Mathias

      Thanks for your question.

      I happen to have a UR5-CB2 image with software version 1.4.6732 that I tried to install and here are my findings.

      The MODBUS menu is inside the Installation tab – so it is possible to add external MODBUS nodes on this version. However when I try to access Port 502 via Ethernet there is no response.

      I do not have a version 1.5, but I have a version 1.6.9558 and that one has some response when accessing Port 502 – however when I read register 400-405 which is the position data I get a odd reply that is not the correct position data. So I am guessing that 1.5 also not yet support port MODBUS 502.

      When I load back the current version I use on the UR5-CB2 robot which is version 1.8.14035 , then when I access port 502 and read registers 400 – 405 I get the correct reply for the position data.

      Author:
      By Zacobria Lars Skovsgaard
      Accredited Universal Robots support Centre and Forum.

      Also check out the CB3 forum

Leave a Reply

Your email address will not be published. Required fields are marked *