Simulink Real-Time TCP Send variable size data input
4 views (last 30 days)
Maximilian Perschl on 18 Sep 2020
I am trying to create a communication interface in simulink real-time where i have to send data of variable size (e.g. I have messages like start/stop which are just a header of constant size, but I also have messages with an attached payload of variable size). I cycle through the desired data using multiport-switch blocks which support inputs of variable size. The TCP Send block of the real-time toolbox however, does not support this. This seems counterintuitive, given as it also takes a length input specifying how long the data input is. Am I overlooking some configuration options in the block?
If not, what is the recommended way to send variable size data via TCP in simulink real-time? My current idea is to apply zero-padding to my data vectors to alter them to a constant size for all cases, while relying on the length input to convince the TCP send block to only send the data I want to send. Would this work? If not, what alternatives are there?
Any help would be greatly appreciated!
Diego Kuratli on 24 Sep 2020
The approach you suggest is correct.
The Data vector should be defined with the expected maximum length. You can control the data that is effectively transmitted with the Length port.
Example: if you have a Data vector of size 100, but the Length port value is 70, only the first 70 elements of the vector are transmitted (the others are ignored)