Closed GoogleCodeExporter closed 8 years ago
That's how it is. The system will probably give the new device a new handle,
etc so you'll always need to
close/reopen it if it's getting disconnected from the system.
Original comment by lst...@gmail.com
on 7 Feb 2010 at 10:09
Wasn't the problem. I closed the port on device removal and opened it again
after connection / alternatively created a new one.
Nothing worked. After I solved issue 39
(http://code.google.com/p/qextserialport/issues/detail?id=39&can=1), now both
methods
work like a charm. So it seems a derivate from that issue. See sample below:
void MainWindow::onDeviceListChanged()
{
QList< QextPortInfo > ports = QextSerialEnumerator::getPorts();
if ( ports.size() == 0 && port->isOpen() )
{
port->close();
}
if ( ports.size() > 0 && !port->isOpen() )
{
// creating a new instance works too!!
// port = new QextSerialPort( "COM15", QextSerialPort::EventDriven);
if (port->open( QIODevice::ReadWrite | QIODevice::Unbuffered ) == true)
{
port->setBaudRate(BAUD57600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->setDtr( true );
port->setRts( true );
connect(port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
connect(port, SIGNAL(dsrChanged(bool)), this, SLOT(onDsrChanged(bool)));
if (!(port->lineStatus() & LS_DSR))
{
qDebug() << "warning: device is not turned on";
}
qDebug() << "listening for data on" << port->portName();
}
}
}
Original comment by Michael....@treggs.com
on 8 Feb 2010 at 6:39
Original issue reported on code.google.com by
Michael....@treggs.com
on 7 Feb 2010 at 9:08