LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Bar code via RS232 -clear timeout event queue

Solved!
Go to solution

Hi Labview Experts,

I am reading a barcode label via RS232 and barcode reader send data every 8 seconds or so (presentation mode).

I have a timeout event (1000 seconds) to read RS232 port and it seems timeout event queues as many events and causes my program to repeat test several times.

I would like to disable or clear these “timeout” QUEUE events as to perform test once.

The total UUT test time is about 60 seconds, and I wonder if there is any practical solution to this issue?

Thanks,

Tstand

Download All
0 Kudos
Message 1 of 6
(2,750 Views)

You might have programmed the read to return data up until the first "13", \r. So all the other data will remain on the serial buffer until the next time you read it. Then it will read the next data.

 

You need to read all data until there's nothing left. Then either use the last or read once more to get the most recent.

 

A parallel loop or VI that continuously reads the port might make sense...

0 Kudos
Message 2 of 6
(2,697 Views)

@tstand wrote:

I am reading a barcode label via RS232 and barcode reader send data every 8 seconds or so (presentation mode).


Since the data is constantly being sent (even at a slow rate), I would recommend putting the reading of the serial port into a parallel loop.  If you only care about the latest reading, you can use a Notifier or Global Variable to send the data to your main processing loop.  If you want every reading, you should use a Queue or User Event.

 

Other note: DO NOT USE THE BYTES AT PORT TO DETERMINE HOW MANY BYTES TO READ!!!!!!!!!!!!!!!!!!!!!!!!!! (still now emphasized enough).

Based on your code, your instrument ends the data message with a Carriage Return (CR, 0xD, 13).  You already have the VISA session set up to use this.  So just tell the VISA Read to read more bytes than you expect in a message.  The VISA Read will read until it reads the number of bytes you tell it, it reads the termination character, or times out.  If you use the Bytes At Port like you are, you have a high risk of getting partial messages.  But by telling the VISA Read to read more bytes than you expect, you are relying on that termination character and you will get the full message.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 6
(2,689 Views)

Hi crossrulz and wiebe,

Thanks for your input, and it looks like I have to use a parallel loop, as it does not appear to be a solution at the state machine module.

 

I was planning to use the barcode reader as a dual purpose:  Read UUT's barcode label and start the test without pressing any keys at the front panel.

 

BTW, barcode label is a 12 digits long (with CR, 0xD, 13) and it will be scanned about 8 to 10 times during the duration of the test. I only need to read once, the very first, just at the start of the test, others are discarded (not needed, because scanner is programmed in presentation mode).

 

Thanks again,

tstand

 

 

 

0 Kudos
Message 4 of 6
(2,679 Views)
Solution
Accepted by topic author tstand

tstand wrote: I only need to read once, the very first, just at the start of the test, others are discarded.

In that case, just make a state that opens the serial port, reads 1 message, and closes the port.  You might want to add some logic to make sure you did not start reading in the middle of a message (try to read 20 bytes, make sure you got at least 12) and retry if your message was not complete.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 6
(2,672 Views)

Thanks crossrulz,

 

tstand

 

 

0 Kudos
Message 6 of 6
(2,659 Views)