LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing Data to Matlab over TCP/IP

Hi all, 

 

I am trying to send data from LabVIEW (client) to Matlab (server) using TCP/IP connection and made two simple examples (Test 1 & Test 2). In Test 1, after establishing the connection, LabVIEW (client) read a variable from Matlab (server), and write another variable to Matlab (server) which works fine. However, in Test 2, I switched the order of 'read' and 'write' which means that LabVIEW (client) write the variable to Matlab (server) first, and then read the other variable from Matlab (server). Test 2 does not work as I intended. Is there anything wrong with Test 2?

I would greatly appreciate if anyone could help me out.

0 Kudos
Message 1 of 3
(3,839 Views)

What kind of errors are you getting?

 

Sorry, I am not really familiar with the matlab side, but are you writing and reading the correct number of bytes?

 

Some general comments for the LabVIEW side:

  • You can set the representation of the diagram constants to the right type (right-click). No need to place an orange diagram constant and convert it to a different representation (I32, I8)
  • If you would use "unflatten from string", it would optionally do the endian conversion for you.
0 Kudos
Message 2 of 3
(3,793 Views)

Thank you for your advice. The reason I converted the constants using 'I8' or 'I32' converter is that this simple example is a part of a more complex code which requires conversion. 

 

Both examples are equivalent except that the order of 'TCP writing' and 'TCP reading'. I expected both examples should work regardless of the order of writing and reading. The symptoms I got from example 2 is that Matlab (Server) cannot get the variable from LabVIEW (Client).

 

I just realized why this problem occurred. When I first run Test2_Matlab_Server.m, this code tries to read the variable from LabVIEW (Client) so quickly even before I run Test2_LabVIEW_Client. vi (i.e., before the connection is established.) Now I think I can fix the problem.

 

Thank you.

0 Kudos
Message 3 of 3
(3,768 Views)