B4J Library jSerial library

Not open for further replies.
The jSerial library allows you to open and communicate with other devices through the computer COM ports.

It can also be used to communicate with Bluetooth devices over a virtual com port.
(jBluetooth library is now available: https://www.b4x.com/android/forum/threads/jbluetooth-library.60184/)


The attached examples implement an Android <-> PC chat app.

In order to run the example you need to first pair the PC and the device and make sure that the Bluetooth is mapped to a virtual com port.

jSerial works with AsyncStreams. Both standard mode and prefix mode are supported. Note that prefix mode can only work if both sides of the connection follow the protocol.
Change AStream.InitializePrefix to AStream.Initialize to disable prefix mode.

jSerial depends on an open source project named JSSC: https://github.com/java-native/jssc

v1.32 - Based on jssc v2.9.4.
v1.31 - Adds missing BAUDRATE, DATABITS, STOPBITS and PARITY constants.
v1.30 - Adds support for Java 11 and 64 bit computers based on: https://github.com/java-native/jssc

Instructions related to jSerial and B4J Packager 11: https://www.b4x.com/android/forum/threads/jserial-library.34762/post-735742


  • B4J_Chat.zip
    1.7 KB · Views: 4,775
  • B4A_Chat.zip
    9.2 KB · Views: 2,842
  • jSerial.zip
    500.3 KB · Views: 1,097
Last edited:


Licensed User
Ok here's the result:
The program runs without problem when started with java -jar Monitor.jar

So no logs to indicate what goes wrong when running as .exe


Licensed User
Any ideas?
What's the difference between the .exe and the .jar prog?
Is it to do with Windows 10 maybe? Still stuck!


Licensed User
1. yes
2. I don't know how. The packager does not prompt me for it, nor does the installer(= the exe that the packager creates)
Instead I manually copied the directory to C:\chat (didn't work either) and then to E:\chat same result.


Licensed User
Thanks for your troubles.
It's not the version, but must be something in Windows 10. I tried compatibility modes.
Would not be the first problem with W10 now would it :eek:
Thanks again


Active Member
Licensed User
Longtime User
This library (Serial) also works with NON-UI apps?
I made an app UI that receives data from the serial and it all works.
Now I did the same app but NOT-UI version, but does not work.
With the logs I saw that the serial port is open and without errors, but the "NewData" event never comes.

Sub AStream_NewData (Buffer() As Byte)
        ValRX = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
        Log("ERROR - NewData")
    End Try
End Sub

Thanks Marco


hi erel i try to use the chat, if i use with b4j consolle ( debug or release or offiscated) iys well, byt if i comile and run jar file the application stop.

if i takeoff 'sp.open("Com4") the app function , but as normal dont recieve message,

the serial port in my pc is emulated by a software emulator ( virtual serial port emulator) that function well, when i try with the consolle b4j all is well.

i try to start program with a bat file as administrator but nothing good..




Licensed User
Longtime User
Try this:
Dim jo As JavaObject = serialport
Dim DCD As Boolean = jo.GetFieldJO("sp").RunMethod("isRLSD", Null)
Thanks Erel, I tried this this morning and the second line, (Dim DCD .... ), generates an exception w.r.t. the field "sp" not found anywhere ...
"java.lang.RuntimeException: Field: sp not found in: anywheresoftware.b4j.serial.Serial"

Is there a way to list/find all of the valid field names ?
Not open for further replies.