qzind / tray

Browser plugin for sending documents and raw commands to a printer or attached device.
https://qz.io
Other
831 stars 272 forks source link

Bluetooth barcode scanner #624

Open thbl opened 4 years ago

thbl commented 4 years ago

Hi I'm new to QZ, as i understand it i can use the HID api to read input from etc. a barcode scanner / keyboard ?

Tho i have tried claming device in demo and click open stream, i get no data from keyboard / barcode scanner ?

What am i doing wrong, using version 2.1

tresf commented 4 years ago

Barcode scanners generally ship with interfaces that are pre-configured. There are many different configurations, but in regards to connectivity, they generally support:

Unfortunately, the default configuration of these devices isn't always obvious. In the case of my scanner, there was a booklet that shipped with it and I had to scan a configuration barcode to switch it from keyboard mode to HID mode.

Note, QZ Tray has been tested with Symbol (Zebra) and Honeywell barcode scanners in HID mode.

thbl commented 4 years ago

@tresf Thanks for your reply ! :)

HID is kind of serial emulation ? Maby i should look for a SPP scanner instead, QZ should support this ?

tresf commented 4 years ago

HID is kind of serial emulation ?

Although some USB devices offer serial emulation, HID is quite different from serial.

Maby i should look for a SPP scanner instead, QZ should support this ?

I'm not sure what an SPP scanner is, but if you share the make/model of your barcode scanner, we can check quickly if it supports HID communication. Symbol (now part of Zebra) is the most popular barcode scanner in the United States and our product works with that just fine. Honeywell is another popular brand and we were able to get it working with some custom code (#288) so that is supported as well.

If your scanner is acting as a keyboard, you should see if it offers HID support, or share the product information with us so that we can check for you.

thbl commented 4 years ago

@tresf its just a cheep no brand bluetooth barcode scanner. Tho in device maneger it says "HID..." but it writes on screen like a keyboard.

Do you have any experience with bluetooth reders ? i looked at zebra & Honeywell but they looks exspensive ^^ thinking on maby buying this https://tera-digital.com/collections/barcode-scanner-2d/products/tera-wireless-barcode-scanner-compatible-with-bluetooth#download

Thanks for your help so far ! :)

tresf commented 4 years ago

@tresf its just a cheep no brand bluetooth barcode scanner.

We're still interested, we try to be hardware agnostic and if there are cheap bluetooth barcode scanners being bought on mass, we'd love to support them like the big brands.

That said, bluetooth is an odd technology to interact with, so we'll need some more information. Firstly, yes, serial is a viable option for some Bluetooth devices, so I'll have to double-back a bit on my previous HID statements. This is because Bluetooth very specifically provides an RS232 emulation layer in the protocol. If you have a way to enable this, you can use our Serial API to communicate with the scanner.

In regards to the Tera digital brand, I have a feeling the comms will be very similar. Most often the cheaper hardware providers attempt to mimic the more expensive brands.

thbl commented 4 years ago

As i have read "HID MODE" is default for ble scanners, and only some support SPP mode (RS232 emulation) The one i have don't support SPP mode, think i will buy the Tera one that supports SPP mode and do a test with that... :)

tresf commented 4 years ago

I have a Tera model arriving next Tuesday, so we can test viability.

thbl commented 4 years ago

@tresf i also just oredre a Tera T5100, so will get back to you when it arrives and i have testet :D

thbl commented 4 years ago

@tresf just got my T5100 today It has 3 BLE modes

So i guess the only way to make ble barcode reader work with QZ is to use the SPP mode with COM. Tho i think this will give some issues when reader goes in standby.

thbl commented 4 years ago

@tresf is it possible to listen for when BLE device connects / disconnect ? To open / close COM As when reader goes from active -> standby -> active You need to close & open COM for it to work again

tresf commented 4 years ago

@tresf is it possible to listen for when BLE device connects / disconnect ? To open / close COM

Not really. You can continuously scan the COM ports and pop something up when a new one's discovered but the COM is relatively generic and if it's through Bluetooth I don't know if the OS removes and re-adds it each time it "connects", knowing it's the scanner would be quite hard, we'd need proper Bluetooth support to know that it's that actual scanner. Bluetooth support doesn't exist for Java proper, so it would be a pretty large enhancement to add it.

thbl commented 4 years ago

@tresf any sugestions on what else to do ? :)

tresf commented 4 years ago

@tresf any sugestions on what else to do ? :)

Mine will arrive on Friday and I'll know more. I don't have an SPP device to know the behavior. My experience with virtual COM ports is you can assign a number, so that might be a good way to control it, e.g. always use COM15 for scanner and you can have a way to check that port.

I don't know how this would work on Mac or Linux though. I'll know more when the hardware arrives, I guess. :D

thbl commented 4 years ago

@tresf in windows bluetooth maneger you can defind what virtual COM the bluetooth device should use. Will do more testing tomorrow, but as i saw it the virtual ble com is always there even device is offline. So main problem is to check what ever device is connected or not.

tresf commented 4 years ago

Blutetooth HID mode

Yeah they call it HID, but it's probably more accurately a HID keyboard, which we're locked out of communicating with for security/keylogging purposes. 🤣

Blutetooth BLE mode

I'd guess this is JSR-82, which is a proposal for Java to have Bluetooth support. It's implemented by a few open source libraries that we can include, but would offer a brand new tab to QZ Tray and take a few months to sort out. "BLE" I believe stands for "Bluetooth Low Energy" which I believe is a way for devices that go to sleep to have a way to wake up and be used immediately, a feature that would be great for QZ Tray, but would need to be slated for a later release.

Blutetooth SPP mode

I'm curious how the port behaves when the device sleeps or gets powered off. I think handling these scenarios is going to prove whether or not SPP is a viable solution. Since they offer this mode, it may be as easy as periodically checking that port, handling closing/opening, etc. This should be relatively easy if the COM port doesn't constantly change.

tresf commented 4 years ago

I'm curious how the port behaves when the device sleeps or gets powered off.

A good way to test this without QZ Tray is to install Putty, open to that COM port and see how Putty behaves. Putty is a nice way to testout the communication for a serial device without having QZ Tray in the middle. We should be able to mimic Putty.

thbl commented 4 years ago

@tresf yea it would be great to have BLE support. For SPP you can assign a static COM, but not 100% on the open/close after standby. Will do more testing on the behavior tomorrow forgot the reader at office xD

tresf commented 4 years ago

Will do more testing on the behavior tomorrow forgot the reader at office xD

Mine will be in tomorrow too, we'll know more then.

thbl commented 4 years ago

@tresf BLE Reader set to COM10

QZ List serial ports always show COM10 even when reader is offline.

PUTTY Reader offline -> open COM10 -> err:"Unable to open connection to COM10, Unable to open serial port" Reader online -> open COM10 (Works) When serial is open and reader goes offline/sleep mode, com windows is still showen in putty. But it dosent work before you close it and open a new window.

tresf commented 4 years ago

@thbl I ran out of time today, but when I get to this, I'll attempt to put together a small routine which automatically checks and opens communication to the device. I should have time time in the next few days.

thbl commented 4 years ago

@tresf I found that for BLE there is actly already BLE build in most browsers. "Web Bluetooth" https://webbluetoothcg.github.io/web-bluetooth/ https://googlechrome.github.io/samples/web-bluetooth/

"LightBlue" app from android store can be used for find custom services/UUID

For Tera T5100 i found the BLE service to be 0000feea-0000-1000-8000-00805f9b34fb and the characteristic (data to read / notify) 00002aa1-0000-1000-8000-00805f9b34fb

I know this is a bit off topic, but wanted to share my findings as this has solved my app issue for the moment.. :)

thbl commented 4 years ago

@tresf I found that for BLE there is actly already BLE build in most browsers. "Web Bluetooth" https://webbluetoothcg.github.io/web-bluetooth/ https://googlechrome.github.io/samples/web-bluetooth/

"LightBlue" app from android store can be used for find custom services/UUID

For Tera T5100 i found the BLE service to be 0000feea-0000-1000-8000-00805f9b34fb and the characteristic (data to read / notify) 00002aa1-0000-1000-8000-00805f9b34fb

I know this is a bit off topic, but wanted to share my findings as this has solved my app issue for the moment.. :)

Seams like its not possible to auto connect to a device tho..... :/ So think best way is if we can get the SPP serial to work some how with QZ @tresf looking forward to see if you can get this to work :D

thbl commented 4 years ago

@tresf maby this could be used in QZ to detected if device close com ? https://stackoverflow.com/questions/45344383/detect-bluetooth-spp-disconnection-without-using-packets

tresf commented 4 years ago

@tresf maby this could be used in QZ to detected if device close com ? https://stackoverflow.com/questions/45344383/detect-bluetooth-spp-disconnection-without-using-packets

I tried to continuously send data to the device in hopes that the interrupted connection would be caught, but it's not. Even Putty seems confused that the device has lost connection.

There's a barcode you can scan which will increase the default sleep time to 30 minutes with the downside of decreasing the battery life.

I'm also getting QZ Tray to become confused about whether or not the port is opened, requiring me to restart QZ Tray between tests.

Proper wake/sleep will likely require a bluetooth library and API expansion. Thoughts are welcome.

tresf commented 4 years ago

Perhaps a middleground is to set a JavaScript timeout that matches the scanner's default timeout which closes the port just before sleep occurs. I can assume that received data is the time it's going to start it's sleep countdown from. It's not ideal, but should at least close the connection out cleanly.

thbl commented 4 years ago

@tresf think it will give troubles to do a timeout function in JS. If time dosent match 100% it will get stucked anyways

thbl commented 4 years ago

@tresf did you check if tera HID over cable works with qz ?

tresf commented 4 years ago

@tresf did you check if tera HID over cable works with qz ?

No I haven't but I'd expect this to work just fine, we're already integrated with Honeywell, Symbol (Zebra) without issue.

tresf commented 4 years ago

@tresf did you check if tera HID over cable works with qz ?

Albeit off-topic to the bluetooth portion of this bug report, I did try, but mine only offered Keyboard Emulation which I was unable to listen upon. I'd be happy to discuss this further over at #634.