Android Question USB to serial log string

jimseng

Member
Licensed User
Hello
In my B4R program I log various bits of information to send back to the host device. On my PC the messages are in one block. On my Android device they seem to come in chunks:
B4X:
ToastMessageShow( bc.StringFromBytes(Buffer,"UTF8"),False)
The string "hello" comes as two messages "hell" and o.
Why is this? Do I need to use stringbuilder in my Android app and explicitly put a CRLF in my log message for it to display correctly? Is there a better (i.e. correct) way of doing this?
Many thanks

Matt
 

Erel

Administrator
Staff member
Licensed User
The reason I've asked it, is that if you were using UsbSerial with AsyncStreams then you could have used AsyncStreamsText. This way you just need to add an end of line character in the Arduino side: astream.Write(Array As Byte(10)) and AsyncStreamsText will take care of correctly building the message.

felUsbSerial doesn't work with AsyncStreams. However you can take the code from AsyncStreamsText and modify it to work with felUsbSerial. It should be quite simple.

Try it and if it doesn't work for you then I can help you with this.
 

jimseng

Member
Licensed User
Thanks for the reply. I tried using UsbSerial (2.3 and 2.4) but it doesn't work with my device, but fellusbserial does. I prefer to work with asyncstrea,s as I am more used to it. I am not sure which way to go. The demo program gets as far as
B4X:
  If dev <> usb1.USB_NONE Then
and then logs
B4X:
Log("Error opening USB port 1")
.
I'll try and see what is going on because if FellUsbSerial works it should be possible.
 

jimseng

Member
Licensed User
The device_filter.xml files are identical in the res folders of both fellusbserial and usbserial demo. I am using an arduino with a device id of 0x042 and vendor ID of 0x2a03
I am assuming that my problem connecting using usbserial (2.4) is that the wrong driver is loading. Should I try editing the IDs in the xml file or should I use setcustomdevice? IF setcustomdevice can someone show me an example of how to do it.
Thanks
 

jimseng

Member
Licensed User
Hi Erel
Perhaps you could help me. I have gone back to fellusbserial as I just can't get usbserial to recognise my arduino. How do I go about modifying asyncstreamstext to work with fellusbserial
 

Erel

Administrator
Staff member
Licensed User
The modified module is attached.

Usage example:
B4X:
Sub Process_Globals
   Private fel As felUsbSerial
   Private felAST As felAsyncStreamsText
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     fel.Initialize("fel", ...)
     felAST.Initialize(Me, "felAST")
   End If
End Sub

Sub fel_DataAvailable (Buffer() As Byte)
   felAST.astreams_NewData(Buffer) '<------push the data to felAST
End Sub

Sub felAST_NewText (Text As String) '<--- will be raised when a new line character is found
   Log("Message received: " & Text) 
End Sub
 

Attachments

Top