PLC TCP communication with several datatypes

We want to send and receive multiple data types over a TCP connection for communication with the robot (e.g. a float array for a position, a bool to see if the robot is running, several integers to send commands and amounts); what is the best way to go about this?

So far we’ve considered to use several TSEND/TRCV blocks, but that seems inefficient.

Ideally we’d use something like a MUX or SEL block to toggle between various inputs and outputs, but MUX and SEL need all inputs to be of the same datatype.

@4lloyd

To be honest, I think the easiest way is to use multiple blocks.

If you only want to have one TSEND/TRCV block, then you should convert all data to/from bytes. In the end, the TCP protocol (ethernet) is only sending bytes, and the software (and the people) gives the meaning to the bits and bytes.

To send data with variable length you can set the “LEN” parameter of TSEND. To receive variable length data you need to set the “ADHOC” parameter to true. The RCVD_LEN will show how much bytes are received. For both ways the datablock cannot be optimized (right click on DB -> Properties… -> Attributes -> Uncheck “Optimized block access”). You also need a way to find out which data was sent. Because, for example, a real or a double int are both equally long (4 bytes).

With the S7-1500 (more advanced PLC than the S7-1200) there are some options to do this, but at SMR we don’t have those.

If you want some extra information of have questions, let me know :slight_smile:.