I want to respond to serial input events on a SAMD21 Pro RF board using the usual Arduino pattern of
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // flagwhether the string is complete
setup()
{
// initialize serial:
SerialUSB.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
...
}
loop()
{
if(stringComplete)
{
SerialUSB.println("Invalid command: " + inputString + ".");
}
// clear the string:
inputString = "";
stringComplete = false;
}
// serialEvent[x]() is normally anything from serialEvent() to serialEvent5() or at least 2 or 3, depending on the board.
void serialEvent[x]()
{
while(SerialUSB.available())
{
// get the new byte:
char inChar = (char)SerialUSB.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
if(inChar == '\n')
{
stringComplete = true;
}
}
}
I cannot find any documentation of a serialUSB version of serialEvent() anywhere. Or decent documentation of serialUSB in general.
I have tried to search all of the header files, grepped through all of the relevant directories. Does such a thing exist? Does serialUSB map to any of the defined hardware serial ports for SAMD chips (SERIAL0-SERIAL5)?
Or am I just barking up the wrong tree?