Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QextSerialPort hangs on close()
Qt 6.11 is out! See what's new in the release blog

QextSerialPort hangs on close()

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    foes0175
    wrote on last edited by
    #1

    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";

    }@

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      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!

      Greetz, Jeroen

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        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

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • F Offline
          F Offline
          foes0175
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

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

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved