Hello!
I'm trying to connect USB devices to an Android device, specifically RFID and barcode readers. Of course, I don't want to have the events dragged into the keyboard, but read out directly via the port.
I had already tried this one, but unfortunately it crashes and tells me that the device is not supported
There must be an easy way to listen to a USB port and read the events, or not ?
If someone has experience, I would be very grateful, because so far I have not been successful for two days now
Martin
I'm trying to connect USB devices to an Android device, specifically RFID and barcode readers. Of course, I don't want to have the events dragged into the keyboard, but read out directly via the port.
I had already tried this one, but unfortunately it crashes and tells me that the device is not supported
felUsbSerial - Alternative Usb Serial library
This library wraps the following open source project: https://github.com/felHR85/UsbSerial (MIT license). It is an alternative to the UsbSerial2 library. The following devices are supported: CP210x, CDC, FTDI, PL2303 and CH34x. Usage is simple. You find the UsbDevice with USB library and then...
www.b4x.com
There must be an easy way to listen to a USB port and read the events, or not ?
If someone has experience, I would be very grateful, because so far I have not been successful for two days now
Martin
Test RFID and Barcode Readers:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private TimerPulse As Timer
Private usbM As UsbManager
Private myRFID As felUsbSerial
End Sub
Private Sub TestStart
Dim UsbDevices() As UsbDevice
UsbDevices = usbM.GetDevices
If UsbDevices.Length = 0 Then
ToastMessageShow("No connected usb devices.", True)
Else
For z = 0 To UsbDevices.Length - 1
Dim UsbDvc As UsbDevice
UsbDvc = UsbDevices(z)
Log (UsbDvc.DeviceName)
Log (UsbDvc.DeviceId)
Log (UsbDvc.ProductId)
Log (UsbDvc.VendorId)
If UsbDvc.DeviceId = 1004 Then
If usbM.HasPermission(UsbDvc) = True Then
myRFID.Close
myRFID.Initialize("RFIDReader", UsbDvc,-1)
myRFID.BaudRate = 9600
myRFID.DataBits =myRFID.DATA_BITS_8
Else
ToastMessageShow("keine Erlaubnis",True)
usbM.RequestPermission(UsbDvc)
End If
End If
Next
End If
End Sub
Sub RFIDReader_DataAvailable (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
ToastMessageShow(msg,True)
End Sub