B4J Question Serial connection with the Raspberry Pi

Toley

Active Member
Licensed User
Longtime User
Hi Erel, I have made some more test with the serial connection of the Rasberry Pi following the advices you gave me yesterday. The communication works well from the Pi to the window's terminal, but when I try to send data to the Pi I face another problem.

Here is the simplest code I can use for this :
B4X:
'Non-UI application (console application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Private myserial As Serial
    Private astream As AsyncStreams
    Private uart_list As List
    Private sndStr As String
    Private rcvStr As String
End Sub

Sub AppStart (Args() As String)
    myserial.Initialize("")
    uart_list = myserial.ListPorts
    myserial.Open(uart_list.Get(0))
    myserial.SetParams(115200,8,1,0)
    astream.Initialize(myserial.GetInputStream,myserial.GetOutputStream,"astream")
    Log("Initialized")
    StartMessageLoop
End Sub

Sub astream_NewData (Buffer() As Byte)
    rcvStr = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    sndStr = "I have received " & rcvStr & Chr(13) & Chr(10)
    Log(sndStr)
    astream.Write(sndStr.GetBytes("UTF8"))
End Sub

When I send 1 key, the window's terminal become filled with this key and then this Pi send the error message (see attach pictures). Thank you very much for your time.
 

Attachments

  • Serial_in.png
    Serial_in.png
    9 KB · Views: 297
  • Terminal.png
    Terminal.png
    24.3 KB · Views: 289
Top