12-06-2011 01:11 PM
hi to all, i need to receive serial packets in ordered manner, and after some minutes the packets start to enter mixed with previous packet.
this is an example packet i need to receive: A509 0C00 3F71 4ED8 1002 0000 0000 05
first 2 bytes are constant, never change. Last byte is CRC.
Its always a 15byte packet.
after some time labview is showing: 3F71 4ED8 1002 0000 0000 05A5 09
thats only an example, but it moves around the packet, i assume because it is mixing the last packet with the previous packet.
what can i use in order to tell labview to always read the 15bytes starting at A509 ?
im just opening the port and reading the contents of the port with serial read ...
thanks!
12-06-2011 01:27 PM
You are going to have to provide the synchronization code yourself. For example, in a loop, read 2 bytes. If the bytes are A509, then exit and read the next 13. After that, you can just keep reading 15 bytes. Don't use the VISA Bytes at Serial Port. Another method is to initially read 15 bytes and determine where the prefix is. Then calculate how many more bytes to read to get to the end of the packet.
12-06-2011 01:47 PM
thanks dennis,
can you provide me a simple example to do this? i dont want to bother you, but if you can it will be of good help, im a newby trying to understand different techniques in labview.
thanks!
12-06-2011 01:58 PM
@Dennis Knutson wrote:
You are going to have to provide the synchronization code yourself. For example, in a loop, read 2 bytes. If the bytes are A509, then exit and read the next 13. After that, you can just keep reading 15 bytes. Don't use the VISA Bytes at Serial Port. Another method is to initially read 15 bytes and determine where the prefix is. Then calculate how many more bytes to read to get to the end of the packet.
If I am not mistaken the first 3 bytes are a header and it appears the thrid byte is the packet length. Therefore the read algorithm can be modified to read 3 bytes. Validate the intial header value of A509 and then get th epacket length. If you have a valid header read the next n bytes where n is the length from the header.
The code to get yourself back in synch is a bit more challenging but doable.
BTW, since the OP had asked questions about this data in other threads one thing he should look at is how the header is defined. Given this data has a CRC it is reasonable to assume the header is well defined and meaningful. Therefore, use the information provided.
12-06-2011 07:22 PM
A way to handle streaming data is to have one loop that always reads all Bytes on the port, then enqueues them for processing in another loop. If the Header1 is good, go to Header2. If that's good, go to length and iterate over that. Save your CRC as you go.
12-14-2011 03:39 PM
Todd, thanks for your diagram, can i please ask you to send a vi example so i can further understand the meaning of the different icons?
thank you very much, im using Labview 2010
thanks again.
12-14-2011 06:28 PM
Drat, I can't find this sample code. The top half has:
Obtain Queue
VISA Bytes at Serial Port
VISA Read
String to Byte Array
Enqueue Element
The bottom half has:
Dequeue Element
Select
Increment
Make the enum (Header1, Header2, etc) a type def.
Either search the pallette, or (on a block diagram) press <ctrl>-spacebar and start typing the names above. This is called Quick Drop.
12-15-2011 08:48 AM
thanks Todd again!
im attaching what i have.
everything is working smoothly without errors, but now a dumb question... how do i get the results? i mean how can i get the packet starting at A5 in a string indicator or byte array?
thanks thanks!
12-15-2011 09:40 AM
No need to overcomplicate things here with queues. The serial driver will take care of this. And it will also provide a 1024 bytes FIFO for the serial data by default. What you need to do is to get in synch with your serial data. Then you can just pull 15 bytes from the serial driver each time you read it. Your example is not good for much. So just drop that idea. And then you post code examples. PLEASE do not just post pictures. One more thing. you must also set up your serial port correct. Like baud-rate, stopbit(s), handshake and so on. What type of instrument are you using. Any link to documentation?

12-15-2011 10:15 AM
Thanks Coq for your response.
I dont have a serial driver, this is a sensor that constantly transmits 15 byte packets, but sometimes i get out of sync, i need to read the packet always from the starting byte.
Here is the packet definition:
D0 D1 Header fix at A5 09
D2 Data Length (its fixed at 0C)
D3 D4 First Sensor Id
D5 Data Type:60=Sensor Reset, 61=Periodical signal, 62=Status Change Signal
D6 D7 Second Sensor Id
D8 Second Sensor Status11= Closed 10= Opened
D9 Battery StatusA0= Battery Charged A1=Battery Discharged
D10 D11 First Sensor Value
D12 D13 Second Sensor Value
D14 CRC
so for example a correct packet will be:
A5 09 0C 00 3F 61 05 1E 10 A0 00 05 00 04 05
A5 09 0C 00 3F 61 05 1E 10 A0 00 05 0C 2F 03
A5 09 0C 00 3F 61 05 1E 10 A0 09 05 09 04 09
but after a while from reading the port, i start receiving in different order, for example: 1E 10 A0 00 05 00 04 05 A5 09 0C 00 3F 61 05
i need one simple example on how to sync this. i think it must be really simple, just i cant figure it out.
regards!
nico.