8 #include "qextserialport.h"
13 INTERFACEBOX::~INTERFACEBOX() {
17 INTERFACEBOX::INTERFACEBOX(QCoreApplication *) : QThread(0) {
21 void INTERFACEBOX::setDatabase(
DATABASE *db) {
26 QTimer::singleShot(10,
this, SLOT(slotInit()));
27 QThread::start(priority);
31 void INTERFACEBOX::slotInit() {
32 QTimer *t =
new QTimer(
this);
33 t->setSingleShot(
false);
34 t->setInterval(600000);
36 connect(t, SIGNAL(timeout()),
this, SLOT(slotThreadAlive()) );
37 connect(
this, SIGNAL(sigRestart()),
this, SLOT(slotRestart()), Qt::QueuedConnection);
42 if (!isRunning())
return;
51 void INTERFACEBOX::slotRestart() {
52 qDebug() <<
"INTERFACEBOX::restart()";
55 for (
int i=0; i<ifcbox.size(); i++) {
56 int line = ifcbox[i].line;
57 QList<DBT_LINES> lines = m_db->
lines(line);
58 if (lines.size() > 0) {
66 BaudRateType speed = BAUD9600;
68 case 110: speed = BAUD110;
break;
69 case 300: speed = BAUD300;
break;
70 case 600: speed = BAUD600;
break;
71 case 1200: speed = BAUD1200;
break;
72 case 2400: speed = BAUD2400;
break;
73 case 4800: speed = BAUD4800;
break;
74 case 9600: speed = BAUD9600;
break;
75 case 19200: speed = BAUD19200;
break;
76 case 38400: speed = BAUD38400;
break;
77 case 57600: speed = BAUD57600;
break;
78 case 115200: speed = BAUD115200;
break;
81 spset.BaudRate = speed;
82 spset.DataBits = DATA_8;
83 spset.Parity = PAR_NONE;
84 spset.StopBits = STOP_1;
85 spset.FlowControl = FLOW_OFF;
86 spset.Timeout_Millisec = line.timeout;
88 QextSerialPort *port =
new QextSerialPort(line.device, spset, QextSerialPort::Polling);
89 port->open(QIODevice::ReadWrite);
90 if (port == NULL || !port->isOpen()) {
94 port->write(
"?", 1); port->flush();
95 sleep(1); port->write(
"1111", 4); port->flush();
96 sleep(1); port->write(
"1111", 4); port->flush();
99 port->write(
"?", 1); port->flush();
100 sleep(1); port->write(
"0000", 4); port->flush();
101 sleep(1); port->write(
"0000", 4); port->flush();
102 sleep(1); port->write(
"0000", 4); port->flush();
108 void INTERFACEBOX::slotThreadAlive() {
109 qDebug() <<
"INTERFACEBOX::slotThreadAlive() Thread is alive :=)";
QList< DBT_INTERFACEBOXES > interfaceboxes(int line=0)
Returns list of interfaceboxes filtered by line number.
QList< DBT_LINES > lines(int line=0)
Returns list of communications lines.
void restart()
Restarts all connected interfaceboxes.
void start(Priority priority=InheritPriority)
Starts the thread.
Class for communication with database.
void quit()
Quits the running thread.
Class describing database table LINES.