B4R Tutorial [tool] External Serial Connector

SS-2016-04-12_15.23.57.png


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


SS-2016-04-25_09.48.44.png


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.

f5CT6pMMYn.png
 

Attachments

  • B4R_Serial_Connector.zip
    7.2 KB · Views: 1,476
Last edited:

Cableguy

Expert
Licensed User
Longtime User
With this we can use an arduino as a USB device and comunicate with a B4j app, right?
 

Moch Firmansyah

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

Beja

Expert
Licensed User
Longtime 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
Longtime User
What run this
External Serial Connector
on B4J 4.20

reflector - not found
and
udpListener.Initialize2 - not found
 

positrom2

Active Member
Licensed User
Longtime 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:

jarda

Member
Licensed User
Longtime User
Hi
reflector - is ok


udpListener.Initialize2 - not found (only Initialize)

see image
 

Attachments

  • Untitled-11.jpg
    Untitled-11.jpg
    280.1 KB · Views: 1,318

mrred128

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

Similar Threads

Top