Nov 21, 2013 Replies: 103 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 Updates: v1.40 - Based on jssc v2.9.6. Provides better handling of low level errors. Edit: a new zip was uploaded which fixes an issue with the standalone packager. 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 B4J_Chat.zip 1.7 KB · Views: 5,892 B4A_Chat.zip B4A_Chat.zip 9.2 KB · Views: 3,751 jSerial.zip jSerial.zip 477.6 KB · Views: 1,091 Last edited: Mar 6, 2025 Click to expand...
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 Updates: v1.40 - Based on jssc v2.9.6. Provides better handling of low level errors. Edit: a new zip was uploaded which fixes an issue with the standalone packager. 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
S SimonElck Member Licensed User Mar 2, 2016 #61 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
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
S SimonElck Member Licensed User Mar 3, 2016 #62 Any ideas? What's the difference between the .exe and the .jar prog? Is it to do with Windows 10 maybe? Still stuck!
Any ideas? What's the difference between the .exe and the .jar prog? Is it to do with Windows 10 maybe? Still stuck!
Erel B4X founder Staff member Licensed User Longtime User Mar 3, 2016 #63 1. Have you tried to run it as an admin? 2. Have you tried to install it to a different folder (c:\test)?
1. Have you tried to run it as an admin? 2. Have you tried to install it to a different folder (c:\test)?
S SimonElck Member Licensed User Mar 3, 2016 #64 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.
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.
Erel B4X founder Staff member Licensed User Longtime User Mar 3, 2016 #65 Can you upload the installation file (upload it to dropbox or a similar service)?
S SimonElck Member Licensed User Mar 3, 2016 #66 Le Voila: https://drive.google.com/file/d/0B3BMyh__aPVwaHEtTkdZWlVlVEk/view?usp=sharing
Erel B4X founder Staff member Licensed User Longtime User Mar 4, 2016 #67 Works fine here. My guess is that it is related to the java version or to a permission problem.
S SimonElck Member Licensed User Mar 4, 2016 #68 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 Thanks again
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 Thanks again
marco.canta Active Member Licensed User Longtime User Mar 16, 2016 #69 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. Code: Sub AStream_NewData (Buffer() As Byte) Try ValRX = BytesToString(Buffer, 0, Buffer.Length, "UTF8") Log(ValRX) Catch Log("ERROR - NewData") End Try End Sub Thanks Marco
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. Code: Sub AStream_NewData (Buffer() As Byte) Try ValRX = BytesToString(Buffer, 0, Buffer.Length, "UTF8") Log(ValRX) Catch Log("ERROR - NewData") End Try End Sub Thanks Marco
Erel B4X founder Staff member Licensed User Longtime User Mar 16, 2016 #70 marco.canta said: This library (Serial) also works with NON-UI apps? Click to expand... Yes. Make sure to call StartMessageLoop at the end of AppStart.
marco.canta said: This library (Serial) also works with NON-UI apps? Click to expand... Yes. Make sure to call StartMessageLoop at the end of AppStart.
marco.canta Active Member Licensed User Longtime User Mar 16, 2016 #71 Thanks Erel. I had forgotten "Start Message Loop". Now it all works
Erel B4X founder Staff member Licensed User Longtime User Jun 23, 2016 #72 v1.06 is available. It allows accessing the native jssc.SerialPort with JavaObject.
S skeedsr Member Jul 12, 2016 #73 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.. thanks!! livio
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.. thanks!! livio
Erel B4X founder Staff member Licensed User Longtime User Jul 12, 2016 #74 Please start a new thread for this question.
W wcieslik Member Licensed User Longtime User Nov 2, 2016 #76 Hello, Is it possible to get the status of the DCD line ? (eg like CTS and DSR) ?
Erel B4X founder Staff member Licensed User Longtime User Nov 2, 2016 #77 Try this: Code: Dim jo As JavaObject = serialport Dim DCD As Boolean = jo.GetFieldJO("sp").RunMethod("isRLSD", Null)
Try this: Code: Dim jo As JavaObject = serialport Dim DCD As Boolean = jo.GetFieldJO("sp").RunMethod("isRLSD", Null)
W wcieslik Member Licensed User Longtime User Nov 3, 2016 #78 Erel said: Try this: Code: Dim jo As JavaObject = serialport Dim DCD As Boolean = jo.GetFieldJO("sp").RunMethod("isRLSD", Null) Click to expand... 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 ?
Erel said: Try this: Code: Dim jo As JavaObject = serialport Dim DCD As Boolean = jo.GetFieldJO("sp").RunMethod("isRLSD", Null) Click to expand... 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 ?
Erel B4X founder Staff member Licensed User Longtime User Nov 3, 2016 #79 Are you using jSerial v1.06: https://www.b4x.com/android/forum/threads/jserial-library.34762/ ?
W wcieslik Member Licensed User Longtime User Nov 3, 2016 #80 Erel said: Are you using jSerial v1.06: https://www.b4x.com/android/forum/threads/jserial-library.34762/ ? Click to expand... Thanks Erel, Appologies, I was using jSerial v1.05. jSerial v1.06 works like a charm ! Thank you again.
Erel said: Are you using jSerial v1.06: https://www.b4x.com/android/forum/threads/jserial-library.34762/ ? Click to expand... Thanks Erel, Appologies, I was using jSerial v1.05. jSerial v1.06 works like a charm ! Thank you again.