B4J Library jSerial library

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
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: http://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

Updates:
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
 

Attachments

Last edited:

Chris_Moulding

Member
Licensed User
Hi,

Does the jserial library work with USB ports? I've searched for documentation on the jserial library but I've not found it yet.

Regards,

Chris
 

kris_audi

Member
Licensed User
Hi,
How I can set param COM port (Even parity)?

Private sp As Serial
sp.Open("")
sp.SetParams(9600,8,1,?)
 

marco.canta

Active Member
Licensed User
How I can set param COM port (NONE parity) ?

I use ... 2400, 8 ,none,1

where can I find an example to get data?
I need to receive data from Arduino


Thanks
 

kris_audi

Member
Licensed User
Hi.

When I close the app I receive the mistake:

Program started.
jssc.SerialPortException: Port name - COM1; Method name - getInputBufferBytesCount(); Exception type - Port not opened.
at jssc.SerialPort.checkPortOpened(SerialPort.java:862)
at jssc.SerialPort.getInputBufferBytesCount(SerialPort.java:786)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:110)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:105)
at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:184)
at java.lang.Thread.run(Thread.java:722)
java.lang.RuntimeException: jssc.SerialPortException: Port name - COM1; Method name - getInputBufferBytesCount(); Exception type - Port not opened.
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:118)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:105)
at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:184)
at java.lang.Thread.run(Thread.java:722)
Caused by: jssc.SerialPortException: Port name - COM1; Method name - getInputBufferBytesCount(); Exception type - Port not opened.
at jssc.SerialPort.checkPortOpened(SerialPort.java:862)
at jssc.SerialPort.getInputBufferBytesCount(SerialPort.java:786)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:110)
... 3 more
 

kris_audi

Member
Licensed User
Hi.

I use astream.Close in MainForm_Close event and I receive the mistake:

Program started.
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:111)
at anywheresoftware.b4j.serial.Serial$1.read(Serial.java:105)
at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:184)
at java.lang.Thread.run(Thread.java:722)
 
Status
Not open for further replies.
Top