LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP communication

Solved!
Go to solution

You actually have quite a few problems with your code. I don't think you quite understand how event structures work or how to use queues properly. You are using queues (dequeuing data) immediately before the event structure. In addition you implement your state machine within the timeout case of the event structure. You are mixing lots of different architectures into one big mess.

 

Generally speaking events structures are used to service UI events. They can also be used to service user defined events. The code contained in events structures is generally very fast. This allows the event structure to quickly service events as they are triggered and to provide a responsive UI. If the event structure services only user defined events its code could take longer to run as this will be a specialized event handler. In a producer consumer architecture the producer (more often than not the loop with the event structure) processes an event and queues a message for the consumer(s) to process. For example, in your client you stop the application by simply reading the value of the stop button in the producer loop (the one reading from the TCP connection). You also use a Stop event in the consumer loop (the one with the event structure). However, if the producer stops before posting any data to the queue your consumer will never exit because it will be waiting for the queue to get data which will never arrive.

 

With respect to your TCP reads you are not doing it correctly. Your server which is sending the data writes the length of the data followed by the data itself. Your read is always reading 100 bytes. Your client should have two reads. The first read should read 4 bytes and convert this to a number. The second read should read that many bytes. That should read your messages properly.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 11 of 14
(909 Views)

I marvel at your understanding of these techniques and concepts . I am now using two reads as suggested but the data output is still corrupted. I am still trying to find out how to read the data correctly. 

 

* With regards to my code having several unrelated elements there is an explanation. The current VI is a sample frame I made from my actual code which I am not allowed to post here but shows how I use some of the items you mentioned. However, I will follow through with each of your suggestions (architecture etc) .  

0 Kudos
Message 12 of 14
(883 Views)

I don't have the IMAQ stuff installed on my machine so I cannot see what form your data is that is being sent by your server. You need to convert from a string to the same representation as the data was sent. I believe the VI on your server is giving you a variant as the data you are sending. This variant represents a specific type (since I don't have the IMAQ stuff I am not sure what that type is) but on your receive side you need to read your data (the data portion, not the lenghth) and do an unflatten from string with the correct data type. You would then need to perform any other data conversions required. You cannot immediately assume that you have 3 floating point numbers separated by commas (which is what your receive side is assuming). Essentially you are writing the message you read in English and interpretting it as German on the receive side. Both sides have to be talking the same "language". When I say language I mean the format of the data.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 13 of 14
(878 Views)

Works great but LabVIEW crashes after running  for a while.   I get the following error ' Fatal Internal Error '  generic mgr.cpp, line 1078. I will clean my code first and see if that helps. Thanks a lot.

Download All
0 Kudos
Message 14 of 14
(870 Views)