Hi people,
using Qt4 plus qextserialport 1.1, I am trying to do couple of things. In the Constructor of my "Motor" class, which is to be controlled using the serial port, I have these two lines pertaining to the serial port. The port settings are correct, and I am also opening the correct device.
port = new QextSerialPort( portFile, portsettings );
connect(port, SIGNAL(readyRead()),this,SLOT(onReceive()));
port = new QextSerialPort( portFile, portsettings );
connect(port, SIGNAL(readyRead()),this,SLOT(onReceive()));
To copy to clipboard, switch view to plain text mode
This is my onReceive():
void Motor::onReceive()
{
if(port->canReadLine()) {
// ("data" is a QByteArray)
// this doesn't work: data = port->readLine(); although QIODevice has it?
char tmp[RX_BUF_SIZE];
qint64 len = port->readLine(tmp, RX_BUF_SIZE);
data.fromRawData(tmp,len);
quint8 fault = 0;
// do something with the data before
// clearing the buffer
data.clear();
rxcnt++;
}
}
void Motor::onReceive()
{
QMutexLocker locker(&m);
if(port->canReadLine()) {
// ("data" is a QByteArray)
// this doesn't work: data = port->readLine(); although QIODevice has it?
char tmp[RX_BUF_SIZE];
qint64 len = port->readLine(tmp, RX_BUF_SIZE);
data.fromRawData(tmp,len);
quint8 fault = 0;
// do something with the data before
// clearing the buffer
data.clear();
rxcnt++;
}
}
To copy to clipboard, switch view to plain text mode
What I want is that it reads the output of the serial controller board for the motor until it hits '\n' and then interprets the results. I noticed there are a variety of methods available to read data from the port, this seemed (intuitively) to be the most straight-forward, but I might be totally off the mark.
Any help would be greatly appreciated.
Thanks,
Stephan
Bookmarks