Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA don't read serial data in the right order

Solved!
Go to solution

Hello all

 

I am working on a project, where I need to sample data at point A, transmit these data wirelessly (zigbee) to point B and from there rs232 connection to the laptop.

I am using labview 2011 to display the sampled data, but I have a small problem, the data is not input in labview in the correct order and this is quite crucial in my application. I have attached a few pictures and my vi to describe the problem in greater detail.

The data is packed in the following form: AS:number1:number2:.......:number49:\r  - where AS is the start character, followed by the sample values, separated by : and the last is followed by a carriage return to end the package. 

When I view the data in different terminals (putty, tera term ect.) then the data is in the correct order. 

To make the problem more obvious I setup the sampling to count a 16bit integer up instead of the real samling 🙂

The teraterm sample png is how it is supposed to look. The vi_sample.png is from the labview string, which is wrong, I've highlighted some errors in the visample. When using the VI I noticed that all the data is being collected, but not in the right order. 

The missing subvi's are some small VI's that reads the rs232 input string and controls different indicators from this.

 

I hope you are able to help me with my problem.

 

Regards

Tommy

 

0 Kudos
Message 1 of 3
(3,086 Views)
Solution
Accepted by topic author Tombech84

In the case structure where you read the serial port you're prepending the string rather than appending. In other words, you're building up the response backwards.

 

Your method for reading is contradictory. You've configured the VISA session to stop reading when it sees a carriage return, but you're not actually doing that. You've set it up so that it reads whatever bytes are on the serial port. This may not be the full set of bytes, especially since you have no delay between the write and the read, so you may be getting only half the message. If you're going to use the termination method, then VISA Read should have a large value wired to the bytes to read. Then, when VISA Read sees the termination character, it will automatically stop. If you're going to use the available bytes, then you need a mini loop to keep reading until you see the end of the response. Pick one or the other - don't try to have it both ways.

Message 2 of 3
(3,076 Views)

Okay I know the data is prepended to the terminal window, it is to make it easier to see the new data (then they will always be at the top of the window).

 

I changed to read size to 512 and going for the termination char approch and it looks like that is the way to go! 

 

Much appriciated and thanks for your time smercurio_fc !

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