Hi, I am trying to send 1/0 to my ARDUINO Board & trying to receive some data from board as a response , I am using QextSerialPort for this But I am not able to write any data to the board & not able to receive any data also.

http://docs.qextserialport.googlecode.com/git/1.2/qextserialport.html

qDebug() << "send.size() : " << send.size() << " data = " << send.data() <<" Written = " << port->write(send, send.size());
This printing : send.size() : 1 data = 1 Written = 0 //Means I am writing 0 bytes every time

Is there a problem in my code ??


Qt Code:
  1. void MainWindow::ledOnOff(bool on)
  2. {
  3. if(port == 0)
  4. {
  5. port = new QextSerialPort("COM6", QextSerialPort::EventDriven); //QextSerialPort* port is class member
  6. port->setBaudRate(BAUD9600);
  7. port->setFlowControl(FLOW_OFF);
  8. port->setParity(PAR_NONE);
  9. port->setDataBits(DATA_8);
  10. port->setStopBits(STOP_2);
  11.  
  12. connect(port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
  13.  
  14. if(port->open(QIODevice::ReadWrite) == true)
  15. {
  16. qDebug() << "Port open success";
  17. }
  18. else
  19. {
  20. qDebug() << "Port open success";
  21. }
  22. }
  23. else
  24. {
  25. port->close();
  26. }
  27.  
  28. quint8 writeByte = 0;
  29.  
  30. if(on)
  31. {
  32. writeByte = 1;
  33. }
  34.  
  35. if(port->isOpen() || port->open(QIODevice::ReadWrite) == true)
  36. {
  37. QByteArray send;
  38. send.resize(writeByte );
  39. send = QByteArray::number(writeByte);
  40.  
  41. port->flush();
  42. qDebug() << "send.size() : " << send.size() << " data = " << send.data()
  43. <<" Writtend = " << port->write(send, send.size());
  44. }
  45. else
  46. {
  47. qDebug() << "device failed to open:" << port->errorString();
  48. }
  49. }
  50.  
  51.  
  52. void MainWindow::onReadyRead()
  53. {
  54. QByteArray bytes;
  55. quint8 a = port->bytesAvailable();
  56. bytes.resize(a);
  57. port->read(bytes.data(), bytes.size());
  58.  
  59. qDebug() << bytes.constData();
  60. }
To copy to clipboard, switch view to plain text mode 


Thanks In Advance.