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. serialport considerations for linux
Forum Updated to NodeBB v4.3 + New Features

serialport considerations for linux

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 814 Views 2 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.
  • A Offline
    A Offline
    agmar
    wrote on last edited by
    #1

    Hi,
    The serialport stuff i was working on ended up working for windows, but it still fails to function correctly on linux and sends random values, even on another (identical) setup

    Are there anythings specifically that could cause this to happen?

    JonBJ 1 Reply Last reply
    0
    • A agmar

      @SGaist Hi, this is the response i get from the port if i add the suggested code to the oenSeriall function :

      bool QSerialPort::setRequestToSend(bool): device not open
      bool QSerialPort::setDataTerminalReady(bool): device not open

      however, if i try adding either of these, nothing sends through the serial port...

      m_serial->open(QSerialPort::ReadWrite);
      m_serial->open(QIODevice::ReadWrite);
      
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #6

      @agmar

      • Put the open() as the first thing in openSerial() (actually immediately after the setPortName()).
      • Always check the return result of any open()s.
      • Remove the open() from writeAll().
      1 Reply Last reply
      3
      • A agmar

        Hi,
        The serialport stuff i was working on ended up working for windows, but it still fails to function correctly on linux and sends random values, even on another (identical) setup

        Are there anythings specifically that could cause this to happen?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @agmar said in serialport considerations for linux:

        Are there anythings specifically that could cause this to happen?

        No.

        I'm not an expert, but at least make sure the baud rate etc. parameters are correct under Linux?

        A 1 Reply Last reply
        0
        • JonBJ JonB

          @agmar said in serialport considerations for linux:

          Are there anythings specifically that could cause this to happen?

          No.

          I'm not an expert, but at least make sure the baud rate etc. parameters are correct under Linux?

          A Offline
          A Offline
          agmar
          wrote on last edited by
          #3

          @JonB

          well, this is the setup:

          private:
              Ui::MainWindow *ui;
              QSerialPort *m_serial;
          
          };
          
          void MainWindow::openSeriall(){
              m_serial->setPortName(portName);
              m_serial->setBaudRate(QSerialPort::Baud19200);
              m_serial->setDataBits(QSerialPort::Data8);
              m_serial->setParity(QSerialPort::NoParity);
              m_serial->setFlowControl(QSerialPort::NoFlowControl);
              m_serial->setStopBits(QSerialPort::OneStop);
          
          }
          
          
          void MainWindow::writeSerial()
          {
          
              QByteArray message;
          
                  message.append(0xFF);
          
          
                 if (m_serial->open(QIODevice::ReadWrite)) {
                     m_serial->write(message);
                     m_serial->waitForBytesWritten(-1);
                     m_serial->close();
          
          }
          }
          
          

          i cant see anything wrong, i took care of the baud rate, data bits...

          maybe no flow control could be causing this? the transmission is successful on a windows pc , strangely enough...

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

            Hi,

            In which direction does the randomness happen ? From your machine to your device ?
            Did you already tried setting requestToSend ? Maybe you need dataTerminalReady.

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

            A 1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              In which direction does the randomness happen ? From your machine to your device ?
              Did you already tried setting requestToSend ? Maybe you need dataTerminalReady.

              A Offline
              A Offline
              agmar
              wrote on last edited by
              #5

              @SGaist Hi, this is the response i get from the port if i add the suggested code to the oenSeriall function :

              bool QSerialPort::setRequestToSend(bool): device not open
              bool QSerialPort::setDataTerminalReady(bool): device not open

              however, if i try adding either of these, nothing sends through the serial port...

              m_serial->open(QSerialPort::ReadWrite);
              m_serial->open(QIODevice::ReadWrite);
              
              
              JonBJ 1 Reply Last reply
              0
              • A agmar

                @SGaist Hi, this is the response i get from the port if i add the suggested code to the oenSeriall function :

                bool QSerialPort::setRequestToSend(bool): device not open
                bool QSerialPort::setDataTerminalReady(bool): device not open

                however, if i try adding either of these, nothing sends through the serial port...

                m_serial->open(QSerialPort::ReadWrite);
                m_serial->open(QIODevice::ReadWrite);
                
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @agmar

                • Put the open() as the first thing in openSerial() (actually immediately after the setPortName()).
                • Always check the return result of any open()s.
                • Remove the open() from writeAll().
                1 Reply Last reply
                3
                • A agmar has marked this topic as solved on

                • Login

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