Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use the serial port to capture data?

What makes the number of bytes in the serial port buffer change? How do I capture an n-character string that is constantly being sent to COM1 by an external device?
0 Kudos
Message 1 of 7
(4,582 Views)
There are a few ways to do this.
If the data packet from the com device is always the same length, loop checking bytes at serial port until bytes at port equals the packet size, then read port.

If the data packet varies in size, you can watch the bytes at port, look for >0 and equal for two loop cycles. This wastes a loop cycle.

If your data packet has a terminating character, read bytes at port and use the string match pattern to identify the end of information.
0 Kudos
Message 2 of 7
(4,582 Views)
I've tried to do the first thing you suggested, but eventually I just end up reading 0 bytes at port and that's it. This does not make sense to me since my device is constantly sending data. Where is this data going?

I have been told I shold wait for double the number of bytes I need and then read the string. That way I am assured a complete dataset.

Thanks.
0 Kudos
Message 3 of 7
(4,582 Views)
One other thing. When is Serial Port Init used? Is it necessary or can I just set up COM1 with Windows?
0 Kudos
Message 4 of 7
(4,582 Views)
Try this simple vi.
0 Kudos
Message 5 of 7
(4,582 Views)
I couldn't open it for some reason. "Resource not found". I'm using Labview V5.1
0 Kudos
Message 6 of 7
(4,582 Views)
This is is 6.0
Try this one
0 Kudos
Message 7 of 7
(4,582 Views)