Serial Barcode Scanner

  1. 2 weeks ago

    Jonathan E

    Nov 28 Pre-Release Testers, Xojo Pro Las Vegas, NV

    I am playing with the serial port example for bar code readers and have come across an odd behavior that I’m not sure how to debug further.

    When I run the program on my Mac it runs as expected, but when I run it on a windows 10 machine with the same model of scanner the DataAvailable Event does not always get raised. It seems that it’s almost always when scanning the first barcode after connecting, although this behavior persists for 2 or 3 scans sometimes. Then, it seems to be one read behind. Meaning if I scan a barcode ending in 852, then a barcode ending in 569 it will print the barcode ending in 852 to the text area (assuming the event gets raised on 569). This behavior is not found on my Mac. I’ve tried setting the baud to the rated speed on the fly as well as exchanging lookahead for readall in the DataAvailable event to no avail.

    I'm using two Datalogic QD2340 scanners.

    Any ideas would be much appreciated.

  2. Bob K

    Nov 28 Pre-Release Testers, Xojo Pro Kansas City

    Can you share the code you have in your dataAvailable event?

  3. Jonathan E

    Nov 28 Pre-Release Testers, Xojo Pro Las Vegas, NV

    @Bob K Can you share the code you have in your dataAvailable event?

    Sure! It is the only thing that I have made (slight) modifications to in the example.

    Sub DataAvailable() Handles DataAvailable
      // For this example, we used the Motorola LS2208 bar code scanner.
      // It can be easily configured to add a carriage return and line feed
      // to the end of the barcode value. This example then looks in the serial
      // port buffer to see if those two characters are present and if so
      // reads the data into the TextArea1 control.
      //Dim data As String = Me.LookAhead(Encodings.ASCII)
      Dim data As String = Me.ReadAll(Encodings.ASCII)
      If InStr(data, Chr(13)) > 0 Or InStr( data, Chr(10)) > 0 Then
        OutputArea.Text = OutputArea.Text + data
      End If
    End Sub
  4. Bob K

    Nov 28 Pre-Release Testers, Xojo Pro Kansas City

    I don't have time to look at it but you have to loop until you have no more DataAvailable

    Off the top of my head:

    dim sData as string
    while me.DataAvailable>0
       sData = sData + me.ReadAll 
       me.poll
    wend
    
    //now deal with sData

    If that's not enough to help I'll dig out what I did in my barcode class.

  5. Bob K

    Nov 28 Pre-Release Testers, Xojo Pro Kansas City
    Edited 2 weeks ago

    Had a chance before meeting to open a project that uses a barcode scanner. Almost had it right. I'm using AddHandler to do this all via code but it demonstrates what you should do with all serial comms.

    Private Sub Serial_DataAvailable(oInstance as Serial)
    
      dim s as string
      
      While oInstance.BytesAvailable > 0
        s = s + oInstance.ReadAll
        
        oInstance.Poll
      Wend
      
      SendBarcodeToListeners(s)
    End Sub
  6. Derk J

    Nov 28 Pre-Release Testers, Xojo Pro

    Use lookahead for the if statement part. That keeps the data in the buffer, so if it’s not all data yet, you can skip the event without loosing the buffer.
    Then use ReadAll when the expected data is in there or even better use Read to get only the string part from the buffer that you need before the check Chr(13) + Chr(10).

    It’s best to keep awat from loops. Just know that the datavailable event is not guaranteed to have all data or even has data. But it can also have more data than expected (for example 2 barcodes in one event)

  7. Jonathan E

    Nov 28 Pre-Release Testers, Xojo Pro Las Vegas, NV

    @Bob K Had a chance before meeting to open a project that uses a barcode scanner. Almost had it right. I'm using AddHandler to do this all via code but it demonstrates what you should do with all serial comms.

    Private Sub Serial_DataAvailable(oInstance as Serial) dim s as string While oInstance.BytesAvailable > 0 s = s + oInstance.ReadAll oInstance.Poll Wend SendBarcodeToListeners(s) End Sub

    I converted the code to include a while loop and when it triggers the while loop works as expected BUT it does not trigger the first (and sometimes second and even third) time the scanner reads a barcode and when it finally does it has the data from the previous scan in Me.Lookahead and Me.ReadAll.

  8. Bob K

    Nov 28 Pre-Release Testers, Xojo Pro Kansas City

    At that point if it's working on the Mac but not in Windows it's probably a Windows driver issue. I've never used a Datalogic scanner so unsure what to advise for next steps.

    Side question: Are you going through a USB to Serial converter or straight USB?

  9. Joost R

    Nov 28 Pre-Release Testers, Xojo Pro The Netherlands

    I maybe missing something, but as far as I see, and we're using one in our project, you could use a "barcode scanner keyboard wedge". Highly configurable and a huge amounts of codeformats and barcode fonts'.

  10. Bob K

    Nov 29 Pre-Release Testers, Xojo Pro Kansas City

    @Joost R "barcode scanner keyboard wedge"

    Mileage seems to vary on this one. We've had zero problems with serial bar-code scanners. We've had huge issues with barcode scanner configured as keyboards messing around with control focus and user input.

  11. Jonathan E

    Nov 29 Pre-Release Testers, Xojo Pro Las Vegas, NV

    @Bob K Side question: Are you going through a USB to Serial converter or straight USB?

    This is straight USB, but the interface is set to simulate RS-232. This seems to be the best mode as far as Xojo even recognizing the device. I will play more with the configuration and look into drivers.

    @Joost R I maybe missing something, but as far as I see, and we're using one in our project, you could use a "barcode scanner keyboard wedge". Highly configurable and a huge amounts of codeformats and barcode fonts'.

    I will look at the keyboard wedge mode.

  12. Jonathan E

    Nov 29 Pre-Release Testers, Xojo Pro Las Vegas, NV

    I'm wondering if this is related to a mismatch in Baud Rate, Parity or some other setting but I'm having a hard time finding the manufacturers reccomendations for those settings.

  13. Bob K

    Nov 29 Pre-Release Testers, Xojo Pro Kansas City

    With our Honeywell VG1450-UG we set it up for "USB Serial". The documentation notes that in Windows you need to download a driver from the Honeywell website. The driver will use the next available COM Port number. Mac's recognize the scanner as a USB CDC class device and automatically uses a class driver.

    Typically with a USB device you don't need to worry about baud rates and parity as that's baked into the USB protocol. So it might be you have a different mode setup than optimal. Our Honeywell must have a dozen different protocols it can handle.

  14. Jonathan E

    Nov 29 Pre-Release Testers, Xojo Pro Las Vegas, NV

    Okay, I got it working. Admittedly, this is probably not the best solution, but I changed the driver from Barcode Scanner to a generic USB Serial device driver in Windows, and it works exactly as expected.

    That being said, I was quite naive, and I need to use the scanner for a web app, so I had to convert the scanner to a keyboard device pair it with a KeyDown event and a custom global prefix to filter out user keystrokes.

  15. last week

    Bob K

    Nov 30 Pre-Release Testers, Xojo Pro Kansas City

    @Jonathan E That being said, I was quite naive, and I need to use the scanner for a web app, so I had to convert the scanner to a keyboard device pair it with a KeyDown event and a custom global prefix to filter out user keystrokes.

    That makes sense since a WebBrowser doesn't have access to a USB or Serial Port! Those devices (might) only exist on the server.

    So having it act as a keyboard is the only solution that I'm aware of for a web app. Well....welcome to Xojo and hopefully you find it as intriguing as I did nearly 20 years ago.

or Sign Up to reply!