Commit 501add36 authored by Evan Raskob's avatar Evan Raskob

try/catch for serial loop

parent 02654fb5
......@@ -71,23 +71,25 @@ void serialAvailable(Serial serial) {
try {
String serialIn = serial.readString();
if (serialIn != null)
{
String serialLines[] = split(serialIn, stopChar); // we might have received a few lines of serial so we
// split them by the stop character (newline)
String serialLines[] = split(serialIn, stopChar); // we might have received a few lines of serial so we
// split them by the stop character (newline)
// for each line, parse it for commands
for (String line : serialLines) {
// for each line, parse it for commands
for (String line : serialLines) {
String input = trim( line ); // trim away space characters and extra newlines etc.
String input = trim( line ); // trim away space characters and extra newlines etc.
// ex: splits a serial line of "a 324\n" to ["a", "324"]
String[] msgs = split(input, ",");
// ex: splits a serial line of "a 324\n" to ["a", "324"]
String[] msgs = split(input, ",");
// check that we've got valid data
if (msgs.length > 0 && msgs[0] != "-") {
synchronized(commandsReceived)
{
commandsReceived.add(msgs);
// check that we've got valid data
if (msgs.length > 0 && msgs[0] != "-") {
synchronized(commandsReceived)
{
commandsReceived.add(msgs);
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment