Simulink TCP/IP sending strings (via uint8)
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2019-1-7
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.
回答(1 个)
Walter Roberson
2019-1-7
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 个评论
Walter Roberson
2019-1-8
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Development Computer Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!