TCP/IP and UDP communication

Benefits of TCP/IP and UDP

Connectivity between devices is become very common and often beneficial essentially in industrial devices communication. Although Modbus, RS485 serial communications have its place still in industrial control and measurement applications, TCP/IP and UDP offers so much diversity that even apps written for I-phone and android could be used to connect with complete production line rolling a car every minute or 1000 milk bottles a minute. It would be indeed great fun to control humungous 400 tonne press machine rolling and flattening steel metal sheet in to car body parts all controlled through slim design apple phone fitting nicely in your pocket. TCP/IP and UDP have indeed opened up options for programmers and system engineers to make two devices connect seamlessly easily.

 Architecture of TCP/IP and UDP

The architecture to achieve connectivity via TCP/IP and UDP has become very simple due to a very modular way hardware and systems have evolved over the last two decades. Today there is a fine abstaction level between apps written in any programming language and hardware yet there are so many layers that transmitted and received data passes through. For app developers, they are only interested in ‘TCP/IP or UDP socket library’. Library contains subroutines and functions for them to establish connection, send data, receive data and perform whatever they wish.

“Code developers need software development key SDK that contains libraries of functions to  access tCp/ip and udp socket within device firmware”

Coders would never worry how parameters passed through these functions are passed on to OS and firmware that handles all network layers i.e Application layer, transport layer, network layer and data link layer to the ether net cable  and finally reassembled and communicated to device connected on the other end of the ethernet cable.TCP IP layers

Relationship between firmware, hardware and OS is beyond the scope of this topic which is merely written to guide developers create a well-architect communication system between industrial devices.

Difference between UDP and TCP/IP

This article is not focused on listing detailed differences in terms of layers and protocols. Both comms method connect devices via ethernet or wireless between devices. TCP/IP is guaranteed packet transfer without packet loss – if packet does not get through, sender node sends it again until acknowledgement is received that packet was received. On the other hand, UDP protocol does not have packet acknowledgement process and might result in data packets losing between devices.

Applications of TCP/IP and UDP

Use TCP/IP when you are developing mission-critical or data-critical application where you need to ensure that you receive every communicate every bit of data during communication. For instance, an actuator motion profile where scientists needs to capture ‘spikes’ in data, you must prefer TCP/IP over UDP. You might as well wish to design a circular buffer system to ensure large amount of data is sent via packets over TCP/IP rather than instantaneous data of small packets. On the other-hand, if all you interested is to display status of current speed reading on a PC display to operator, then I would not hesitate to stick with UDP.

Cleaner and Organised approach to handle device communication.

Lastly, I wanted to give a quick overview of a very organised way that engineers and developers use today to communicate between industrial devices communication. I would suggest such approach is incorporated when you want to create communication channel between two devices in your project.

  • Design your app such that position, velocity, and other real number data is sent as a 4-bytes.
  • Pack all discretes as a 2-byte word.

Reason for the above is that nearly all Programmable Logic Controllers PLC, SCADA, motion controllers map the memory and communicate in above fashion of bytes. If you have developed your C or Java app to write your speed as a 4-byte command then you are very close to successfully drive motion axis of 6-axis delta robot picking and placing car body part from one press to another.

Signal Control Word

Like I said, pack all digital inputs as 2-byte word so 16 bits are 16 different commands. A bit command could be to switch on a motor drive. Another bit command could be to turn on relay to move hydraulic ram out of the way. You can have up to 16 different commands per signal control word for your application.

Signal Status Word

Likewise, arrange all the status bit as 16 bit word. A status bit could be to monitor safety door. Another status bit could be to ensure axis is in home position.

Establish Data Packet Telegram

Once you are satisfied in your program app that you have put together all commands, status and data, determine how many bytes communication you require between your app and industrial device. For instance, for a two-byte signal control word, 2 byte signal status word, 4-byte position command, you require a UDP or TCP/IP packet of 8-bytes. When you pack your data as a cluster of eight byte and send it over ethernet cable, industrial device on the receiving end then needs to be set up in similar order receive the 8-byte packets.

“Due to differences in chip, some devices might need byte swapping”

You must also check with manufacturers of devices to ensure byte order is compatible. Often you might require byte swapping to make sense of received packet telegram. I hope this article provides a neat architecture and programming practices to develop a good communication app.