Android Question log about sending characters into usb buffer

fgh3966

Active Member
Licensed User
Hello

Is it possible to have a log of the characters sent in the usb buffer by "msg" buffer ?

how to log about (msg):
Sub Bbegin_Click
    If usbserial.IsInitialized Then
        Dim s As String = "begin" & Chr(1)
        Dim msg() As Byte = s.GetBytes("UTF8")
        usbserial.Write(msg)

        Log(s)
        'Log(msg) are not possible
    End If
    
End Sub


Thank in advance.
 

fgh3966

Active Member
Licensed User
Hello everybody ?

In this message i find how to log about " msg" usb send to ftdi hardware.
Log("New data: " & bc.HexFromBytes(Buffer))
Don't forget library "bc As ByteConverter"

Also debug mode fine ?

My problem how to log to USB are solved.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i'm not sure what you think you're going to get. chr(1) is a non printing character, so printing it to the log is meaningless.
print msg() to the log isn't going to tell you something you don't already know, ie, "begin" + chr(1).
if what you mean is you want to see "begin" + chr(1) as numeric byte values or a hex values, then you can use the 2 routines below.
as you will see, when you simply print out "begin" + chr(1) as character values, chr(1) does not print. if your original string consisted of other control characters, then printing it out would show a number of missing characters.


B4X:
    Dim s As String = "begin" & Chr(1)
    Dim msg() As Byte = s.GetBytes("UTF8")
    Dim sb As StringBuilder
    sb.Initialize
    For Each b As Byte In msg
        sb.Append(b).Append(" ")
    Next
    sb.Append(CRLF)

    For Each b As Byte In msg
        sb.append("0x").Append(Bit.ToHexString(b.As(Int))).Append(" ")
    Next
    sb.Append(CRLF)

    For Each b As Byte In msg
        sb.Append(Chr(b)).Append(" ")
    Next
    
    Log(sb.ToString)
 
Upvote 0

fgh3966

Active Member
Licensed User
Hello and thank you for your help.
Your message are good and help me ;)
Indeed chr(1) is useless, thank you.
Otherwise I am trying to understand how to send a character string with the usbserial library.

Now my code are :
new code:
Sub Bbegin_Click
    If usbserial.IsInitialized Then
        Dim s As String = "begin"
        Dim msg() As Byte = s.GetBytes("ascii")
        usbserial.Write(msg)        
        Log("New data: " & bc.HexFromBytes(msg))
    End If
End Sub
 
Upvote 0
Top