1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question USB to serial log string

Discussion in 'Android Questions' started by jimseng, May 24, 2016.

  1. jimseng

    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:
    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Which library are you using to read the serial logs?
     
  3. jimseng

    jimseng Member Licensed User

    Hi I am using fellUsbSerial
     
  4. Erel

    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.
     
  5. jimseng

    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
    Code:
    If dev <> usb1.USB_NONE Then
    and then logs
    Code:
    Log("Error opening USB port 1")
    .
    I'll try and see what is going on because if FellUsbSerial works it should be possible.
     
  6. jimseng

    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
     
  7. jimseng

    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
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    The modified module is attached.

    Usage example:
    Code:
    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
     

    Attached Files:

  9. jimseng

    jimseng Member Licensed User

    Thanks Erel. Works perfectly. Just what I needed.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice