Ajout de plein d'affaires.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
|
||||
#include "PortListener.h"
|
||||
#include <QtDebug>
|
||||
|
||||
PortListener::PortListener(const QString &portName)
|
||||
{
|
||||
qDebug() << "hi there";
|
||||
this->port = new QextSerialPort(portName, QextSerialPort::EventDriven);
|
||||
port->setBaudRate(BAUD38400);
|
||||
port->setFlowControl(FLOW_OFF);
|
||||
port->setParity(PAR_NONE);
|
||||
port->setDataBits(DATA_8);
|
||||
port->setStopBits(STOP_1);
|
||||
|
||||
if (port->open(QIODevice::ReadWrite) == true) {
|
||||
connect(port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
||||
connect(port, SIGNAL(dsrChanged(bool)), this, SLOT(onDsrChanged(bool)));
|
||||
if (!(port->lineStatus() & LS_DSR))
|
||||
qDebug() << "warning: device is not turned on";
|
||||
qDebug() << "listening for data on" << port->portName();
|
||||
}
|
||||
else {
|
||||
qDebug() << "device failed to open:" << port->errorString();
|
||||
}
|
||||
}
|
||||
|
||||
void PortListener::onReadyRead()
|
||||
{
|
||||
QByteArray bytes;
|
||||
int a = port->bytesAvailable();
|
||||
bytes.resize(a);
|
||||
port->read(bytes.data(), bytes.size());
|
||||
qDebug() << "bytes read:" << bytes.size();
|
||||
qDebug() << "bytes:" << bytes;
|
||||
}
|
||||
|
||||
void PortListener::onDsrChanged(bool status)
|
||||
{
|
||||
if (status)
|
||||
qDebug() << "device was turned on";
|
||||
else
|
||||
qDebug() << "device was turned off";
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
|
||||
#ifndef PORTLISTENER_H_
|
||||
#define PORTLISTENER_H_
|
||||
|
||||
#include <QObject>
|
||||
#include "qextserialport.h"
|
||||
|
||||
class PortListener : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PortListener(const QString &portName);
|
||||
|
||||
private:
|
||||
QextSerialPort *port;
|
||||
|
||||
private slots:
|
||||
void onReadyRead();
|
||||
void onDsrChanged(bool status);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /*PORTLISTENER_H_*/
|
||||
@@ -0,0 +1,7 @@
|
||||
TEMPLATE = app
|
||||
DEPENDPATH += .
|
||||
CONFIG += console
|
||||
include(../../src/qextserialport.pri)
|
||||
|
||||
SOURCES += main.cpp PortListener.cpp
|
||||
HEADERS += PortListener.h
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main file.
|
||||
* @author Michal Policht
|
||||
*/
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include "PortListener.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QString portName = QLatin1String("/dev/ttyS0"); // update this to use your port of choice
|
||||
PortListener listener(portName); // signals get hooked up internally
|
||||
|
||||
// start the event loop and wait for signals
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user