Bar Code Reader Spookiness

I’ve got a strange one that I’m hoping maybe someone has figured out. I have a barcode scanner I’m connecting to using SerialConnection and it seems to work just fine on my Mac, but when I switch to my Windows machine the behavior gets wonky.

My first scan doesn’t go through and each subsequent scan gives me the data from the previous one. So if I scan the barcode 1234, I don’t get any event firing. Then I’ll scan 5678 and I’ll get a DataAvailable event, read the port and get 1234. This continues in perpetuity as far as I can tell.

I opened the example Serial Port Bar Code Reader and the behavior persists there. It behaves the same whether I’m debugging directly on the machine, debugging remotely with the IDE open on my Mac or compiled.

I’ve tried flushing the port before connecting, manually setting all the pertinent properties such as baud rate and bits and even manually polling the SerialConnection doesn’t yield any data. I have to scan it again.

If anyone has any experience or ideas on what I should try next, I’m pulling my hair out.

I’ve tried this with a Datalogic QD2430 and a Zebra SR2278 in every single interface mode that either allow.

Can you post your code that you are using the DataAvailable event?

Is this an actual serial device (RS 232 port) or USB scanner. Are you absolutely sure you have the scanner set up as a serial device rather than a keyboard emulator? Maybe just open notepad and see if the characters show up if you scan something, which indicate you are set up in keyboard emulation.

I can’t but this behavior persists even in the included Xojo Example which has this code in the DataAvailable Event. Nothing that would cause it to fail once and fall behind as it uses ReadAll. And the problem is the event doesn’t fire at all with the first scan and subsequent scans show the data from the previous one. I can confirm this by putting “Break” on the very first line.

Xojo example project code:

If InStr(Me.LookAhead(Encodings.ASCII), Chr(13) + Chr(10)) > 0 Then
OutputArea.Text = OutputArea.Text + Me.ReadAll(Encodings.ASCII)
End If

They are both USB scanners and I’ve tried them as a USB-COM device and as RS232 emulated devices but I did not use it as a USB Keyboard interfaces as that wouldn’t work.

Since they are not emulating keyboards this will not do anything, but I tested it just for the sake of thoroughness and can confirm it doesn’t do anything.

To add, the Xojo example checks for connected serial devices and adds them to a pop-up. They both appear here as expected and have no issue connecting, I just can’t get the data and that breaks my application.

DataAvailble is not in-line, meaning it could send “chunks” of what it has received as to be available currently.

You can best try to buffer and check for a line-ending or another end-marker. If you don’t have an end-maker the see if you know the lenght of the data… and chop it back from there.

As with all serial, tcp or udp connections data won’t come in the pieces you think.

Say you have a barcode:
1234567890
xojo may receive it like:

  • DataAvailable event, ReadAll returns: 12345
  • DataAvailable event, ReadAll returns: 678
  • DataAvailable event, ReadAll returns: 90

That is plain normal behaviour…
ooh it’s because the system has a databuffer, that it wan’t to fill up before it’s sending it to xojo…

I’ve actually controlled for this in my program. I’ve tried two different approaches previously where I test for a termination character (one I set as a global suffix so the scanner always appends it) and either buffer it myself and a ReadAll call or just test with lookaheads for the termination character as Xojo’s example app does.

The problem isn’t chunks of data that don’t make sense, it’s that they come in delayed by one trigger pull.

I suppose this could explain the problem, but I don’t know where I’d even look to adjust this.

You could try it with cool term

See if that has the same issue.