B4R Question Sending text via hardware serial port

Tim Chapman

Active Member
Licensed User
Longtime User
I am trying to send text via Hardware Serial port and getting nothing. Am I doing this wrong?
Serial Text:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
    
    'TXD1/RXD1 Serial for RYLR998
    Private SerialNative1 As Stream 'https://www.b4x.com/android/forum/threads/additional-hardware-serial-ports.67150/
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    
    'Serial for RYLR998 connected to Hardware Serial Port 1.
    RunNative("SerialNative1", Null)
    Delay(2000)
    
    Dim Buffer() As Byte = "AT+SEND=1,5,HELLO"
    
    'AT+SEND=0,5,HELLO
    Log("AppStart")
    Log("Burrer = ",Buffer)
    
    SerialNative1.WriteBytes(Buffer,0,Buffer.Length)
        
End Sub

#if C
void SerialNative1(B4R::Object* unused) {
 ::Serial1.begin(115200); //<--You can change the baud rate
 b4r_main::_serialnative1->wrappedStream = &::Serial1;
}
#end if

Thank you all in advance for the help!
 
Solution
The delay call is not needed.
You are missing the end of line characters.
B4X:
Private eol() As Byte = Array As Byte(13, 10)

B4X:
SerialNative1.WriteBytes(Buffer,0,Buffer.Length)
SerialNative1.WriteBytes(eol, 0, eol.Length)

Tim Chapman

Active Member
Licensed User
Longtime User
The delay call is not needed.
You are missing the end of line characters.
B4X:
Private eol() As Byte = Array As Byte(13, 10)

B4X:
SerialNative1.WriteBytes(Buffer,0,Buffer.Length)
SerialNative1.WriteBytes(eol, 0, eol.Length)
Hi Erel.
That fixed the problem. Thank you!
For my education, can you tell me how you figured that out?
 
Upvote 0

emexes

Expert
Licensed User
AT command terminator is actually just the one Return (Enter) key byte:

B4X:
Private eol() As Byte = Array As Byte(13)

although any half-decent AT-command-set implementation should be robust enough to ignore the superfluous linefeed.
 
Upvote 0
Top