B4R Question SOLVED Additional serial ports write.

tigrot

Well-Known Member
Licensed User
Longtime User
Hi everybody
I don't understand what is my mistake.
I write to native serial port 1 on Arduino Mega 2560 by this code:

B4X:
strx=Array As Byte( "PE",13,10)
Main.Serialnative1.WriteBytes(strx,0,4)   
strx=Array As Byte("RD 0", 13,10)
Main.Serialnative1.WriteBytes(strx,0,6)
Main.Serialnative1.Flush

The result in hex code is
B4X:
00 0d 0a 46 00 0d 0a 00 0d 0a                    ...F......

It doesn't resemble to anything, apart CR/LF.
Probably the strings are not converted correctly in Array function?
Thank you for help
Regards
Mauro Zanin
 

tigrot

Well-Known Member
Licensed User
Longtime User
Solved I had to redefine temporary arrays of bytes to strings:

B4X:
Dim stringx As String=JoinStrings(Array  As String( "PE",CRLF))
Main.Serialnative1.WriteBytes(stringx,0,4)  
stringx=JoinStrings(Array As String("RD 0", CRLF))
Main.Serialnative1.WriteBytes(stringx,0,6)

This works!
 
Upvote 0
Top