none
Slow down data entry from USB scanner RRS feed

  • Question

  • I have a USB Scanner that is dumping barcode scans into a VB application.

    After each barcode is received (using cr/lf to trigger complete) some lookup is performed.

    I suspect that when the database lookup is processed over a WAN/VPN connection to the server across the country, that a delay might cause some input data not getting processed.  The next entry interrupts the completion of the previous.

    Data is entered on a Windows Form textbox.  Can I safely 1) receive data until cr/lf, 2) disable textbox, 3) process data, 4) enable textbox?  Will this tell the USB device handshake to wait?

    Or is there a better way?  Thanks.

    Thursday, August 17, 2017 4:02 PM

Answers

  • Probably what you want to do is to use a thread to read the barcodes and another thread to process the barcodes. Assuming the read thread would need to be able to report errors and exceptions, both threads should be BackgroundWorkers. After processing the barcode, the data can be put into the textbox using the ProgressChanged event. Use the Queue class to create a queue that the read thread adds to and the processing thread reads from. You can use an AutoResetEvent for the read thread to notify the processing thread of work to do.



    Sam Hobbs
    SimpleSamples.Info


    Friday, August 18, 2017 3:55 AM

All replies

  • It generally helps to supply some code to see what you have going on.

    Without looking at it, you could create a Bool variable (initial val=false) and conditionally run your code depending on this value.

    You would set the Bool to true on databinding complete, for example.


    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Thursday, August 17, 2017 4:11 PM
  • Can I safely 1) receive data until cr/lf, 2) disable textbox, 3) process data, 4) enable textbox?  Will this tell the USB device handshake to wait?

    Or is there a better way?

    That would depend on what the device is and how it is connected.  If you have implemented it as a keyboard wedge then you generally can't control the data flow.   If you are using a device driver supplied by the manufacturer then there should be a way to suppress data, but whether that means the data is queued or discarded is impossible to say.

    The best solution is to use threading.  Either process the database update in a separate thread from the GUI thread and queue the data in the GUI thread, or run the data collection in its own thread and queue it there.  It just depends on what the configuration of the reader is.

    Note that any queueing solution needs to cope with the possibility that the queue could overflow, for instance if the network connection is lost.

    Thursday, August 17, 2017 10:21 PM
  • Probably what you want to do is to use a thread to read the barcodes and another thread to process the barcodes. Assuming the read thread would need to be able to report errors and exceptions, both threads should be BackgroundWorkers. After processing the barcode, the data can be put into the textbox using the ProgressChanged event. Use the Queue class to create a queue that the read thread adds to and the processing thread reads from. You can use an AutoResetEvent for the read thread to notify the processing thread of work to do.



    Sam Hobbs
    SimpleSamples.Info


    Friday, August 18, 2017 3:55 AM
  • Thank you for your suggestions - threading is the solution, I believe, to the USB wedge-style keyboard input speed.  I will work on implementing that solution.
    Tuesday, August 22, 2017 4:17 PM