Qextserialport destroy and reinitialize freeze



  • Unfortunately, I am still a little new at Qt4. I am developing on a linux system and am currently using the QextSerialPort libraries.
    When my application starts, it creates a serial port by instantiating a class that I have created called serial which creates the serial port and reads an ini file for settings on the port.

    Also, in my application I have a configuration screen that the user can set certain serial port settings and re write them to the ini file.

    Here comes the issue. After the user has changed all the settings in the dialog box, and the box closes, I am trying to reinitialize the serial port to the settings the user have changed. My thoughts were, all I would have to do is close the port already created. Reset the settings, and then re open the port. I have a function that does this shown below called reinitialize.

    @

    serial::serial(const QString & portName)
    {
    this->port = new QextSerialPort(portName, QextSerialPort::EventDriven); // create serial port
    setsettings(); // set settings for the port
    // control port port
    if (port->open(QIODevice::ReadWrite) == true) // check if device opened properly
    connect(port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    else{
    error.setText("Could not open serial port, please change configuration settings.");
    error.exec();
    }
    status = 0; // clear status
    }

    void serial::reinitialize()
    {
    port->close(); // close the port
    setsettings(); // reset port settings
    // recontrol port
    if (port->open(QIODevice::ReadWrite) == true) // check if device opened properly
    connect(port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    else{
    error.setText("Could not open serial port, please change configuration settings.");
    error.exec();
    }
    }

    @

    When I do this, the program just goes into a freeze state... in which when I close, the Qt4 designer points to this location in which it is freezing within the QextSerialPort file
    @
    qint64 QextSerialPort::readData(char * data, qint64 maxSize)
    {
    QMutexLocker lock(mutex);
    int retVal = ::read(fd, data, maxSize);
    if (retVal == -1)
    lastErr = E_READ_FAILED;

    return retVal;
    

    }
    @

    it gets stuck right on the read. I guess my question is, is there something else I would need to do to just reopen the port with the new settings from the ini file?



  • I'm not quite getting it. When did you read data? The reinitialize() method doesn't involve reading data from the port, does it?



  • No it does not. It just closes the port and re opens it with the new settings. That's where I am confused as well. This QextSerialPort function is from the code provided by the Qextserialport package.

    But my application freezes and I cant click on anything, all my ui dissapears, and when I stop it in the designer, it points me to that file.

    Do I have to destroy the instance of the serial port and recreate it? or.... I dont know, i thought closing the port and re opening would be sufficient enough.

    I honestly dont know how the qextserialport c files initialize serial ports so the read function is beyond me. Maybe its an echo?



  • I just checked the source of QextSerialPort, and readData() is not called when you open/close the port. Can you identify whether the freezing occurs when you close, reopen, or after reopening the port? Maybe offering a piece of onReadyRead() would also help. I had experiences in which readyRead() is triggered without data actually coming in when ports are reopened. This, coupling with certain implementations of onReadyRead(), can block your program.



  • I am currently working on this for you! Sorry for the late reply, I have run into other issues on another project :(


Log in to reply
 

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