Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PortListener.cpp 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "PortListener.h"
  2. #include <QtDebug>
  3. PortListener::PortListener(const QString & portName)
  4. {
  5. qDebug() << "hi there";
  6. this->port = new QextSerialPort(portName, QextSerialPort::EventDriven);
  7. port->setBaudRate(BAUD9600);
  8. port->setFlowControl(FLOW_OFF);
  9. port->setParity(PAR_NONE);
  10. port->setDataBits(DATA_8);
  11. port->setStopBits(STOP_2);
  12. if (port->open(QIODevice::ReadWrite) == true) {
  13. connect(port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
  14. connect(port, SIGNAL(dsrChanged(bool)), this, SLOT(onDsrChanged(bool)));
  15. if (!(port->lineStatus() & LS_DSR))
  16. qDebug() << "warning: device is not turned on";
  17. qDebug() << "listening for data on" << port->portName();
  18. }
  19. else {
  20. qDebug() << "device failed to open:" << port->errorString();
  21. }
  22. }
  23. void PortListener::onReadyRead()
  24. {
  25. QByteArray bytes;
  26. int a = port->bytesAvailable();
  27. bytes.resize(a);
  28. port->read(bytes.data(), bytes.size());
  29. qDebug() << "bytes read:" << bytes.size();
  30. qDebug() << "bytes:" << bytes;
  31. }
  32. void PortListener::onDsrChanged(bool status)
  33. {
  34. if (status)
  35. qDebug() << "device was turned on";
  36. else
  37. qDebug() << "device was turned off";
  38. }