B4J Question [SOLVED]Raspberry Pi Zero 2 W cannot open the serial port

tzfpg

Active Member
Licensed User
Longtime User
When I run the program, i get a error messages
B4X:
Waiting for debugger to connect...
Program started.
java.lang.UnsatisfiedLinkError: 'long jssc.SerialNativeInterface.openPort(java.lang.String, boolean)'
    at jssc.SerialNativeInterface.openPort(Native Method)
    at jssc.SerialPort.openPort(SerialPort.java:158)
    at anywheresoftware.b4j.serial.Serial.Open(Serial.java:78)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:673)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.
internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
    at b4j.example.main.main(main.java:29)
java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: 'long jssc.SerialNativeInterface.openPort(java.lang.String, boolean)'
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:138)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
    at b4j.example.main.main(main.java:29)
Caused by: java.lang.UnsatisfiedLinkError: 'long jssc.SerialNativeInterface.openPort(java.lang.String, boolean)'
    at jssc.SerialNativeInterface.openPort(Native Method)
    at jssc.SerialPort.openPort(SerialPort.java:158)
    at anywheresoftware.b4j.serial.Serial.Open(Serial.java:78)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runVoidMeth
od(Shell.java:673)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
    ... 3 more
Program terminated (StartMessageLoop was not called).

my B4j code
B4X:
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Private sp As Serial
    Private astream As AsyncStreams
    Private bc As ByteConverter
    
End Sub

Sub AppStart (Args() As String)
    sp.Initialize("")
    sp.Open("/dev/ttyAMA0")
    sp.SetParams(9600,8,1,0)
    astream.Initialize(sp.GetInputStream,sp.GetOutputStream,"AStream")
    StartMessageLoop
End Sub


Sub AStream_NewData (Buffer() As Byte)
    Log("AStream_NewData : " & bc.HexFromBytes(Buffer))
End Sub


Sub AStream_Error
    Log("AStream_Error")
End Sub

Sub AStream_Terminated
    Log("AStream_Terminated")
End Sub

I use python to write a testing receive data from serial, I can get all the data.

here is my python code
B4X:
#!/usr/bin/env python
import time
import serial

ser = serial.Serial(
        port='/dev/ttyAMA0',
        baudrate = 9600,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1
)

while 1:
        x=ser.readline()
        print(x)

Raspberry pi side serial already can read data, but b4j error when open port.

Please help me look the code, which part I do wrong.
 
Top