Simulink TCP/IP sending strings (via uint8)
6 views (last 30 days)
Show older comments
I'm trying to send a string over TCP/IP. I'm able to do this in Matlab, but for various reasons I need to get the equivalent functionality in simulink. The matlab code I wrote (which works) is as follows:
simin = [0,0,0,0,0,0];
ts=tcpip('192.168.1.2',12000,'NetworkRole','server');
fopen(ts);
while true
tic;
while toc<1
continue;
end
if simin(1)<50
simin(1) = simin(1)+1;
else
simin(1) = 0;
end
fwrite(ts, [num2str(simin(1)) ',0,0,0,0,0']);
end
Moving this to simulink, I get the following (attached a larger picture if hard to see):

Everything in the blue box is directly from the simulink target-to-target communication (so I assume it works). I'm just trying to change the input (initially a sine wave) to match what I want my input to be. The build error I receive here is as follows:
Rapid accelerator simulation and External simulation are not supported when the model contains Simulink string data type.
However, I'm running in "Normal" mode, so I can't figure out why this error is arising or how to fix it.
Any help would be appreciated (including different ways to approach the same problem - as long at its still in simulink - not matlab).
Thanks!
3 Comments
Walter Roberson
on 7 Jan 2019
Sending over tcp/ip would not require switching to Simulink.
What it might require is looking in the File Exchange for the tcpudpip contribution that would permit you to use tcp without the Instrument Control Toolbox. That could be important if you wanted to compile.
Answers (1)
Walter Roberson
on 7 Jan 2019
The only context in which Simulink can deal with characters, is locally within a MATLAB Function Block. It can never use characters as signals.
The work-around for signals is to send uint8() of the character vector, probably padded with null or blanks to a fixed width. Or to send the numeric data into a MATLAB Function Block that does the
ts=tcpip('192.168.1.2',12000,'NetworkRole','server');
on initialization, and does
fwrite(ts, [num2str(simin(1)) ',0,0,0,0,0']);
at each step.
2 Comments
Walter Roberson
on 8 Jan 2019
Simulink Real Time product has client and server TCP blocks.
But I am still unclear as to your reasons for switching to Simulink ? Because if you do happen to be deploying to hardware then it is possible that there are tcp blocks specific to the hardware.
See Also
Categories
Find more on Development Computer Setup in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!