LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial communication : waiting indefinitely / cancel wait

Dear All
 
I want to connect a serial (RS-232) barcode reader to my PC.
 
There are quite a lot of posts on serial communication, but none address this point with regard to barcode readers - i.e.:-
 
Say you want to scan an unknown number of boxes, just to make a list of them...
 
The program may have to "listen" for a long time for a scan, without timing out (while you're having a cup of tea). But you may also need to be able to cancel the "listening" (e.g. when you've finished scanning) to let the program continue.
 
So you can't just set a long timeout, because you can't cancel "VISA Read" mid-flow.
 
So I suppose some kind of loop is in order, but these are often a bit hideous to write, because you have to cater for the event where the scan takes place at the same time as the loop "loops"
 
Any suggestions, or anybody written such a routine already? I'm not asking for a homework project, but I don't see any point in having to write it if I don't have to!
 
PS  I would have bought a keyboard wedge scanner but they are rare beasties if you want it to be cordless too...
 
TIA
 
Julian
 
 
 
0 Kudos
Message 1 of 6
(3,149 Views)
Hi Julian,
if you poll the number of bytes available in the serial port buffer and read only if there are some available, you have enough time to react on user input. As an example see the BD below (the other case is 0):



Greets, dave

Message Edited by daveTW on 02-27-2007 11:44 AM

Greets, Dave
Message 2 of 6
(3,143 Views)

Another option is to put the 'listener' in its own thread of execution (concurrent loop).  Here you can continuously wait for the read or timeout in a loop, on timeout you can check for the condition to continue listening, if so, clear the timeout error and itterate the loop again.  you can use a queue to pass the bar coded values back to the program or vene better you can make a user event or a value(signal) node to allow main loop to respond to an event of new barcode scanned event.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 3 of 6
(3,130 Views)

Hiya

Sorry for the delayed response - busy, then was away for a week

Thank you both for your replies.

I've attached the VIs that I wrote to do this, in LV7 format, for future reference for others that have this requirement. It might not work straight out of the box but gives enough of an idea of what's going on, I hope.

The "AbortBtnRef2" global is a reference to a "Cancel" button on the front panel. Ignore the other globals... they're for the rest of my app.

Before calling this VI, I ensure first that the serial buffer has been cleared. After, I check that the CR+LF is at the end of the string that I've read out.

Once again, thanks

Julian

 

0 Kudos
Message 4 of 6
(3,083 Views)
Hey, you forgot to attach the VIs Smiley Very Happy

Greets, dave
Greets, Dave
0 Kudos
Message 5 of 6
(3,070 Views)

D'oh! Anyway, I've just discovered a bug in them anyway - will re-post as soon as I've got them working - don't hold your breath tho'!

Julian

 

0 Kudos
Message 6 of 6
(3,067 Views)