05-15-2013 11:59 PM
Hi all.
I have data streaming (from a microcontroller) sent to a serial port on the computer. I know the data is made up of;
1 byte - Header
1 bytes - ID code
15 byte - Data
Check sum - 1 byte
I wrote the program received as shown in the figure.
Then I get the data.
There are some questions you need help.
I configure Serial Port with Termination char.
Why I read the first byte from VISA always is Termination char?
Then followed by a stream 18byte I wanted, but sometimes do not get a stream, at the time 12byte or 6 bytes as shown in Figure Monitor, sometimes it is termination char byte.
Someone please tell me how to read a data stream such that no data is lost ??
Speed sends a stream of data is 5ms/stream from microcontroller.
Or how to read each byte on the com port at the moment it arrived.
Thanks!
05-16-2013 03:45 AM - edited 05-16-2013 03:46 AM
Hello stone8xvn,
Friend if I am not wrong then between two consecutive iteration thers is delay of 5 ms. If yes then it is very less. May be it is reading previous values only. Increase the delay.
What is your requirement ? Is it some kind of command response way ?
Tell me how response is coming ? is it after you send command or it is sending continously ?
Dont worry we will deal with it. In my application I am reading 500 bytes in the interval of 1 sec so it is not really very big data
05-16-2013 11:38 AM
Stone,
First, you should never use Bytes at Port and Termination Character Enabled = True at the same time. They will fight with each other. From your statement about the data structure, it appears that no termination chracter is sent by the microcontroller. Therefore, disable termination characters at the Configure Serial Port VI.
Second, you do not indicate whether the Header and ID code are characters (or a character sequence) which can never occur in the data. If they are not unique, then how are you supposed to know when a data packet ends?
Lynn
05-16-2013 12:00 PM
It looks like you've set your termination character to be 5A since every read ends in that. I don't know why you say your reads start with a termination character.
Since it looks like you are reading raw hex data where any of the 256 bytes are equally valid, you should not use a termination character. If the termination character you assigned shows up as a valid byte within the stream, then the VISA read will end early and the byte will show up as the last byte in the VISA read. That seems to be exactly what is happening to you.
If you know every message is exactly 18 bytes, then just read 18 bytes. Don't use the termination character. Don't use the bytes at port.
In the event that you would open the port and start getting bytes in the buffer in the middle of a message packet, then you have a problem. You will need to figure out a method where the incomplete packet ends and a complete packet starts. This might mean accumulating multiple bytes within a shift register, and search through that string until you determine where the valid message packet is. I assume that means looking at 18 consecutive bytes and determining that the checksum is correct. Anything else such as a consistent header byte could help you determine where a packet starts. (Of course a particular header byte might also show up as part of the normal data within the packet.)
05-20-2013 03:20 AM
I have found a solution to your problems.
Thank all.
05-20-2013 03:22 AM - edited 05-20-2013 03:23 AM
Who is your by the way ?