LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data transfer LabView/Simulink through UDP

Solved!
Go to solution

Dear 12311

 

Are you using LabView on any of the PCs? Or how is the structure of your application?

I think you'll have similar problems with the type casting, and putting the certain amount of bytes into TCP/IP channel. Please find the recommendations in this Forum Topic.

 

As I can guess: If your TCP Writer app is in LabVIEW, you'll have to force to send the TCP packet inmediately after the TCP Write VI with the TCP Flush VI. With Flush the writer won't wait until the TCP buffer gets full, so maybe it will avoid the Timeout on the receiver side.

 

Hope, it's helping.

 

Regards,

Tamas

0 Kudos
Message 11 of 36
(6,311 Views)

Dear Tamas,

 

This time it did not work.

 

Probably I modified original .vi file in wrong way but I cannot find where I made mistake.  To this message I attached vi file in which I added “bytes to read” input. But there is other errors which I cannot find.

 

One question: is it necessary to use two blocks TCP read? One to read number of bites and the second to read data? In Labview examples I saw this scheme. But is it required? I did not use it that it why I ask you.

 

At the end. Could you have working example of LabView TCP client? Or do you know where I can find it?

 

miro

0 Kudos
Message 12 of 36
(6,294 Views)

Dear miro,

Thanks to send me the screenshot of your application.

So this is the client, which connects to the remote port 838 with the TCP Open Connection VI.

 

There is maybe a little problem at the Read TCP VI. You wired 838 constant as "Bytes to Read" into the VI. This means that it will read 838 byte, which will appear on the output signal. After it, you try to Type-cast the 838 bytes into double. The double is only 8bytes long. I think try to put 8 instead of 838 into this constant, and than hopefully it will work 😉

 

I made a simple TCP client application for you, which reads double values from TCP channel. It doesn't have connect and disconnect buttons, it's only focused on the TCP connection.

 

I hope I could help you, and this will work well.

Best Regards,

Tamas

TCP client

0 Kudos
Message 13 of 36
(6,266 Views)

Dear Tamas,

Thank you for your .vi.
I still have many problems with TCP, LabVIEW and Matlab.


At the beginning I started testing sent .vi with simple TCP Labview server. To this message I attached two files with obtained results. It is quite confusing for me. Labview server sends sine signal with frequency 1 Hz and amplitude 1. In the second picture shape of signal received by Labview client is not sine signal. Amplitude is different as well. I cannot understand it. Moreover if I increase frequency (10 or more Hz) any signal is received by Labview client.

There is no connectivity with Matlab as well. I do not have idea how to solve this problem. Few weeks ago I dealt with the same problem of connectivity between LabView and Matlab but by use UDP. I did not have any problem. So it is very surprising form me.

miro

Download All
0 Kudos
Message 14 of 36
(6,239 Views)

Hi miro,

thanks for the screenshots.

I checked again your sent server VI.

I realized that you try to convert the Dynamic Signal, which is comming from the Simulate Signal Express VI, is converted to SGL datatype. This dynamic data signal is containing a set of date, like in an array. Using this conversion, you'll only convert one data from the array. That's why you could get different amplitude and frequency. You can get the array data from this dynamic signal with the "Convert From Dynamic Data" VI. You can find it here:

convertfromdynamicsignal.png

 

You can check out in the Help menu/ Find Examples dialog: Browsing the Networking / TCP & UDP you'll find the Simple Data Server and Simple Data Client VI, which can show you a simple connection.

I also made a very simple, but not fully featured client and Server VI, which shows how to handle right the conversions and communication with single float data type. I use generated sine wave with array type. Please find the attachement below.

 

I hope it helps to make it working. I really belive that the communication should work fine 😉

Best Regards,

Tamas

 

Download All
0 Kudos
Message 15 of 36
(6,232 Views)

Dear Tamas,

 

Thank you very much for your last .vis and help. Now everything works fine.

 

I made connection between LabVIEW and Simulink through TCP.  One remarks for all interested in connection LabView and Simulink. It is possible to send data from LabView to Simulink using TCP. But it is probably not possible to do it inversely. I found few opinions about this problem. Simulink cannot work as TCP server when client is on different PC in network (there is no problem when we do it on the same computer). It means that it is not possible to send data from Simulink to e.g. LabView through TCP. There is only one way to do it: using UDP protocol. But in some cases it is not acceptable solution…

 

I have one question for you Tamas. I send you picture of .vi which is compound of two .vis: to send data through TCP (standard LabView .vi form) and then collected data from Bluetooth interface (.vi build by Shimmer manufacturer which produces Bluetooth sensors). Task is as follow: collected through Bluetooth data send using TCP.  

 

My solution is simple: I combined these two .vis to one .vi and I used local variable to transfer data from one part (data collection by Bluetooth) to another (send through TCP). It works, by I wonder does it possible to do it better? Maybe this kind of problem usually solve in different way… How you judge this solution?

 

I attached picture of .vi and mark my modifications.

miro

 

Download All
0 Kudos
Message 16 of 36
(6,205 Views)

Dear miro,

Sorry for my late answer first of all, and thanks for the summary about the simulink communication.

I think the problem could be (I'm not sure, because I use Simulink very rarely) the following about the Simulink TCP server:

If the TCP server is on Simulink, the TCP Listener function is listening only on the localhost, and is not open for any IP adress to connect. So the listener IP is not 0.0.0.0 or *, but 127.0.0.1.  In this case it accepts connections only from this IP address.

If the listener address is correct, still there can be issues with the firewall to accept incomming connections from other computer to the Simulink host.

 

I checked out the VIs you sent, and they looks possible working, but anyway the code is Huge, and a hard to "read". I can recommend you some small tricks, how to do it more readeable:

 

- use and create SubVIs: You can select a group of functions in LabVIEW and save it as SubVI: Select the group and: Edit>Create SubVI

(for example in your code, you could make group of the logics in the big while loop)

- use Clusters to group the set of variables, and wires. The cluster can handle different type of wires, grouped into one wire. To expand or create the clusters you can use the Cluster palette. 

(for example you could make a cluster with the accelerometer data, and a cluster also for the integer parameter constants.)

 

For more sofisticated, and better structured code, you could use the State-Machine architecture. There is a very useful tutorial: 

http://zone.ni.com/devzone/cda/tut/p/id/3024

You can find more tutorials and solutions on http://zone.ni.com 😉

 

Best Regards:

Tamas

 

0 Kudos
Message 17 of 36
(6,133 Views)

Hello Everyone

I've been reading the topic and thanks to discussion tips could establish connection via TCP between LV and Simulink. Your advises are very helpful. I am manage to send one dbl data to simulink and plot the data as well comming every 1 ms. But my goal is to use simulink model to predict behavior of physical one measured by LV. So, all measured data from LV  I have to transfer to simulink in form of array (inputs, outputs).

In simulink I can use block reading but unfortunately I don't know how to prepared data to transfer in LV. Let's consider sin signal in 200 element array.

Can you help me to overcome this problem, please?

Hepta

Download All
0 Kudos
Message 18 of 36
(5,824 Views)

Dear Hepta,

I'm glad to read that you find this forum topic useful for your application as well.

Unfortunately I don't have the Simulink installed at my computer, so I cannot open the .mdl file in the attached array.zip now. Please, can You send me a screenshot of your simulink drawings and the relevant setup windows that I can understand how you want to acquire date from TCP?

 

As I know the DBL array sent from the LabVIEW is a standard array, like programmed in C. When the data is transfered through TCP, the meta information of the DBL array, like (size) is not transfered, only the pure bytes of data. The data in the array are aligned next to each other like in a datastream. I think nothing special preparation is required for it, but I would know more if I can take a look on the simulink file.

 

Tamas Szekely

0 Kudos
Message 19 of 36
(5,814 Views)

Hello Tomas,

I've attached screenshots of two .mdl file. sim_tcp_array and sim_tcp_oneElement.

The first one is when I expected 200 element array competed in every step of simulink. The second when I read only one element in every step of sim. I use blocking mode in both configurations for tcp. LV TCP Data Server - array.vi (also attached) generates 200 points sinus dbl array.

 

When I send one dbl element from LV, simulink receives data, but it doesn't when I try to transfer array of doubles. 

 

My goal is to send dynamic object measured data from LV to simulink model of the object and calculate residues, than transfer it back to LV. (Simply fault detection diagnostic technique).

Thanks for helping me 🙂

Hepta

 

0 Kudos
Message 20 of 36
(5,811 Views)