1 #include <QtCore/QCoreApplication>
7 #include <qextserialport.h>
11 class pollSerialPort
: public QThread
{
13 pollSerialPort(QString dn
, QString fn
) : device(dn
), outFile(fn
)
19 // const char framingRaw[16] = {7,9,3,15,193,130,150,10,7,9,3,15,193,130,150,10};
20 const char framingRaw
[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
21 QByteArray
framing(framingRaw
, 16);
23 PortSettings Settings
;
25 Settings
.BaudRate
= BAUD115200
;
26 Settings
.DataBits
= DATA_8
;
27 Settings
.Parity
= PAR_NONE
;
28 Settings
.StopBits
= STOP_1
;
29 Settings
.FlowControl
= FLOW_OFF
;
30 Settings
.Timeout_Millisec
= 500;
32 QextSerialPort
serialPort(device
, Settings
);
33 serialPort
.open(QIODevice::ReadOnly
);
36 if (!file
.open(QIODevice::WriteOnly
)) {
37 qDebug() << "Failed to open file: " << outFile
;
41 QTextStream
ts(&file
);
44 dat
= serialPort
.read(500);
45 if (dat
.contains(framing
)) {
46 int start
= dat
.indexOf(framing
);
47 int count
= *((int *)(dat
.data() + start
+ 16));
48 qDebug() << "Found frame start at " << start
<< " count " << count
;
49 } else if (dat
.size() == 0) {
50 qDebug() << "No data";
52 qDebug() << "No frame start";
64 int main(int argc
, char *argv
[])
66 QCoreApplication
a(argc
, argv
);
71 device
= "/dev/tty.usbserial-000014FAB";
73 device
= QString(argv
[1]);
79 log
= QString(argv
[2]);
82 pollSerialPort
thread(device
, log
);