LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA doesnt read the complete string

Hello,

 

I'm communication with a sensor where I have to select first what kind of data output I want and after that it just keeps sending. If I acces my connection with hyperterminal it works fine, the data is shown fast and complete. If I use labview however most of the times I only get parts of the string that the sensor is sending. Now and then I get the full string.

 

For the moment I bypassed that problem with a case that only lets the string through if its complete, it causes a delay but it works. I have to add now some more sensors and I also will need my full sending speed so I wont be able to use my bypass anymore. (Added picture is current situation)

 

If anybody would have an idea how I can solve this please let me now, I am already searching for this a while and I have tried several things but all without result.

 

Greetings,

 

Jed Noo

0 Kudos
Message 1 of 6
(3,065 Views)

I suspect that you are not reading the data fast enough. I would recommend that you create a parallel task that does nothing but read the data from the connection as quickly as possible. This task would then post the data to a queue for a separate task to parse and process. The read task can either read a large number of bytes with a relatively short timeout and simply ignore the timeout and post whatever was read. If your data uses a termination character of some sort you could read until you see the termination character and then post that to the queue.



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 2 of 6
(3,060 Views)

Why are you clearing the buffer inside the loop?

 

You get bytes at port, then read that many bytes.  Then you clear the buffer.  If you get any bytes between the time you get the count and read them, you are going to lose them because they weren't read, then you cleared the port.

0 Kudos
Message 3 of 6
(3,040 Views)

Yes you will need to loop to read the port faster than it is sending.

 

After that, from what I can see you do not seem to be using anything to help sync up with you data.

You just read what ever number of bytes happen to be at the port and then you flush any bytes that just happen to arrive a little late.

 

I would use the termination setting to terminate your read on either the # or $ (which one is the end?) or is there a line feed or carriage return.

Set the timeout for the port to some value like twice the time between messages. (or more)

Then read a fixed number of bytes that is greater than the number of expected bytes in your message. Going larger will avoid the warning about more data might be at the port.

Remove the Bytes at port and the Flush functions.

Plus you are clearing any error messages so do not know if something went wrong. Or are you just clearing the warning about more data at port becasue you used the Bytes at Port. Use the termination and you will not get that warning.

 

Then with each read you should get one and only one complete data message with each read.

 

If you still have problems post a sample of the data message so we can better understand what it is you are trying to capture.

Omar
0 Kudos
Message 4 of 6
(3,038 Views)

Hello, thx for the sugestions

 

I already took the buffer out of the loop and the speed of the incoming data at least doubled, my 3D picture even cant follow anymore, but I know how to lower it with the period of the while loop. The termination character didnt had much effect. I still have to look to implement the parallel tasking because now I have some problems with excess data. The visa gives the following error : VISA:  (Hex 0xBFFF006C) An overrun error occurred during transfer. A character was not read from the hardware before the next character arrived. and I get data like $,-136,-23,-211,375,,376,374,372,384,-125,175,# where I only should receive 9 values $,-136,-23,-211,375,376,374,372,384,-125,# . I will now try ones to work with parallel tasking, one process that reads the data and one that processes it. I'll let it know when I solved it or when I get stuck 🙂 Already much thanks for the help

 

Jed Noo

0 Kudos
Message 5 of 6
(2,991 Views)

Hello,

 

Since this morning I'm trying to complete the tips I got with my question,for the parallel tasking I introduced an event which I based on the example from the solarsystem (3D picture control) but my new problems are staying, I get a delay of a few seconds before the picture follows and I still get often a string that now is longer than the string that is sended, the contrary of the beginning problem. I put as attachment a screenshot with a bad received string and what problems that introduces and a pdf with my complete program (latest version).

 

Thanks for looking at it, I try to find out as much myself but it takes a while to learn to work with labview

 

Jed Noo

Download All
0 Kudos
Message 6 of 6
(2,944 Views)