LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data transfer LabView/Simulink through UDP

Solved!
Go to solution

Dear All,

 

Sorry if the problem has been solved but I cannot find anything and I am little confused.

My problem is to send data stream from LabView to Simulink (and then results obtained in Simulink transfer back to LabView) using UDP protocol.

 

To send data I use (a little changed) example from LabView folder. It is work good. However I have a problem with Simulink program. It is not possible to read data send through UDP, I have following error:

 

“Error evaluating registered method 'Outputs' of M-S-Function 'sudprb' in 'simulinkip/UDP Receive'. The specified amount of data was not returned within the Timeout period.
Please ensure that data is being sent to the specified port or specify a greater timeout value.”

 

If I understand well data type send by LabView is different that data expected by Simulink problem. And that is my question: LabView can send through UDP only strings but Simulink can read only numerical data such as single, double, integer and unsigned integer. How can I force LabView to cooperate with Simulink?

Is there anyone who solve this problem?

 

miro

0 Kudos
Message 1 of 36
(11,740 Views)
Solution
Accepted by topic author cabal23

Dear miro!

 

I didn't check this error message in Simulink yet, but if you want to send numeric values via UDP, maybe you can use the Flatten to String VI. You can find it in the palette: Numeric > Data Manipulation > Flatten To String

http://zone.ni.com/reference/en-XX/help/371361G-01/glang/flatten_to_string/

 

This VI converts the Numeric value into byte array which is represented as a string, and you can send it via UDP - by connecting this string into the UDP Write VI.

 

If there is still an error, you can change also the byte order: big endian, little endian. I think the default value is the network byte order (big endian)

If the Simulink reads different representation of a numeric value, you can convert the number-representation in LabView, before using the Flatten to String VI: Select one in Labview in the Palette: Numeric > Conversion > double / single / Int32 etc...

 

I hope it will help to solve this problem!

Best Regards,

Tamas

 

 

0 Kudos
Message 2 of 36
(11,694 Views)

Dear Tamas,

 

It works.

Thank you.

 

miro

TamasTamas
0 Kudos
Message 3 of 36
(11,673 Views)

Dear Tamas,

 

Thank you for your help.
One more question. Now, I want to do the same for TCP. As TCP server I use program from LabView’s “example” directory (TCP Data Server - Touch Panel.vi). I modified it a little by use of "flatten to string". It is possible to connect Simulink with LabView but any data cannot be sent.  The same error occurs as it was in problem with UDP:

“Error evaluating registered method 'Outputs' of M-S-Function 'stcpiprb' in 'untitled/TCP//IP Receive'. The specified amount of data was not returned within the Timeout period.
Please ensure that data is being sent to the specified port or specify a greater timeout value.”

 

 

How solve this problem?


miro

 

0 Kudos
Message 4 of 36
(11,655 Views)

Dear miro,

I think the problem is again the type mismatch.

Check it out, which type you're expecting on the Simulink side, and prepare the same type in the Labview before you use the flatten to string vi.

 

For me, it looks like "the specified amount of data" means the size of the datatype you're using. For example if you want to receive at Simuling an INT32, and you just put INT16 type into the flatten and after it to write to TCP, the simulink gets only 2 bytes, and it is still waiting 2 more bytes, which never arrives. So, you get time-out.

 

Please check the data types you are sending, and use the Numeric > Conversion palette if necessary. You can check the data type if you click on the wire and you press the Ctrl-H. It will open the Context help window and it will show up the actual data-type of the wire.

 

If it does not work,may I ask you to tell me, which data-type are you reading in Simulink, and send me a screenshot with the part, how you send the data on the LabView side?

 

Best Regards,

Tamas

0 Kudos
Message 5 of 36
(11,632 Views)

Dear Tamas,

 

Unfortunately it doesn’t work. Probably I did something wrong. If it is not a problem I attached following files:

  1. Simulink simple application (client) to received TCP and draw signal
  2. LabView Server in two version:
  • with flatten data to string modification
  • with flatten data to string modification and without sending string length (I saw to version of TCP protocol implementation in Labview: with and without sending string length)

 

LabView server is modified .vi file from example directory.

I still do not know why data can be send. It is possible to connect server with client but any data transferred.

 

miro

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

Dear miro,

sorry for the late answer.

 I hope you enjoyed the eastern a lot.

 

Thanks to send me your code.

I couldn't open the Simulink program yet, because it's not installed on my computer.

But I checked the VI you sent, and it looks like it should work fine. I think you get time-out because this LabVIEW VI waits at the TCP Read.VI until a string character arrives, or throws a timeout error after 10 seconds. (10000 miliseconds). If this character is "1" it generates a Sine wave, if not, a random signal, and sends it to the Simuling.

 

If you send a character from Simulink to the LabVIEW, you should be sure, that the TCP buffer is sent. With only one character in the buffer, probably the TCP handler doesn't send immediately the packet, so  you should use a Flush command at the Simulink/sender side.

 

If you don't want to wait to receive any character in LabVIEW, just delete the Read TCP VI, and connect the broken wires. 

As I can see, the LabVIEW program sends single-float type of values, so the Simulink code should be prepared to acquire standard 32bit floating point data.

 

You can also use the Highlight Execution in LabVIEW to see, where the program stucks while executing. Using this, you will see, where the problem accours.

You can find this in the block-diagram, next to the RUN tool-bar icon: it looks like a light bulb.

 

I hope I could help you with this little VI analysis.

If you have any questions, or you got some problems, just let me know.

 

Best Regards:

Tamas

 

 

 

 

 

0 Kudos
Message 7 of 36
(11,540 Views)

Dear Tamas,

 

Thank you very much for your help. Now it is works what you wrote. Your advice are very helpful.

 

I have one more problem. I want to send data in the opposite direction i.e.: from Simulink to Labview. There is another problem. As you know I use server and client .vi files and I try to modify them a little.

 

Now, when I use Simulink as the server (see jpg file) and Labview as a client there is a connection but on the Labview chart (client) is only 0, nothing more. In order to test and to compare the modified Labview client I tried to communicate with Labview server – there is completely the same problem as when Simulink was the server.

 

I modified Labview server as you suggested in last post (and I think now it works fine) but I had to modified Labview client as well. And I think that there can be the source of problem.

 

To this message I attached modified Labview server (in comparison purpose) and client (.vi files) and screenshot of Simulink server.

 

 

Best regards,

miro

0 Kudos
Message 8 of 36
(11,499 Views)

Dear all, i am doing a program using simulink in which i want to have a pid controller on 1 PC and a water level tank (actuator) on another PC and i want them to communicate with each other using TCP/IP

 

i am getting this error message 

 

 

Error evaluating registered method 'Outputs' of M-S-Function 'stcpiprb' in 'pid2/TCP//IP Receive'. Error using ==> stcpiprb>Outputs at 211
The specified amount of data was not returned within the Timeout period.
Please ensure that data is being sent to the specified port or specify a greater timeout value.

 

Error evaluating registered method 'Outputs' of M-S-Function 'stcpiprb' in 'pid2/TCP//IP Receive'. Error using ==> stcpiprb>Outputs at 211The specified amount of data was not returned within the Timeout period.Please ensure that data is being sent to the specified port or specify a greater timeout value.

 

and i don't know where is the problem, can anyone help me plzzzzz

 

 

Thank you

0 Kudos
Message 9 of 36
(11,435 Views)

Dear miro,

 

Sorry for my late answer. Thanks for your screenshot and your VIs.

 

I think you'll get more information about the error, if you also wire the Error out line of the TCP Read VI on the Block diagram. You can make it as a chain: wire the  Error in with the Error out lines of VIs in the loop.

And if you use PC, I don't know if the PDA error handler VI at the end will show up the source of the error. I guess so, but I'm not sure.

 

I think the main source of the problem is that you should provide a number for the input "bytes to read" of TCP Read VI. If you read double, it should be 8, if single float numbers: 4 bytes.

If you don't wire here any input, the TCP Read VI will read all the bytes at once, which is received. Probably all the bytes at once cannot be converted to double. 

 

If you want to acquire continuesly a certain amount of data to show in a Graph, you can also provide N * 8 or 4 bytes to read. In this case you can provide an array of doubles in the Type Cast VI, after the Read TCP VI.

 

Please check it out, and I hope it works well now;)

 

Best Regards,

Tamas

0 Kudos
Message 10 of 36
(11,427 Views)