Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

TCP communication in Matlab/Simulink

MetaKnightMetaKnight Posts: 1Member
Hello,

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:
[code]
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.
fopen(t);


end

[/code]

and this second function is supposed to receive the string, parse the string, and store it in an array:
[code]
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, ';');

end

end
[/code]

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.