Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

serial

Dear all,
sory in my first post i forgot to attach the image.
I've attached a simple Subvi that is meant to read
from serial port that has a sensor connected to
it.
the sensor can be puten into timed continous mode
and transfer at every 30Ms.
While the Vi is very simple and looks reasonable
to me, the results are odd. For example once I
expect 20 bytes at port sometimes it shows 40. and
it varies, each time.
I should also mention that in the first frame of the sequence I have wait loop of 30ms.
Is there anything i've done wrong ?
0 Kudos
Message 1 of 2
(3,233 Views)
Hello,

Your diagram looks correct, but I think that it's possible that you could do this a little differently and maybe better. If you're getting more than 20 bytes at the port, it's most likely because your device or random line noise is causing your serial hardware to detect those extra bytes.

It seems that you are waiting for exactly 20 bytes at the port, so why not simply drop the delay at the "Get Bytes At Port" and read 20 bytes? If you do not get the 20 bytes, you will get a timeout error that you can trap and return a message to the user saying that the device didn't behave as expected. If you get more than the 20 bytes, you read only the first 20 and do whatever you want with the remainder (flush the buffer, save them for debugging, etc).

Agai
n, I'm pretty sure that the bytes are there at the port if the function calls say they are, so something is going unexpectedly with the device.

Hope this helps.

Scott B.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(3,233 Views)