B4R Question How to read or write a byte from serial?

welu1805

Active Member
Licensed User
Longtime User
Hi all,

In C I can look with serial.availabe if there are any bytes to read. With serial.read I can read one byte, with serial.write I can write one. Are there similar commands in B4R?

Thanx
Lutz
 

welu1805

Active Member
Licensed User
Longtime User
OK, that is what I want. In my special case I want to use an Arduino Mega, because it has 4 UARTs. Serial for Logs with 115000 and Serial2 for Midi with 31250.

How can I access Serial2 (or 3 and 4)?
 
Upvote 0

welu1805

Active Member
Licensed User
Longtime User
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial As Serial
Private SerialNative1 As Stream
End Sub

Private Sub AppStart
Serial.Initialize(115200)
Log("AppStart")

RunNative("SerialNative1", Null)
End Sub

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

I get this error:

B4R version: 1.80
Parsing code. Error
Error parsing program.
Error description: Unbalanced #End If
Occurred on line: 29 (Main)
 
Upvote 0

welu1805

Active Member
Licensed User
Longtime User
I found the error:

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