PacketDriver::PacketDriver(const QString& cfgPrefix)
: mFifo(cfgPrefix)
{
mSerialPort = new QSerialPort(this);
connect(mSerialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error()));
connect(mSerialPort, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
mSerialPort->setPortName("/dev/ttyUSB0");
if (!mSerialPort
->open
(QIODevice::ReadWrite)) log_exception(PacketDriverException, "cannot open /dev/ttyUSB0");
if (!mSerialPort->setBaudRate(921600))
log_exception(PacketDriverException, "cannot set baud 921600");
if (!mSerialPort->setDataBits(QSerialPort::Data8))
log_exception(PacketDriverException, "cannot set databits 8");
if (!mSerialPort->setParity(QSerialPort::NoParity))
log_exception(PacketDriverException, "cannot set noparity");
if (!mSerialPort->setStopBits(QSerialPort::OneStop))
log_exception(PacketDriverException, "cannot set one stopbits");
if (!mSerialPort->setFlowControl(QSerialPort::NoFlowControl))
log_exception(PacketDriverException, "cannot set noflow");
}
void PacketDriver::error()
{
QString err
=mSerialPort
->errorString
();
std::cout<<"Error:"<<err.toStdString()<<std::endl;
}
void PacketDriver::onReadyRead()
{
std::cout<<"dataAvailable";
if (mSerialPort->bytesAvailable()) {
std::cout<<", bytes:"<<bytes.length()<<std::endl;
readChar(bytes);
}
}
PacketDriver::PacketDriver(const QString& cfgPrefix)
: mFifo(cfgPrefix)
{
mSerialPort = new QSerialPort(this);
connect(mSerialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error()));
connect(mSerialPort, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
mSerialPort->setPortName("/dev/ttyUSB0");
if (!mSerialPort->open(QIODevice::ReadWrite))
log_exception(PacketDriverException, "cannot open /dev/ttyUSB0");
if (!mSerialPort->setBaudRate(921600))
log_exception(PacketDriverException, "cannot set baud 921600");
if (!mSerialPort->setDataBits(QSerialPort::Data8))
log_exception(PacketDriverException, "cannot set databits 8");
if (!mSerialPort->setParity(QSerialPort::NoParity))
log_exception(PacketDriverException, "cannot set noparity");
if (!mSerialPort->setStopBits(QSerialPort::OneStop))
log_exception(PacketDriverException, "cannot set one stopbits");
if (!mSerialPort->setFlowControl(QSerialPort::NoFlowControl))
log_exception(PacketDriverException, "cannot set noflow");
}
void PacketDriver::error()
{
QString err=mSerialPort->errorString();
std::cout<<"Error:"<<err.toStdString()<<std::endl;
}
void PacketDriver::onReadyRead()
{
std::cout<<"dataAvailable";
if (mSerialPort->bytesAvailable()) {
QByteArray bytes = mSerialPort->readAll();
std::cout<<", bytes:"<<bytes.length()<<std::endl;
readChar(bytes);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks