user43025: What are the differences in serial communication between PC <---> Arduino UNO (ATMEGA328p) and PC <---> Arduino Leonardo (ATMEGA32u4)?  
I am asking because of a problem related to using these two Arduino boards for data logging in the following way:

PC sends a specific char string to Arduino, via serial port, to initialize datalogging
Arduino measures data, let's say a fixed number of ADC readings
Arduino stops measuring, sends data back to the PC over serial port
Arduino waits until new serial data are received before logging new data 

If I send/receive data via the Arduino IDE serial monitor, this procedure works on both boards.  However, I want a separate GUI program (Qt) to handle the serial communication, where one clicks a button to send the data in step 1, and plot the data from step 3 on a graph.   
I wrote a simple Qt GUI where a button is clicked, and the measured data are printed to the GUI screen.  Observations while testing it:

Arduino UNO as datalogger: Arduino is plugged into USB socket of PC, then I launch the GUI, then click button to start data acquisition.  The data are shown.  Program appears to work fine. 
Arduino Leonardo as datalogger: Arduino is plugged into USB socket of PC, then I launch the GUI, then click button to start data acquisition.  The data are not received, program hangs.  

Then

Arduino Leonardo as datalogger: Arduino is plugged into USB socket of PC, Open Arduino IDE serial monitor, send command to acquire data.  Then close Arduino IDE serial monitor, launch the GUI, click button to start data acquisition.  The GUI program now works.

Long story, but basically there appears to be a difference when using the two Arduino boards with external programs to do serial communication.  Can someone outline the differences and why Leonardo needs the "jump start" I described above using Arduino serial monitor?  Ultimately I want to fix the problem and avoid that hack.
Reluctant to post Qt code on Arduino stack exchange, but here is how I start the serial port:

ui->setupUi(this);
microcontroller_is_available = false;
microcontroller_port_name = "false";
microcontroller = new QSerialPort(this);
qDebug() << "Number of available ports: " << QSerialPortInfo::availablePorts().length();
foreach (const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()) {
    qDebug() << "Has product ID " << serialPortInfo.hasProductIdentifier();
    if(serialPortInfo.hasProductIdentifier()){qDebug() << "Product ID: " << serialPortInfo.productIdentifier();}
    qDebug() << "Has vendor ID " << serialPortInfo.hasVendorIdentifier();
    if(serialPortInfo.hasVendorIdentifier()){qDebug() << "Vendor ID: " << serialPortInfo.vendorIdentifier();}
}

foreach (const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()) {
   if(serialPortInfo.hasVendorIdentifier() && serialPortInfo.hasProductIdentifier()){
       if(serialPortInfo.vendorIdentifier() == micro_vendor_id){
           if(serialPortInfo.productIdentifier() == micro_product_id){
              microcontroller_port_name = serialPortInfo.portName();
              microcontroller_is_available = true;
           }
       }
   }
}

if(microcontroller_is_available){  // open and configure serialport
    microcontroller->setPortName(microcontroller_port_name);
    microcontroller->open(QSerialPort::ReadWrite);
    microcontroller->setBaudRate(QSerialPort::Baud115200);
    microcontroller->setDataBits(QSerialPort::Data8);
    microcontroller->setParity(QSerialPort::NoParity);
    microcontroller->setStopBits(QSerialPort::OneStop);
    microcontroller->setFlowControl(QSerialPort::NoFlowControl);
}
else{QMessageBox::warning(this, "Port error", "Cannot connect DAQ.");}

Setup part of my Arduino code:
void setup(){
  DDRB  |= B11111111;  // (654210 outputs, miso input)     
  PORTB &= ~_BV(RF_AMPL);
  DDRD  |= B1100010; 
  PORTD |= (_BV(SRAM_HOLD) | _BV(SRAM_SS1)); 
  ADCSRA=0;
  SPCR = B01010000;           // SPI init (could get away with 11010000 on 328p but not 32u4)
  SPSR = B00000001;
  PORTD &= ~_BV(SRAM_SS1);     // Slave init
  SPDR=WRMR;  while(!(SPSR & (1<<SPIF)));
  SPDR=SEQUENTIAL_MODE; while(!(SPSR & (1<<SPIF)));
  PORTD |= _BV(SRAM_SS1); 
  __builtin_avr_delay_cycles(160);
  PORTD &= ~_BV(SRAM_SS1); 
  SPDR=RDMR; while(!(SPSR & (1<<SPIF)));
  SPDR=0x00; while(!(SPSR & (1<<SPIF)));
  PORTD |= (_BV(SRAM_HOLD) | _BV(SRAM_SS1)); 
  state1=0;
  count=0;
  pulse_count=0;
  serial_counter=0;
  Serial.begin(115200);  while(!Serial){}
}


user43025: I solved this by resetting the Arduino (open serial port at 1200 baud, then close serial port) when launching the Qt program.
Here is the relevant part of the Qt program:
        microcontroller->setPortName(microcontroller_port_name);
        microcontroller->open(QSerialPort::ReadWrite);
        microcontroller->setBaudRate(QSerialPort::Baud1200);
        microcontroller->setDataBits(QSerialPort::Data8);
        microcontroller->setParity(QSerialPort::NoParity);
        microcontroller->setStopBits(QSerialPort::OneStop);
        microcontroller->setFlowControl(QSerialPort::HardwareControl);

        qDebug() << "open 1200 baud";
        Sleep(10);
        microcontroller->close();
        Sleep(10);

        microcontroller->open(QSerialPort::ReadWrite);
        microcontroller->setBaudRate(QSerialPort::Baud115200);
        microcontroller->setDataBits(QSerialPort::Data8);
        microcontroller->setParity(QSerialPort::NoParity);
        microcontroller->setStopBits(QSerialPort::OneStop);
        microcontroller->setFlowControl(QSerialPort::HardwareControl);

Now whenever I launch the Qt program, the Arduino is ready to accept serial data.

43025: <p>What are the differences in serial communication between PC &lt;---> Arduino UNO (ATMEGA328p) and PC &lt;---> Arduino Leonardo (ATMEGA32u4)?  </p>

<p>I am asking because of a problem related to using these two Arduino boards for data logging in the following way:</p>

<ol>
<li>PC sends a specific char string to Arduino, via serial port, to initialize datalogging</li>
<li>Arduino measures data, let's say a fixed number of ADC readings</li>
<li>Arduino stops measuring, sends data back to the PC over serial port</li>
<li>Arduino waits until new serial data are received before logging new data </li>
</ol>

<p>If I send/receive data via the Arduino IDE serial monitor, this procedure works on both boards.  However, I want a separate GUI program (Qt) to handle the serial communication, where one clicks a button to send the data in step 1, and plot the data from step 3 on a graph.   </p>

<p>I wrote a simple Qt GUI where a button is clicked, and the measured data are printed to the GUI screen.  Observations while testing it:</p>

<ul>
<li><strong>Arduino UNO as datalogger</strong>: Arduino is plugged into USB socket of PC, then I launch the GUI, then click button to start data acquisition.  The data are shown.  Program appears to work fine. </li>
<li><strong>Arduino Leonardo as datalogger</strong>: Arduino is plugged into USB socket of PC, then I launch the GUI, then click button to start data acquisition.  The data are not received, program hangs.  </li>
</ul>

<p>Then</p>

<ul>
<li><strong>Arduino Leonardo as datalogger</strong>: Arduino is plugged into USB socket of PC, <strong>Open Arduino IDE serial monitor, send command to acquire data</strong>.  Then close Arduino IDE serial monitor, launch the GUI, click button to start data acquisition.  The GUI program now works.</li>
</ul>

<p>Long story, but basically there appears to be a difference when using the two Arduino boards with external programs to do serial communication.  Can someone outline the differences and why Leonardo needs the "jump start" I described above using Arduino serial monitor?  Ultimately I want to fix the problem and avoid that hack.</p>

<p>Reluctant to post Qt code on Arduino stack exchange, but here is how I start the serial port:
</p>

<pre class="lang-cpp prettyprint-override"><code>ui-&gt;setupUi(this);
microcontroller_is_available = false;
microcontroller_port_name = "false";
microcontroller = new QSerialPort(this);
qDebug() &lt;&lt; "Number of available ports: " &lt;&lt; QSerialPortInfo::availablePorts().length();
foreach (const QSerialPortInfo &amp;serialPortInfo, QSerialPortInfo::availablePorts()) {
    qDebug() &lt;&lt; "Has product ID " &lt;&lt; serialPortInfo.hasProductIdentifier();
    if(serialPortInfo.hasProductIdentifier()){qDebug() &lt;&lt; "Product ID: " &lt;&lt; serialPortInfo.productIdentifier();}
    qDebug() &lt;&lt; "Has vendor ID " &lt;&lt; serialPortInfo.hasVendorIdentifier();
    if(serialPortInfo.hasVendorIdentifier()){qDebug() &lt;&lt; "Vendor ID: " &lt;&lt; serialPortInfo.vendorIdentifier();}
}

foreach (const QSerialPortInfo &amp;serialPortInfo, QSerialPortInfo::availablePorts()) {
   if(serialPortInfo.hasVendorIdentifier() &amp;&amp; serialPortInfo.hasProductIdentifier()){
       if(serialPortInfo.vendorIdentifier() == micro_vendor_id){
           if(serialPortInfo.productIdentifier() == micro_product_id){
              microcontroller_port_name = serialPortInfo.portName();
              microcontroller_is_available = true;
           }
       }
   }
}

if(microcontroller_is_available){  // open and configure serialport
    microcontroller-&gt;setPortName(microcontroller_port_name);
    microcontroller-&gt;open(QSerialPort::ReadWrite);
    microcontroller-&gt;setBaudRate(QSerialPort::Baud115200);
    microcontroller-&gt;setDataBits(QSerialPort::Data8);
    microcontroller-&gt;setParity(QSerialPort::NoParity);
    microcontroller-&gt;setStopBits(QSerialPort::OneStop);
    microcontroller-&gt;setFlowControl(QSerialPort::NoFlowControl);
}
else{QMessageBox::warning(this, "Port error", "Cannot connect DAQ.");}
</code></pre>

<p>Setup part of my Arduino code:</p>

<pre class="lang-cpp prettyprint-override"><code>void setup(){
  DDRB  |= B11111111;  // (654210 outputs, miso input)     
  PORTB &amp;= ~_BV(RF_AMPL);
  DDRD  |= B1100010; 
  PORTD |= (_BV(SRAM_HOLD) | _BV(SRAM_SS1)); 
  ADCSRA=0;
  SPCR = B01010000;           // SPI init (could get away with 11010000 on 328p but not 32u4)
  SPSR = B00000001;
  PORTD &amp;= ~_BV(SRAM_SS1);     // Slave init
  SPDR=WRMR;  while(!(SPSR &amp; (1&lt;&lt;SPIF)));
  SPDR=SEQUENTIAL_MODE; while(!(SPSR &amp; (1&lt;&lt;SPIF)));
  PORTD |= _BV(SRAM_SS1); 
  __builtin_avr_delay_cycles(160);
  PORTD &amp;= ~_BV(SRAM_SS1); 
  SPDR=RDMR; while(!(SPSR &amp; (1&lt;&lt;SPIF)));
  SPDR=0x00; while(!(SPSR &amp; (1&lt;&lt;SPIF)));
  PORTD |= (_BV(SRAM_HOLD) | _BV(SRAM_SS1)); 
  state1=0;
  count=0;
  pulse_count=0;
  serial_counter=0;
  Serial.begin(115200);  while(!Serial){}
}
</code></pre>
 43025: <p>I solved this by resetting the Arduino (open serial port at 1200 baud, then close serial port) when launching the Qt program.</p>

<p>Here is the relevant part of the Qt program:</p>

<pre><code>        microcontroller-&gt;setPortName(microcontroller_port_name);
        microcontroller-&gt;open(QSerialPort::ReadWrite);
        microcontroller-&gt;setBaudRate(QSerialPort::Baud1200);
        microcontroller-&gt;setDataBits(QSerialPort::Data8);
        microcontroller-&gt;setParity(QSerialPort::NoParity);
        microcontroller-&gt;setStopBits(QSerialPort::OneStop);
        microcontroller-&gt;setFlowControl(QSerialPort::HardwareControl);

        qDebug() &lt;&lt; "open 1200 baud";
        Sleep(10);
        microcontroller-&gt;close();
        Sleep(10);

        microcontroller-&gt;open(QSerialPort::ReadWrite);
        microcontroller-&gt;setBaudRate(QSerialPort::Baud115200);
        microcontroller-&gt;setDataBits(QSerialPort::Data8);
        microcontroller-&gt;setParity(QSerialPort::NoParity);
        microcontroller-&gt;setStopBits(QSerialPort::OneStop);
        microcontroller-&gt;setFlowControl(QSerialPort::HardwareControl);
</code></pre>

<p>Now whenever I launch the Qt program, the Arduino is ready to accept serial data.</p>
