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. Problem connecting to the serial port
Forum Updated to NodeBB v4.3 + New Features

Problem connecting to the serial port

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 6.8k 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.
  • S Offline
    S Offline
    SALA-BANAKISSA
    wrote on last edited by
    #1

    I have a problem opening the COM1 and communication to the xbee, I came writing even a single character even read what I get, is that a person of good will could help me if please? this is urgent, thank you.
    here is my error message:
    "
    bool __thiscall QSerialPort::setBaudRate(int,class QFlags<enum QSerialPort::Direction>): device not open
    Message written
    "

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The question might seem silly but: did you call open on your serial device before setting its baud rate ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SALA-BANAKISSA
        wrote on last edited by
        #3

        yes I opened the front port to speed configuration, see the function:

        serial->open(QIODevice::ReadWrite);

        serial->setBaudRate(9600);
        
        if (serial->portName()!= "COM1") 
        

        {

            serial->close();
        
            serial->setPortName("COM1");
        
            if (!serial->open(QIODevice::ReadWrite)) 
        

        {

                processError(tr("Can't open %1, error code %2")
                             .arg(serial->portName()).arg(serial->error()));
        
                return;
        
            }
        
            if (!serial->setBaudRate(QSerialPort::Baud19200)) 
        

        {
        processError(tr("Can't set rate 19200 baud to port %1, error code %2")
        .arg(serial->portName()).arg(serial->error()));

                return;
        
        
            }
        
            if (!serial->setDataBits(QSerialPort::Data8)) 
        

        {

                processError(tr("Can't set 8 data bits to port %1, error code %2")
                             .arg(serial->portName()).arg(serial->error()));
                return;
        
            }
        
            if (!serial->setParity(QSerialPort::NoParity))
        

        {

                processError(tr("Can't set no patity to port %1, error code %2")
                             .arg(serial->portName()).arg(serial->error()));
                return;
        
            }
        
            if (!serial->setStopBits(QSerialPort::OneStop))
        

        {

                processError(tr("Can't set 1 stop bit to port %1, error code %2")
                             .arg(serial->portName()).arg(serial->error()));
        
                return;
        
            }
        
            if (!serial->setFlowControl(QSerialPort::NoFlowControl)) 
        

        {

                processError(tr("Can't set no flow control to port %1, error code %2")
                             .arg(serial->portName()).arg(serial->error()));
        
                return;
        
            }
        }
        
        
        qDebug() << "Message written";
        
        this->msgRequest = "O";
        
        serial->write(msgRequest);
        
        serialTimer->start(400);
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SALA-BANAKISSA
          wrote on last edited by
          #4

          and I still have the same error;

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Please, enclose your code in coding tags (one @ at the beginning and one at the end) That will make it readable.

            You don't check that your first open did succeed

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SALA-BANAKISSA
              wrote on last edited by
              #6

              le code est :

              @ serial->open(QIODevice::ReadWrite);
              serial->setBaudRate(9600);

              if (serial->portName()!= "COM1") {
              
                  serial->close();
                  serial->setPortName("COM1");
              
                  if (!serial->open(QIODevice::ReadWrite)) {
                      processError(tr("Can't open %1, error code %2")
                                   .arg(serial->portName()).arg(serial->error()));
                      return;
                  }
              
                  if (!serial->setBaudRate(QSerialPort::Baud19200)) {
                      processError(tr("Can't set rate 19200 baud to port %1, error code %2")
                                   .arg(serial->portName()).arg(serial->error()));
                      return;
                  }
              
                  if (!serial->setDataBits(QSerialPort::Data8)) {
                      processError(tr("Can't set 8 data bits to port %1, error code %2")
                                   .arg(serial->portName()).arg(serial->error()));
                      return;
                  }
              
                  if (!serial->setParity(QSerialPort::NoParity)) {
                      processError(tr("Can't set no patity to port %1, error code %2")
                                   .arg(serial->portName()).arg(serial->error()));
                      return;
                  }
              
                  if (!serial->setStopBits(QSerialPort::OneStop)) {
                      processError(tr("Can't set 1 stop bit to port %1, error code %2")
                                   .arg(serial->portName()).arg(serial->error()));
                      return;
                  }
              
                  if (!serial->setFlowControl(QSerialPort::NoFlowControl)) {
                      processError(tr("Can't set no flow control to port %1, error code %2")
                                   .arg(serial->portName()).arg(serial->error()));
                      return;
                  }
              }
              
              
              qDebug() << "Message written";
              this->msgRequest = "O";
              serial->write(msgRequest);
              serialTimer->start(400);@
              
              1 Reply Last reply
              0
              • S Offline
                S Offline
                SALA-BANAKISSA
                wrote on last edited by
                #7

                you say that my first successful opening is to say ? and the fact that this feature is linked to a button QPusButton I said, I do not understand why I do not.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @serial->open(QIODevice::ReadWrite);@

                  This one, you just don't check that it worked,

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SALA-BANAKISSA
                    wrote on last edited by
                    #9

                    I still have the same problem

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SALA-BANAKISSA
                      wrote on last edited by
                      #10

                      it still does not work, what should I do?

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Did you check whether you have an error ? If so which one ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SALA-BANAKISSA
                          wrote on last edited by
                          #12

                          Yes there is a mistake, because it does not even written on the port, it says that the port is not open, I can not communicate to a PC during a test of communication that I 'I write, I do not understand, help me please!

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            Like I said:

                            @serial->open(QIODevice::ReadWrite);@

                            You don't check whether this call to open fails or not. Add the necessary if and and in the else part, print the error you are getting from serial.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            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