TCP communication in Matlab/Simulink


I'm working on a project that requires various computersto receive data from a C++ program via TCP. I coded the C++ program, which sends out data sets related to our process in a character string every 5 milliseconds, with individual values and I've been able to successfully do to code to communicate between different computers whether through C, C++, Java, even Labview programs, but for some reason we can't seem to get the communication to work with Matlab/Simulink.

I'm not well versed in Matlab, but I'm trying to help my teammate who is working on the Simulink simulation. I did some Googling, and came up with a couple of m functions that I hoped could be put in Simulink blocks, but no luck.

Here's the first function I made, which is meant to simply connect to the second computer at the start of the program:
function initCom()
t = tcpip('x.xx.xx.x', 55555);

% Set size of receiving buffer, if needed.
set(t, 'InputBufferSize', 30000);

% Open connection to the server.



and this second function is supposed to receive the string, parse the string, and store it in an array:
function recv( t )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here

DataReceived = fscanf(t)
for i=1:6
t{k}= strtok(DataReceived, ';');



It seems that the 'initCom' function doesn't work, as we get connection timeouts. Would anybody have any idea how to get things working?

Thanks for reading.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!