QextSerialPort hangs on close()



  • I am using the QextSerialPort library in a small GUI application. I am able to open and communicate over the port successfully. However, I am not able to ever close the port manually by calling the close method. Here is my code. Anyone else seen this behavior before? Any suggestions? I am using Window 7 64bit.

    @//get the available ports
    SerialPort::FindAvailablePorts();

    QList<QextPortInfo> portinfos = SerialPort::ports;
    foreach(QextPortInfo q, portinfos)
    {
    Port_Name = q.portName;
    ControllerCOM = new SerialPort();
    ControllerCOM->myPort->setPortName(Port_Name);
    ControllerCOM->myPort->open(QIODevice::ReadWrite);
    if(ControllerCOM->myPort->isOpen())
    {
    ControllerCOM->myPort->setBaudRate(Port_Settings.BaudRate);
    ControllerCOM->myPort->setDataBits(Port_Settings.DataBits);
    ControllerCOM->myPort->setFlowControl(Port_Settings.FlowControl);
    ControllerCOM->myPort->setParity(Port_Settings.Parity);
    ControllerCOM->myPort->setStopBits(Port_Settings.StopBits);
    ControllerCOM->myPort->setTimeout(Port_Settings.Timeout_Millisec);
    ControllerCOM->myPort->setDtr(true);
    ControllerCOM->myPort->setRts(true);

    }

    //connect the signals to the slots
    connect(ControllerCOM,SIGNAL(dataAvailableSig(QByteArray,QString)),this,SLOT(Data_Received(QByteArray, QString)));
    connect(ControllerCOM,SIGNAL(deviceConnectedSig()),this,SLOT(Controller_Connected()));
    connect(ControllerCOM,SIGNAL(deviceLostSig()),this,SLOT(Controller_Disconnected()));
    Run_Cmd("/1&R\r\n");
    Sleep(50);

    }@

    In the destructor of the class I am calling the close method.
    @Motor_Controller::~Motor_Controller()
    {
    if(ControllerCOM->myPort->isOpen())
    ControllerCOM->myPort->close();
    qDebug() << "Destroyed Controller";

    }@



  • Hi there,
    Maybe just a thought (never used the QextSerialPort software) but it inherits its data stuff from QIODevice, so why not use those as signals for your slots like in the examples given:
    @
    QextSerialPort* port = new QextSerialPort("COM1");
    connect(port, SIGNAL(readyRead()), myClass, SLOT(onDataAvailable()));
    port->open();

    void MyClass::onDataAvailable()
    {
        QByteArray data = port->readAll();
        processNewData(usbdata);
    }
    

    @
    Before the close you might want to disconnect the signal/slots first?
    Good luck bug hunting!


  • Moderators

    welcome to devnet

    I did not notice such a behavior, when using QExtSerialPort. However, I know that there different versions are floating around. It may be dependent where you have downloaded yours. I had started out a while ago with a buggy version. SourceForge for instance holds an old version. The most recent version I know of is found "here":http://code.google.com/p/qextserialport/
    There is also an alternative Qt-based implementations "QtSerialPort":http://qt-project.org/wiki/QtSerialPort



  • Thanks guys. I found my problem. You do indeed need to make sure all signals are disconnected before trying to close the port. Happy coding!


  • Moderators

    Be sure and edit your initial post and add [Solved] to the title. Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.