inside MainWindow:
Qt Code:
  1. plcTimer = new PlcTimer();
  2. connect(plcTimer, SIGNAL(jack_sendToRS(char*,int)), rs_plc, SLOT(rs_plcDataAqustn(char*,int)));
  3. plcTimer->start();
  4. rs_plc->rs_plcOpenPort((char *)"/dev/ttyS0"); /*/dev/ttyS3*/
To copy to clipboard, switch view to plain text mode 

QThread signal or QTimer signal connects to serial SLOT which write n reads packet to and from serial port:
Qt Code:
  1. bool RS::rs_plcDataAqustn(char* data, int len)
  2. {
  3. QByteArray rd15Bytes;
  4.  
  5. // QByteArray built((char*)data, 6) ;
  6. // qDebug() << built.toHex();
  7.  
  8.  
  9. if(!rs_serialWrite(data, len))
  10. {
  11. qDebug() << "Failure:( rs_dataqustn: rs_plcWrite(data, len)";
  12. emit plc_port_dscntd();
  13. return false;
  14. }
  15.  
  16. if(len == 3)
  17. {
  18. qDebug() << "len = 3";
  19.  
  20. rs_delay();
  21.  
  22. if(rs_plcRead(&rd15Bytes))
  23. {
  24. qDebug() << rd15Bytes.length();
  25. //qDebug() << "->" << rd15Bytes.toHex();
  26.  
  27. if(rd15Bytes.isEmpty())
  28. {
  29. emit logMessage("Failure:( rs_dataAqustn, if(rd15Bytes.isEmpty())");
  30. }
  31. else
  32. {
  33. if(!rs_plcCheckChecksum(&rd15Bytes))
  34. emit logMessage("Failure:( rs_dataAqustn, if(!rs_plcCheckChecksum(&rd15Bytes))");
  35. else
  36. {
  37. emit rs_plcSendRdPacket(rd15Bytes);
  38.  
  39. if(!rs_serialWrite((char* )"0x06", 1))
  40. {
  41. qDebug() << "Failure:( rs_dataqustn: rs_plcWrite(PLC_ACK, 1)";
  42. }
  43. }
  44. }
  45. }
  46. else
  47. {
  48. emit plc_hmiBoard_dscntd();
  49. }
  50. }
  51.  
  52. return true;
  53. }
To copy to clipboard, switch view to plain text mode 


Read from Plc:
Qt Code:
  1. bool RS::rs_plcRead(QByteArray *data)
  2. {
  3. unsigned char buff[128];
  4. int len, tries;
  5.  
  6. tries = 0;
  7.  
  8. while(tries < 13)
  9. {
  10. len = read(fd, buff, PLC_READ_BYTE);
  11.  
  12. if((buff[0] == PLC_HEADER) && (len == PLC_READ_BYTE))
  13. {
  14. data->append((char *)buff, PLC_READ_BYTE);
  15. //qDebug() << data->toHex();
  16. return true;
  17. }
  18. else
  19. {
  20. tries++;
  21. qDebug() << "retry";
  22. }
  23. }
  24.  
  25. return false;
  26. }
To copy to clipboard, switch view to plain text mode 

should you need more info, please note it.