Android Question felUsbSerial-error:maybe SDK26 or android-28\android.jar

f0raster0

Well-Known Member
Licensed User
Hi guys

What can be this error:
B4X:
Logger connected to:  samsung GT-I9300
--------- beginning of /dev/log/main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_btnconnect_click (java line: 392)
java.lang.RuntimeException: Error opening serial device.
    at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize2(felUsbSerial.java:74)
    at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize(felUsbSerial.java:54)
    at b4a.examplek.main._btnconnect_click(main.java:392)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:4475)
    at android.view.View$PerformClick.run(View.java:18786)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5419)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
    at dalvik.system.NativeStart.main(Native Method)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_btnconnect_click (java line: 392)
java.lang.RuntimeException: Error opening serial device.
    at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize2(felUsbSerial.java:74)
    at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize(felUsbSerial.java:54)
    at b4a.examplek.main._btnconnect_click(main.java:392)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:4475)
    at android.view.View$PerformClick.run(View.java:18786)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5419)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
    at dalvik.system.NativeStart.main(Native Method)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
main_btnconnect_click (java line: 392)
java.lang.RuntimeException: Error opening serial device.
    at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize2(felUsbSerial.java:74)
    at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize(felUsbSerial.java:54)
    at b4a.examplek.main._btnconnect_click(main.java:392)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:4475)
    at android.view.View$PerformClick.run(View.java:18786)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5419)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
    at dalvik.system.NativeStart.main(Native Method)
--------- beginning of /dev/log/system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_btnconnect_click (java line: 392)
java.lang.RuntimeException: Error opening serial device.
    at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize2(felUsbSerial.java:74)
    at anywheresoftware.b4a.objects.usb.felUsbSerial.Initialize(felUsbSerial.java:54)
    at b4a.examplek.main._btnconnect_click(main.java:392)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:4475)
    at android.view.View$PerformClick.run(View.java:18786)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5419)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
    at dalvik.system.NativeStart.main(Native Method)
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **


I'm using this library/example, last month this example was working fine
https://www.b4x.com/android/forum/threads/felusbserial-alternative-usb-serial-library.62216/
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private usbserial As felUsbSerial
    Private manager As UsbManager
    Private bc As ByteConverter
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Private ScrollView1 As ScrollView
    Private EditText1 As EditText
End Sub



Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
   If FirstTime Then
     manager.Initialize
   End If
   Dim btnConnect As Button
   btnConnect.Initialize("btnConnect")
   btnConnect.Text = "Connect"
   'Activity.AddView(btnConnect, 10dip, 10dip, 100dip, 100dip)
End Sub

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

Private Sub serial_DataAvailable (Buffer() As Byte)
   'Log("Buffer: " & Buffer)
    ToastMessageShow( bc.StringFromBytes(Buffer,"UTF8"),False)
    Log(bc.StringFromBytes(Buffer,"UTF8"))
   Log("New data: " & bc.HexFromBytes(Buffer))
    EditText1.Text=("data: "&bc.HexFromBytes(Buffer))
    
End Sub

What is different between last moth and now, only changed :

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="26"/>
and
C:\Android\platforms\android-28\android.jar

thank you for any help
 
Last edited:

DonManfred

Expert
Licensed User
Upvote 0

f0raster0

Well-Known Member
Licensed User
Does it work if you set the targetSdkVersion to 14?
yes, I went back to
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15"/>
C:\Android\platforms\android-28\android.jar
and it works fine (it's ok for now, how this app only will be used in a private unique tablet)
 
Upvote 0
Top