OK, thank you for the help. Here's a minimum set of code to reproduce the problem.
There's really not that much here, so there must be something else going on, unless I'm missing something painfully obvious.
I still think the most valuable clue to the problem is the fact that I can restart the computer (without removing power or disconnecting the USB cable) to recover. Some other points that might be relevant that I forgot to mention earlier.
- USB connection is going through a USB 3.0 Hub to a USB 3.0 port (the only USB port on the Microsoft Surface Pro 2)
- There are two (custom) shields being include, 1 does 5V - 5A power regulation for the other hardware, the other is an LED driver.
// PIN CONTANSTS
#define LED1Pin 3
char const verInfo[] = "NGA-LED-INT:1";
// pins for the LEDs:
const int led1 = LED1Pin;
char inputString[16] = {'\0'}; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
int inputStringLen = 0; //char of input String
int machineState = 0;
int ledAmp;
int led1Amp = 0;
void setup() {
// initialize serial:
Serial.begin(9600);
strcpy(inputString,'\0');
inputStringLen = 0;
ledAmp = 255;
analogWrite(led1, 0);
pinMode(led1, OUTPUT);
}
void loop() {
serialEvent222();
if (stringComplete) {
doSomething();
// clear the string:
strcpy(inputString,'\0');
inputStringLen = 0;
stringComplete = false;
}
}
void doSomething() {
int Error = 0; //set to 0, and set if appropriate function is NOT found
// should respond with ":" ... to indicate OK, otherwise...
if (strcmp(inputString,"L1") == 0) { // LED 1
led1Amp = 255;
analogWrite(led1, led1Amp);
Serial.print(F(":"));
Serial.println(led1Amp);
} else if (strcmp(inputString,"O") == 0) { // TURN OFF LEDS
int tmpAmp = 0;
led1Amp = tmpAmp;
analogWrite(led1, led1Amp);
Serial.print(F(":"));
Serial.println(tmpAmp);
} else if (strcmp(inputString,"S") == 0) { // STATUS OF MACHINE, count to one after first check
Serial.print(F(":"));
Serial.println(machineState);
machineState = machineState + 1;
} else if (strcmp(inputString,"VER") == 0) { // Respond to same Ver command as MMC-100
Serial.print(F(":"));
Serial.println(verInfo);
} else {
Error = 1;
}
if (Error > 0) {
Serial.println("!Invalid");
}
Serial.flush();
}
void serialEvent222() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
if (inChar == '\n') {
} else if (inChar == '\r') {
stringComplete = true;
} else {
// add it to the inputString:
inputString[inputStringLen] = inChar;
inputStringLen = inputStringLen + 1;
inputString[inputStringLen] = '\0';
}
}
}