ViniciusDamiati / qextserialport

Automatically exported from code.google.com/p/qextserialport
Other
0 stars 0 forks source link

Port doesn't continue read, when the device will be disconnected / connected again while reading #38

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Use Windows Vista. Port is open, reads data (event driven) from the device. 
If I disconnect / connect the device again, I have no chance to get the port 
working again, nevertheless I close the port, create a new port or something 
else.

Original issue reported on code.google.com by Michael....@treggs.com on 7 Feb 2010 at 9:08

GoogleCodeExporter commented 9 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

GoogleCodeExporter commented 9 years ago
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