Android Question Serial Comm, AsyncStreams with B4A ...Chars and Numbers Problem Solved !!!! :-)

ttronic

Member
Licensed User
Longtime User
Hello,

use B4A --> to send commands to Attiny

how can i send textcommands like "r" or Data like "50" as ascii char ?
i tried some with byteconverter and StringtoHex.... but nothing is successfull...

Have anybody idea how i can send Textcommands ?...

Thousend Thanks
Heinz
 

OliverA

Expert
Licensed User
Longtime User
Hi @ttronic . I read your other post (https://www.b4x.com/android/forum/threads/serielle-Übertragung-von-zahlenwerten.126411/#post-790376), but I'm confused as to what exactly is sent to your microcontroller. You explained that when you typed 5, 0, (i'm guessing here) and enter, you would see the byte values 53, 48 and 13 transferred. Later you mention hex values 35 and 30. It could be as simple as this
B4X:
    Dim bc As ByteConverter            ' Only used to log hex version of bytes to be sent
    Dim sourceString As String = $"50${Chr(13)}"$
    Dim bytesToSent() As Byte = sourceString.GetBytes("UTF8")
    Log(bc.HexFromBytes(bytesToSent))
    
    Dim bytesReceived() As Byte = Array As Byte (53,48,13)
    Dim asString As String = BytesToString(bytesReceived, 0, bytesReceived.Length, "ASCII") ' ASCII received from microcontroller
    Log(asString)
    
    bytesReceived = Array As Byte (0x35, 0x30, 0x0D)
    asString = BytesToString(bytesReceived, 0, bytesReceived.Length, "ASCII") ' ASCII received from microcontroller
    Log(asString)
 
Upvote 0

ttronic

Member
Licensed User
Longtime User
Hello , this is the solution ......

Private Number = 50 As Double
Message = NumberFormat(Number, 1, 0).GetBytes("Ascii")
Msgbox("123 "& Message(0) & Message(1) , "info1")

CallSub2(Starter, "SendMessage", Array As Byte(Message(0),Message(1),13,10))
^ ^ ^ ^
5 0 cr lf

Vielen Dank...... Thank u
 

Attachments

  • Image 1.png
    Image 1.png
    87.2 KB · Views: 200
Upvote 0
Top