LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reading a serial port based on events

I have a device that under a certain condition will spit out data on a serial port. I am trying to capture that data so I can interperate the status of the DUT. How can I set up to read a serial port based on when the DUT starts spewing data?
0 Kudos
Message 1 of 9
(4,599 Views)
You can use the Bytes at Serial Port in a while loop. When a certain byte count is reached then perform the read.
Andrew Alford
Production Test Engineering Technologist
Sustainable Energy Technologies
www.sustainableenergy.com
0 Kudos
Message 2 of 9
(4,589 Views)
Hi,

You can do an infinite loop to wait for bytes at serial port, but that will rail your CPU if you're trying to do anything else while waiting. There are some event functions you can use. First, enable VISA events with "VISA enable event". The arguement should be 0x3fff2035 (event type = character). Now an event will be generated wheneve a character arrives. You can use "VISA wait on event" in your loop. I use a timeout of 500ms in case something goes wrong and no event is generated.

Good Luck,
-Ted
Message 3 of 9
(4,583 Views)
You should always place a small time delay in any loop, this will stop labview from "railing" your CPU. A wait of 10ms will stop the 100% CPU usage.
Andrew Alford
Production Test Engineering Technologist
Sustainable Energy Technologies
www.sustainableenergy.com
0 Kudos
Message 4 of 9
(4,577 Views)
thanks for the input. I chose to use the bytes at input technique and it works great. Thanks for your assistance
Phil
0 Kudos
Message 5 of 9
(4,542 Views)
Ted,

Any more information on VISA events?  I don't see the option of "charcter" listed when I drop an "Enable events" VI on the block diagram.  Only GPIB and VXI stuff.... I'm using LV 6.1 by the way with VISA 2.6.0.

Where should I read up on them.  I think this is a really elegant way to do things, but I've always wondered how to implement it (After 10 years of serial programming - DOH!).

It's time I took a LV course....

Shane.

Message Edited by shoneill on 08-28-2006 03:23 PM

Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 6 of 9
(4,542 Views)
Hi Shane,

I found it by just typing in "serial" and "event" in the developer zone search box. The way it works is that you have to enable events first for a given VISA session. When you enable the event, you tell it what events you'd like it to respond to. One of the event choices for a serial interface is a "receive character" event.

Here's the help page:
http://zone.ni.com/reference/en-XX/help/371361A-01/lvinstio/visa_enable_event/


That being said, you might be SOL on the older version of Labview.

It clearly is an elegant way to go. I was doing an endless loop of polling the bytes at serial port until it was greater than 0. The problem with that was that it railed the CPU, and therefore, Labview couldnt do the very task that would send the serial character that I was waiting for! (before a timeout). So, if you do the polling mechanism, I would at least put in some wait statements between iterations.

Hope that helped
-Ted
Message 7 of 9
(4,494 Views)

shoneill wrote:

...  I don't see the option of "charcter" listed when I drop an "Enable events" VI on the block diagram.  Only GPIB and VXI stuff.... I'm using LV 6.1 by the way with VISA 2.6.0. ....


Shane,

With LV6.1 and VISA 2.6, you do have access to serial VISA events which are not listed in the "Select Event Type" ring (which ='s the list in the LV6.1 help). Instead of the ring, use a U32 constant with an appropriate value as shown in this old example.

=====================================================
Fading out. " ... J. Arthur Rank on gong."
0 Kudos
Message 8 of 9
(4,396 Views)
I have always preferred to use the termination character event, so that no event is generated until I know that I have a full line of data in the buffer.  Of course this only works if your serial communication includes a termination character.

-tuba


@tpascaru wrote:
Hi,

You can do an infinite loop to wait for bytes at serial port, but that will rail your CPU if you're trying to do anything else while waiting. There are some event functions you can use. First, enable VISA events with "VISA enable event". The arguement should be 0x3fff2035 (event type = character). Now an event will be generated wheneve a character arrives. You can use "VISA wait on event" in your loop. I use a timeout of 500ms in case something goes wrong and no event is generated.

Good Luck,
-Ted



Message 9 of 9
(4,360 Views)