OptimusPrime

Hi Community!I just tried to modify the example "SerialEvent" in "Communication" to work with the due's native usb port. Everything seems to work out fine, but the SerialEvent is never beeing called. I read through the reference and stumbled upon some threads e.g. http://forum.arduino.cc/index.php?PHPSESSID=9n0ue2d191td03larfose2vfb0&topic=135011.0 but i didn't find a solution yet to catch this event.Anyone struggeling with similar issues? Is there another event for the native port (SerialUSBEvent)?

/* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs, so using delay inside loop can delay response. Multiple bytes of data may be available. */void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.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; } }}

/* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs, so using delay inside loop can delay response. Multiple bytes of data may be available. */

////////////////////no magic herevoid serialEvent() { 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; } }}

You will notice that there are 4 serial event handler functions defined. You'll also notice that SerialUSB is not one of them. To the best of my knowledge there is no serialEvent type function for the SerialUSB (native port) on the Due. You need to do this yourself. This isn't as big of a problem as you might expect. That function I showed above? It is called every time your loop function is called. So, really, it is just a convenience. Put these lines in your loop function: