03-27-2015 01:54 PM
Hi!
I am creating a tcp/ip communication between labview and matlab. I am trying to send different information at the same time, strings and arrays mostly from Matlab to Labview. I used a template that I found in internet that uses Java language and from there I have been doing modifications.
This is the first time that I work with tcp/ip communication, for that matter until now I have been only able to send one string to Labview and convert it array, from there on I have been stuck, I cannot visualize the second string sent.
The code from Matlab does not give me errors and it seems to be that sends the information, but I do not know how to reach the second string sent.
Can anybody help me please?
Thank you very much!!
03-27-2015 02:44 PM
That's not a good tester VI. You have everything in a while loop together, no idea when things are happening, waiting on reads and writes in the same loop, waiting forever for 2000000 bytes to show up, and more.
You also close the connections immediately after the read / write operations (for some reason you close one of the connections twice). Do you know that you don't even need two separate connections?
It's possible that you aren't seeing anything past the initial connection and string because your VI is waiting to finish its first iteration of that huge while loop.
I haven't looked at your MATLAB code yet.
04-02-2015 10:20 AM - edited 04-02-2015 10:22 AM
Hi VItan,
Thank you very very much for answering, so what you suggest is to put everything in different loops? and no, I did not know that with only one connection was possible. This is the first time that I have been working with Labview and have not found to many examples of tcp/ip communication in the way that I am doing, since I want it to be receiving and sending data at the same time.
I really do need help, so please which would be your suggestions?
Hope to hear from you soon
04-02-2015 10:57 AM
For just a quick test, I would use something like this to connect and send/receive data:
I didn't include converting it from the bytestream string to array, but it should be simple to make a conversion SubVI and use it with the read string.
04-08-2015 12:08 PM - edited 04-08-2015 12:10 PM
Hello once again!
Thanks very much! I have tried the code for several days while at the same time doing some modifications specially on the Matlab since perhap there was the mistake, but the connection between Labview and Matlab does not occurs. Both programs do not seem to present by themselves any problem with code, simply they do not connect when I run them simultaneously using localhost
Hope to hear from you, either way thanks for your time in helping me
04-09-2015 07:34 AM
I would try a simple connection first to make sure that you have things working.
I haven't investigated your original MATLAB code, but you may want to consider simply using MATLAB's tcpip object first. For example, in MATLAB:
% Create the tcpip object in the server NetworkRole
My_Connection = tcpip('localhost', 2057, 'NetworkRole', 'server');
% Listen on the socket. This will wait forever until a connection is made.
fopen(My_Connection);
%%
% Once we get to this point, the connection is active. Use fread and fwrite to interact with the stream.
%%
% Disconnect and delete the tcpip object
fclose(My_Connection);
delete(My_Connection);
clear My_Connection;
04-15-2015 11:15 AM
Hi VItan I managed to get working everything! Thanks very much, and I managed to get the string into a array as well, but I have several question that would might help me understand some stuff:
the only format that the information is passing from Matlab to Labview if I use "regexprep(num2str(Vout2(1),6),'\.',',')" converting the data of for example Vout2 vector into num2str and using that expression while at the same time changing it to ",". Is it the only format that Labview accepts? or do you know of any other way?
Also I am trying to send several information and to be saved in different arrays and numeric indicators lets say I write:
fwrite(Connection,data_to_send_serie);
fwrite(Connection,data_to_send_serie1);
fwrite(Connection,data_to_send_serie2);
But if I try to do several tcp read I do not seem to extract each information, in other words one array for data_to_send_serie other for data_to_send_serie1 and so on, it is just received into one single string. So far if I only send one fwrite it does create the array but that is it.
I have been trying unsuccessfully to do this, maybe you have some idea that might help me do this.
Thank you very much once again!!
04-16-2015 04:09 PM
TCP is a connection-based octet-stream protocol. This means two things related to your questions:
04-20-2015 12:42 PM
VItan thanks for your explanation specially regarding communications between platform and how tcp/ip works, once more has become helpful!. It is a nice suggestion and very tempting the idea of using UDP but sadly it is demanded to be done by tcp/ip and through Labview 😕 those are the two requirements that I have been impose. You say that there exist some techniques, some path that I could follow? any direction to it? seriously I have been running out of ideas in this aspect......