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
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)