Android Question felUsbSerial questions

red30

Well-Known Member
Licensed User
Longtime User
B4X:
Sub btnConnect_Click
   If manager.GetDevices.Length = 0 Then
     Log("No connected usb devices.")
   Else
     Dim device As UsbDevice = manager.GetDevices(0) 'assuming that there is exactly one device
     If manager.HasPermission(device) = False Then
       ToastMessageShow("Please allow connection and click again.", True)
       manager.RequestPermission(device)
     Else
       usbserial.Initialize("serial", device, -1)
       usbserial.BaudRate = 115200
       usbserial.DataBits = usbserial.DATA_BITS_8
       usbserial.StartReading
     End If
   End If
End Sub
1) In this part of the code, after one device is detected, permission is requested, and after that you need to click this button again to establish a connection with this device. How can I make it so that if permission has been obtained, then immediately establish communication with the device? (In order not to press the button again) And if permission has not been obtained, then display the message “Allow the connection to connect to the device”

2) If you do not explicitly choose a serial class, then with the “CDCSerialDevice” devices the application crashes with an error, but with “FTDISerialDevice” everything works fine. Why it happens?
B4X:
main_button1_click (java line: 377)
java.lang.RuntimeException: Error opening serial device.
    at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize2(felUsbSerial.java:82)
    at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize(felUsbSerial.java:62)
    at b4a.example.main._button1_click(main.java:377)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6608)
    at android.view.View.performClickInternal(View.java:6585)
    at android.view.View.access$3100(View.java:778)
    at android.view.View$PerformClick.run(View.java:25944)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6865)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:504)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 
Top