B4R Question asyncstreamstext in B4R

bdunkleysmith

Active Member
Licensed User
Longtime User
Can I use asyncstreamstext in conjunction with serial in B4R?

If not, how do I handle Buffer in this sub:

B4X:
Sub astream_NewData (Buffer() As Byte)



End Sub

so I can separate out each piece of data ending with a newline in a similar method Erel suggested in this question https://www.b4x.com/android/forum/threads/usbserial-with-freetronics-leostick.86967/ by way of this reference felUsbSerial - AsyncStreamsText: https://www.b4x.com/android/forum/threads/usb-to-serial-log-string.67231/#post-425804?
 

bdunkleysmith

Active Member
Licensed User
Longtime User
Thanks for the reference Erel.

This would not work in all situations, but as my data is relatively small and of known fixed lengths, this is the simple solution which works for my application:

B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private usocket As WiFiUDP
    Private wifi As ESP8266WiFi
    Private astream As AsyncStreams
    Private bc As ByteConverter
End Sub

Sub astream_NewData (Buffer() As Byte)
    usocket.BeginPacket(ip, port)
    For Each s() As Byte In bc.Split(Buffer, CRLF)
        If s.Length <> 0 Then
            usocket.Write(s)
            usocket.SendPacket
        End If
    Next
End Sub

So you can see as per the suggestion/recommendation in this thread https://www.b4x.com/android/forum/threads/esp8266-wifi-shield-on-uno.86862/, I'm successfully coding the ESP8266 and the UNO separately, with the ESP8266 sending the data collected by the UNO via UDP over WiFi.

Thanks again for your great support.
 
Upvote 0
Top