Android Question Print on com1 using felusb library

fabton1963

Member
Licensed User
Longtime User
Hello,
I waste a lot of time belonging this error and still don't understand how felusb handles usb ports.
I just recompile an old application that uses felusb library for ptint into a thermal printer.
I use a device with many usb ports and the the device path for com1 is /dev/bus/usb/001/010.

this is the code I use to print and works with no change, with the same hardware, using the previous apk built with b4a 8.x with debug sign key
now crash with message "unsupported device" when I call
usbserial.Initialize("serial", device, -1)
the usbport I use is 0 I found it trying all values until device.DeviceName returns /dev/bus/usb/001/010

where I can find more information about the GetDevices's usbport parameters ?
why the new apk crashes and the old one works if I didn't change anything related to usb/serial handling?


B4X:
    If manager.GetDevices.Length = 0 Then
'        'Log("No connected usb devices.")
    Else
    
        Dim device As UsbDevice = manager.GetDevices(usbport) 
        If manager.HasPermission(device) = False Then
            ToastMessageShow("Conferma i permessi e riavvia.", True)
            manager.RequestPermission(device)
        Else

            Log("Provo a stampare su porta "&usbport)
            Log("DeviceClass "&device.DeviceClass)
            Log("DeviceSubclass "&device.DeviceSubclass)
                    
            Log("DeviceName "&device.DeviceName)
            Log("DeviceId "&device.DeviceId)
            Log("VendorId "&device.VendorId)
            Log("ProductId "&device.ProductId)
            Log("InterfaceCount "&device.InterfaceCount)
           
            
            usbserial.Initialize("serial", device, -1)
            Log("inizializzatao il device ")
            
            usbserial.BaudRate = 9600
            usbserial.DataBits = usbserial.DATA_BITS_8
            
        
            usbserial.Write(PrintBuffer.GetBytes("UTF8"))
            'Sleep(1000)
        End If
    End If
 

Attachments

  • photo_2019-04-03_16-28-40.jpg
    photo_2019-04-03_16-28-40.jpg
    164.1 KB · Views: 319
  • photo_2019-04-03_16-29-01.jpg
    photo_2019-04-03_16-29-01.jpg
    123.6 KB · Views: 290

fabton1963

Member
Licensed User
Longtime User
This is the log
Provo a stampare su porta 0
DeviceClass 0
DeviceSubclass 0
DeviceName /dev/bus/usb/001/010
DeviceId 1010
VendorId 2278
ProductId 13433
InterfaceCount 1
main_vvvvvvvvvvvv5 (java line: 831)
java.lang.RuntimeException: UsbDevice is not supported.
at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize2(felUsbSerial.java:79)
at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize(felUsbSerial.java:62)
at vcup.CUP4MedKiosk.main._vvvvvvvvvvvv5(main.java:831)
at vcup.CUP4MedKiosk.main._jobdone(main.java:1875)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:743)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:769)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
--------- beginning of crash
I didn't change anything related to print or usb management just update B4A and felusb with last version

I also try to use usbserial.Initialize2("serial",device, 1,"CP2102SerialDevice") but I still cannot initialize usbserial.
DeviceClass 0
DeviceSubclass 0
DeviceName /dev/bus/usb/001/010
DeviceId 1010
VendorId 4939
ProductId 518
InterfaceCount 2
Buffer size: 16384
main_aprostampante2 (java line: 831)
java.lang.RuntimeException: Error opening serial device.
at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize2(felUsbSerial.java:82)
at vcup.CUP4MedKiosk.main._aprostampante2(main.java:831)
at vcup.CUP4MedKiosk.main._jobdone(main.java:1875)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:743)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:769)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
--------- beginning of crash

I try also with usbserial2 lib with no success.
Using the same code in another device with the same hardware it works good, the difference is the port value in the working device is nr 2.
I dont understand the real meaning of the parameter required by GetDevices() method of felusb class and how android assign it to an hardware device your examples use allways 0 value assuming that there is exactly one device but what do you mean with device, the usb bridge or the connected usb device ?
I'm very confused beacause the chip used by my hardware should be supported by felusb and until saturday it worked perfectly.
 
Upvote 0

fabton1963

Member
Licensed User
Longtime User
[solved]
if I try to print with the hardware's diagnostic software It works with device name /dev/bus/usb/001/010
I printed the device info from device 0 to 4 using manager.GetDevices(usbport)
the device corresponding to device name /dev/bus/usb/001/010 is nr 0
but the silicon labs device is nr 4 so I set usbport to 4
and now it works again.
My mistake .
 

Attachments

  • device0.jpg
    device0.jpg
    34.3 KB · Views: 273
  • device1.jpg
    device1.jpg
    36.8 KB · Views: 271
  • device2.jpg
    device2.jpg
    44.3 KB · Views: 274
  • device3.jpg
    device3.jpg
    41.5 KB · Views: 256
  • device4.jpg
    device4.jpg
    43.2 KB · Views: 265
Upvote 0
Top