LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bytes at serial port dropping bytes

Hi there,

I've created a VI that sends serial data out to a system and then receives data back from the same system. When receiving the data back, I use the Bytes At Serial Port sub-vi because the received bytes varies between 27 and 3 (controlled with a switch).

The problem I'm having is when I run the VI while receiving 27 bytes, during the FIRST loop, the Bytes at Serial Port sub-vi always yields the last 19 bytes. It seems like it's just dropping the first 8 bytes as if it didn't have enough preparation time. The second loop through it picks up the 27 bytes as expected. Does anyone know of this problem? Thanks!
0 Kudos
Message 1 of 3
(2,659 Views)
Hi Bonehomme,

after you have initialized the serial port you are able to send and receive data. If you send data to a system and then enter a loop to check how much bytes you have received you will get an increasing number from Bytes at Serial Port.
You are sending data to a system with Serial Write. After that your system needs some time to read the data and create an answer. Also it takes some time to transfer the data back to your PC (at 9600 Baud it needs 1 millisecond per byte). Meanwhile your program enters the loop and checks how much data has been received until now. Dependig on the timings it could be that you will see 19 bytes and on the next iteration 27.
Bytes at Serial Port cannot drop any bytes, because it gives you only the number of byte
s you have received.
If you are using the VISA serial functions and do binary serial transfer you have also to disable the termination character handling.

Waldemar
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 2 of 3
(2,659 Views)
I would wonder if your initialization to the serial port is in the same loop as the data collection - I built a serial data system recently, and had similar problems until I moved all the initialization stuff forward, and the serial read loops back towards the end of the vi. Also, I found at 9600 baud (the speed of my D/A system) that I needed a 30ms timer in front of serial read vi's to give the system enough time to receive data.
Try placing a timer (30 ms as example) into the vi and see if that helps. Might need longer (or shorter) times too.
-Dave
0 Kudos
Message 3 of 3
(2,659 Views)