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):
Capture.JPG
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 个评论
Geoff Horowitz
Geoff Horowitz 2019-1-7
I'm sending to another computer over TCP/IP (a linux machine if it matters).
Walter Roberson
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
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 个评论
Geoff Horowitz
Geoff Horowitz 2019-1-7
Thanks for your help Walter. I was trying to avoid using function blocks, but I think your solution is right. I'm just surprised I can't do this fully in simulink.....
To answer your earlier question, the Instrument Control Toolbox (at least the one I have) only has a client block, not a server block. Thats why I went in this direction.
Walter Roberson
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 CenterFile Exchange 中查找有关 Development Computer Setup 的更多信息

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by