I am working on an Arduino project for a digital multimeter interface. When the user connects to the interface via the USB virtual serial port, a version string is displayed. This is done with Serial.println(F(""verstr"); in the setup() section.
The problem was that I kept getting the string displayed in the terminal vertically one character per line prior to it finally being displayed on one complete line. Sometimes I got random characters displayed prior to the version string as well. I seemed to have solved this by placing a Serial.flush() just before the Serial.println() statement to "clear" the serial transmit buffer. This works for most part, but there is a caveat.
When you connect to the serial port, a reset signal is generated and the interface resets, firing up the bootloader. This causes a delay, which, in turn, causes problems with auto-detection with third party programs. It is possible to prevent the interface from being reset by placing a capacitor between the RESET and GND pins. This solves the auto-detection problems nicely. However, since setup() is no longer being run on reset, I can connect but I don't get the version string displayed and sometimes random characters are still displayed on connection. I figured if there is a way to detect the event of a connection being opened from the terminal on the PC, then I could use this to do a Serial.flush() and display the version string, but I can't find such a function. The nearest I found is serialEvent() although this seems to be intended to capture incoming data.
With the bootloader disabled, is it possible to detect on the Arduino when a serial connection is opened from the host PC?