Problem reading Serial from PC

I am having a problem communicating with an Arduino Uno through the Serial port. I think I am missing some kind of configuration issue:)

The Arduino is programmed to receive commands from a Windows PC software program (which I did not write, and have no access to the code). It receives commands terminated with a '#' character.

When I use the Serial Monitor window to send the commands, everything works fine. Arduino receives the command, sends the correct response back. I also use a serial port sniffer to see the data going back and forth between the Arduino and the Serial monitor.

The problem: when I use the PC program to communicate with the Arduino, the strings from the PC are not received by the Arduino. The sniffer shows the correct command coming from the PC, for example :GH# with no cr/lf. But, the Arduino does not register the command. The Serial.available() (in the code below) never shows any data received.

The Arduino code looks like the following. The FlashLED function is debugging to let me know a command has been received. It flashes correctly when I use the Serial Monitor window to send commands, but not when the PC sends data.

void setup()
{
  Serial.begin(9600);
}

// called from the main loop
unsigned int readCommand(String *inCommand, int maxLength)
{
  *inCommand = "";
  
  if (Serial.available() > 0)
      {
      *inCommand = Serial.readStringUntil('#'); 
      FlashLED();
      }
  else
      {
      return (0);
      }
  
  return ((*inCommand).length());
}

The sniffer correctly shows the data from the PC, so the PC must be using the same 9600 baud, 1 stop bit, no parity configuration. I also set that configuration on the COM port in Device Manager, but it didn't help.

I don't know what to do next - how to get the Arduino to read the data.

brew: The Serial.available() (in the code below) never shows any data received.

Sounds like Arduino is talking on the right com port and the other one is not.

Well, the PC program is configured to use the same COM5 port, and the software sniffer program is looking at the same COM5. The sniffer shows a) the PC successfully opened COM5, and b) the data coming from the PC, but the Arduino never indicates Serial.available as having any data.

I finally figured it out, I think.

It turns out that the PC program opens the COM port with DTR enabled. It looks like when it sends the command string it turns on the DTR line; I see the RX LED flash. The PC program does not provide an option to turn this off:(

Unfortunately, the Arduino reacts to the DTR as a reset. It resets itself, in the process losing the string sent down. Thus, it never reads the string and doesn't know to respond.

I found this post http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection which describes adding a 10uF capacitor to the Uno which disables the reset operation. When I do this, the Uno works as expected. Hallelujah!

The capacitor also prevents the downloading of code and using the Serial Monitor, which requires a reset of the board. So, I have added a switch with the capacitor. In one position ("Load") the capacitor is disabled and I can download code, use the Serial Monitor, etc. In the other position ("Run") the capacitor is enabled and the PC correctly communicates to the Arduino.

brew: Unfortunately, the Arduino reacts to the DTR as a reset. It resets itself, in the process losing the string sent down. Thus, it never reads the string and doesn't know to respond.

I write my PC programs so they open the Serial port and keep it open until they are completely finished with the Arduino. That means the Arduino just resets once. I also get the Arduino to send a message from setup() - perhaps Serial.println("Arduino is ready"); and get the PC program to wait until it receives that message before it tries to send anything to the Arduino.

...R Serial Input Basics