Hello,

I'm trying to send data packets of 11 bytes using QSerialPort. It starts working fine, but it doesn't transmit all the bytes over, only sends about 8.
Not sure why it's behaving like this, any insight will be helpfull.

Qt Code:
  1. #include <QCoreApplication>
  2. #include <QTextStream>
  3. #include <QSerialPort>
  4. #include <QDebug>
  5. #include <QFile>
  6. #include <QTimer>
  7. #include <QtSerialPort/QSerialPortInfo>
  8. #include <QStringList>
  9.  
  10. QSerialPort serial;
  11.  
  12. int sendCmd(const QByteArray &myCmd);
  13.  
  14. int main(int argc, char *argv[])
  15. {
  16. QCoreApplication a(argc, argv);
  17.  
  18. serial.setPortName("COM7");
  19. serial.setBaudRate(QSerialPort::Baud9600);
  20. serial.setDataBits(QSerialPort::Data8);
  21. serial.setParity(QSerialPort::NoParity);
  22. serial.setStopBits(QSerialPort::OneStop);
  23. serial.setFlowControl(QSerialPort::NoFlowControl);
  24.  
  25. if (serial.open(QIODevice::ReadWrite))
  26. {
  27.  
  28. qDebug() << "Connected";
  29. }
  30. else
  31. {
  32. qDebug() << "Error";
  33.  
  34. }
  35.  
  36. QByteArray testOuts;
  37.  
  38. testOuts[0] = '$';
  39. testOuts[1] = 'D';
  40. testOuts[2] = 'W';
  41. testOuts[3] = '!';
  42. testOuts[4] = 'S';
  43. testOuts[5] = 'H';
  44. testOuts[6] = 'P';
  45. testOuts[7] = 'X';
  46. testOuts[8] = 'X';
  47. testOuts[9] = 'O';
  48. testOuts[10] = '#';
  49.  
  50. serial.write (testOuts);
  51. serial.flush();
  52. serial.waitForBytesWritten(1000);
  53.  
  54. //return a.exec();
  55. //serial.close();
  56. }
To copy to clipboard, switch view to plain text mode