Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

how to recieve bytes from microcontroller correctly

Hi,
I am using LV8.0 to communicate with my microcontroller that is used to collect the data from 3 channels of a 12bit ADC. So basically, I have 6 bytes (2 bytes for each ADC channel) each time to send to the PC via the serial port. What I want is to recieve the data and dislay them continously in the correct order (first byte, second byte, ...).
However, right now I am facing with the order of bytes each time I stop & start again the VI. Sometimes,  the second byte comes first and the other time the sixth byte come first.

Here is my example:
I send 6 bytes: 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA
What I recieve: 0xFD, 0xFC, 0xFB, 0xFA, 0xFF, 0xFE    or  0xFB, 0xFA, 0xFF, 0xFE, 0xFD, 0xFC    or   0xFA, 0xFF, 0xFE, 0xFD, 0xFC, 0xFB... it's random...

As I guess, there is some problem with the buffer and what I need to do is to packet my data with a header and teminator so that the VI can recognize what are the start and stop of the packet. Is this correct? If not, could you please correct me and advise me what I should do?
Anyone has a code and ever face with the same problem?

Thanks,
Anh

Message Edited by anhdtvt on 12-13-2006 01:42 PM

0 Kudos
Message 1 of 3
(3,411 Views)
Since the device is sending data continuously and you have no header or termination character, it will be impossible to synchronize, imo. I think that all you need to do is to add a term charcter such as CR or LF. When you use VISA Configure Serial Port, you can enable a termination character and specify what the character is. Do a flush buffer immediately after. Then in while loop, a VISA Read will automatically terminate when the character is read no matter how many bytes you told it to read. If the actual number of bytes read is less than what you expected, discard this reading. After that, your data read should be synchronized and you can display it.
0 Kudos
Message 2 of 3
(3,391 Views)
Many thanks to you! I work perfectly.
Anh
0 Kudos
Message 3 of 3
(3,367 Views)