B4J Library jSerial library

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

SS-2013-11-21_15.46.10.png


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

Attachments

  • B4J_Chat.zip
    1.7 KB · Views: 5,168
  • B4A_Chat.zip
    9.2 KB · Views: 3,124
  • jSerial.zip
    500.3 KB · Views: 1,609
Last edited:

rdkartono

Member
Licensed User
Longtime User
Hi Erel,

Set Parameter already correct (4800 bps, 8 bit, 1 stop bit, None parity), because i already can read GPS string correctly. I can get correct Time, Longitude, and Latitude string. This port (/dev/ttyAMA0) is the result from "dmesg | grep tty".
I tried calling GPS_PORT.PurgePort(GPS_PORT.PURGE_RXCLEAR) everytime AsyncStreams.New_Data event triggered (after i get the data), yet still after few seconds std::bad_alloc still showed.
I tried polling to serialport bytesavailable value using a timer with interval 1 ms, yet bytesavailable always return 0.
I tried to wrap serial port inputstream to TextReader, yet also no data available.

It seems that AsyncStreams.New_Data event is the only way to get serial data, yet it is unstable.

Please advice more.
Thanks.
 

a_carignan

Member
Licensed User
Longtime User
I can not connect the two software together. on the phone, it displays an error connecting to the computer and it shows no wear.
 

alexhi

Member
Licensed User
Longtime User
sp.Open(cmbPort.Value) Works in Windows but does not work Mac OS , in Mac OS X 10.9 receives NULL
 

wonder

Expert
Licensed User
Longtime User
I need help! :(

I did everything right, paired my phone with the PC. Added a COM port and tried to connect.
When I choose my PC name, I get a pairing request on my phone, which after one second disappears and I get a "connection reset by peer" java.io error.
I've tried the prefix and standard mode, recompiling both B4A and B4A apps. HELP! :(

help.png
 

SimonElck

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: https://www.b4x.com/android/forum/threads/jbluetooth-library.60184/)

SS-2013-11-21_15.46.10.png


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: http://code.google.com/p/java-simple-serial-connector/ (the jar file is included in the zip file).
I compiled this program an ran it.
It works fine, BUT
as soon as I make an installable version with packager, it does not work anymore.
It quits at the line sp.Open(cmbPort.Value)
Even when I put it in a try /catch it quits
Again the prog works fine when I run it, either debug or release.
It has nothing to do with readonly files either.

Please help, I'm stuck!
 

SimonElck

Member
Licensed User
Thanks Erel,
It's going to be a bit awkward for my users.
Will the packager installed Java still be sufficient when going this way, or will the end-users have to install jre or something?
 
Status
Not open for further replies.
Top