B4R Tutorial [tool] External Serial Connector

Erel

Administrator
Staff member
Licensed User


This is a small B4J program that uses jSerial library to connect to an Arduino board.

To see it working start with this simple B4R program:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private astream As AsyncStreams
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   astream.Initialize(Serial1.Stream, "Astream_NewData", "Astream_Error")
End Sub

Sub Astream_NewData (Buffer() As Byte)
   Log("Received: ", Buffer)
End Sub

Sub AStream_Error
   Log("error")
End Sub



In this mode the IDE will send a message to the serial connector to close the serial port during compilation and to open it afterward.

You can modify the code to send binary data instead of strings.

Updates

- v1.20 - Uses a small console app to get the ports description.

 

Attachments

Last edited:

Moch Firmansyah

Member
Licensed User
is like hyperterminal for direct serial communication, gateway only or virtual communication port as VSPD(virtual serial port driver)?
 

Beja

Expert
Licensed User
Thanks Erel, but sorry not following.. I see only one B4J app in which it sends eg4g from one editbox and receives it in another editbox in the same B4J app (unless I am missing something)
Can we have a block diagram of the system so we can see the different components?
Thanks.
 

jarda

Member
Licensed User
What run this
External Serial Connector
on B4J 4.20

reflector - not found
and
udpListener.Initialize2 - not found
 

positrom2

Active Member
Licensed User
Edit: Solved:
I had copied j... library files to the B4R libraries. Unchecking them in the library manager the program compiles.
By the way, I have several j... lib files in the B4R folder. Must they all be removed?

Original post:
Error message when compiling the code from first post. I have followed the two links at the end of the first post:
B4R version: 1.00
Parsing code. (0.00s)
Compiling code. Error
Error compiling program.
Error description: Cannot cast type: {Type=Stream,Rank=0, RemoteObject=True} to: {Type=java.io.InputStream,Rank=0, RemoteObject=True}
Occurred on line: 10
astream.Initialize(Serial1.Stream, "Astream_NewData", "Astream_Error")
Word: stream
 
Last edited:

mrred128

Active Member
Licensed User
I removed all refs to network objects and removed jNetwork. It worked fine. Was this console made for something else initially?
 
Top