title: QT serial port not working
body: <p>I'm trying to write \ read from a serial device using a usb / rs 232 cable.
  I'm pretty sure that my code writes " #002s " (this is a control code) to the serial device, because </p>
  
  <p>a) the serial port is open</p>
  
  <p>b) the serial port is writable</p>
  
  <p>c) the code successfully navigates  "wait For Bytes Written (-1)"</p>
  
  <p>d) when using a serial port sniffer the data is successfully written.</p>
  
  <p>The issue I have is that I don't receive any data, and no data is being emitted from the other device. When using qt terminal writing the same "  #002s " produces the correct response.</p>
  
  <p>Any ideas?</p>
  
  <p>many thanks.</p>
  
  <pre><code>    #include "test_serial.h"
  #include "ui_test_serial.h"
  #include &lt;QtSerialPort/QtSerialPort&gt;
  #include &lt;QDebug&gt;
  
  QSerialPort *serial;
  Test_Serial::Test_Serial(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::Test_Serial)
  {
      ui-&gt;setupUi(this);
  
    serial = new QSerialPort(this);
    connect(serial,SIGNAL(readyRead()),this,SLOT(serialReceived()));
    serial-&gt;setPortName("COM1");
    serial-&gt;setBaudRate(QSerialPort::Baud9600);
    serial-&gt;setDataBits(QSerialPort::Data8);
    serial-&gt;setParity(QSerialPort::NoParity);
    serial-&gt;setStopBits(QSerialPort::OneStop);
    serial-&gt;setFlowControl(QSerialPort::NoFlowControl);
    serial-&gt;open(QIODevice::ReadWrite); 
  
    if (serial-&gt;isOpen() &amp;&amp; serial-&gt;isWritable())
   {
    QByteArray input;
  
    input = "#";
    serial-&gt;write(input);
    serial-&gt;waitForBytesWritten(-1);
    input = "0";
    serial-&gt;write(input);
    serial-&gt;waitForBytesWritten(-1);
    input = "0";
    serial-&gt;write(input);
    serial-&gt;waitForBytesWritten(-1);
    input = "2";
    serial-&gt;write(input);
    serial-&gt;waitForBytesWritten(-1);
    input = "s";
    serial-&gt;write(input);
    serial-&gt;waitForBytesWritten(-1);
    input = "\r";
    serial-&gt;write(input);
    serial-&gt;waitForBytesWritten(-1);
    serial-&gt;flush();
  
    serial-&gt;waitForReadyRead(100);
    QByteArray output = serial-&gt;readAll();
    ui-&gt;label_2-&gt;setText(output);
  
  }}
  
  
  Test_Serial::~Test_Serial()
  {
      delete ui;
      serial-&gt;close();
  }
  
  void Test_Serial::serialReceived()
  {
      QByteArray output;
      output = serial-&gt;readAll();
      ui-&gt;label-&gt;setText("output");
  }
  </code></pre>