Fixes to gvret serial for use with TCP/IP connection

This commit is contained in:
Collin Kidder
2018-05-17 20:41:19 -04:00
parent f5b8f1090b
commit f345642b03
+8 -6
View File
@@ -72,12 +72,6 @@ void GVRetSerial::sendToSerial(const QByteArray &bytes)
void GVRetSerial::piStarted() void GVRetSerial::piStarted()
{ {
connectDevice(); connectDevice();
/* start timer */
connect(&mTimer, SIGNAL(timeout()), this, SLOT(handleTick()));
mTimer.setInterval(250); //tick four times per second
mTimer.setSingleShot(false); //keep ticking
mTimer.start();
} }
@@ -287,12 +281,14 @@ void GVRetSerial::connectDevice()
/* open new device */ /* open new device */
if (getPort().contains('.')) //TCP/IP mode then since it looks like an IP address if (getPort().contains('.')) //TCP/IP mode then since it looks like an IP address
{ {
qDebug() << "TCP Connection to a GVRET device";
tcpClient = new QTcpSocket(); tcpClient = new QTcpSocket();
tcpClient->connectToHost(getPort(), 23); tcpClient->connectToHost(getPort(), 23);
connect(tcpClient, SIGNAL(readyRead()), this, SLOT(readSerialData())); connect(tcpClient, SIGNAL(readyRead()), this, SLOT(readSerialData()));
connect(tcpClient, SIGNAL(connected()), this, SLOT(tcpConnected())); connect(tcpClient, SIGNAL(connected()), this, SLOT(tcpConnected()));
} }
else { else {
qDebug() << "Serial connection to a GVRET device";
serial = new QSerialPort(QSerialPortInfo(getPort())); serial = new QSerialPort(QSerialPortInfo(getPort()));
if(!serial) { if(!serial) {
qDebug() << "can't open serial port " << getPort(); qDebug() << "can't open serial port " << getPort();
@@ -362,6 +358,12 @@ void GVRetSerial::tcpConnected()
sendToSerial(output); sendToSerial(output);
/* start timer */
connect(&mTimer, SIGNAL(timeout()), this, SLOT(handleTick()));
mTimer.setInterval(250); //tick four times per second
mTimer.setSingleShot(false); //keep ticking
mTimer.start();
if(doValidation) { if(doValidation) {
QTimer::singleShot(1000, this, SLOT(connectionTimeout())); QTimer::singleShot(1000, this, SLOT(connectionTimeout()));
} }