Android Question Add Event on serial input

freetoair

Member
Licensed User
Longtime User
Is it possible to add an event when new data arrives at "serinp = File.OpenInput ("", "/ dev / ttyS0")" ?
 

freetoair

Member
Licensed User
Longtime User
B4X:
sout = File.OpenOutput("","/dev/ttyS0",True) ' open serial output
      sinp = File.OpenInput("","/dev/ttyS0") ' open serial input
    astreams.Initialize(sinp,sout, "astreams")
 
Upvote 0

freetoair

Member
Licensed User
Longtime User
Yes, on the transmit side is ok, but I had to add "sout.Flush" after each "astreams.Write (Array As Byte (Convert.outpkt (2)))" .But the rx side seems to astreams not deleted input buffer (sinp) when reading. At least, it seems to me when I follow the flow of data on to the serial terminal.
 
Upvote 0

freetoair

Member
Licensed User
Longtime User
Now I've tried and the service module, and do not know if this is right?
B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
'    sout = File.OpenOutput("","/dev/ttyS0",True) ' open serial output
'       sinp = File.OpenInput("","/dev/ttyS0") ' open serial input
'   
    Dim inpkt(128) As Byte ' serial comm input packet buffer
    Dim sout As OutputStream ' serial out stream
      Dim sinp As InputStream ' serial in stream
    Dim c, rxlen As Int
    Dim s As String
End Sub

Sub Service_Create
    sout = File.OpenOutput("","/dev/ttyS0",True) ' open serial output
      sinp = File.OpenInput("","/dev/ttyS0") ' open serial input
    End Sub

Sub Service_Start (StartingIntent As Intent)

    rxlen = sinp.BytesAvailable ' check if bytes available on serial input
   If rxlen > 0 Then
     sinp.ReadBytes(inpkt,0,rxlen) ' read pending characters
      s = "" ' clear string
      For c = 0 To rxlen-1 ' build string from characters
         s = s & Chr(inpkt(c))
      Next
         'Log(s)
        ToastMessageShow (s,True)
   End If

End Sub

Sub Service_Destroy

End Sub
 
Upvote 0

freetoair

Member
Licensed User
Longtime User
Yes, I used AsyncStreams but never rises Astreams_newdata. When is connect to " astreams.Initialize (usb.GetInputStream, usb.GetOutputStream, "astreams")" everything is working normally. I was able to find documentation from the manufacturer (DWIN model: DMT80480T070_32WT) of the modules and their example is operating normally. But unfortunately example and API is written in Java so for me is not a lot of help.
 
Upvote 0

freetoair

Member
Licensed User
Longtime User
I want to connect to an audio processor that is controlled by the microcontroller which has a connection via the serial port, so do this Android machine looked ideal for it. But I guess I'll have to use a USB to COM adapter.
 
Upvote 0
Top