Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Serial port
Qt 6.12 LTS is out! See what's new in the release blog

Serial port

Scheduled Pinned Locked Moved C++ Gurus
5 Posts 4 Posters 4.7k 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.
  • J Offline
    J Offline
    JoeMatt
    wrote on last edited by
    #1

    Hi guys, I'm apologize for my English, I hope explain well my problem.. I should use C++ to activate the serial port of a microcontrollor which is located on a rover.., and I should be able to communicate with it, sending information and receiving. But I've no idea to start.. Can you help to solve my problem, giving me some advices? Thank you very much

    J.M. 92

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      Hi JoeMatt! Welcome to DevNet!
      Take a look to a "Qt Serial Port":http://qt-project.org/wiki/QtSerialPort
      I tryed use different libs but this one fully satisfied me.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JoeMatt
        wrote on last edited by
        #3

        Thank you very much!! It will be very useful!!

        J.M. 92

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dreamerindia
          wrote on last edited by
          #4

          Create the Class for interfacing with qextserialport for basic open,close,read and write opertaions.

          This will be helpful for you.

          Declare object for QextSerialPort as,

          @QextSerialPort *port;@

          In Cpp,

          @Seriallib::Seriallib()
          {
          QString portName = QLatin1String("ttyS2");// update this to use your port of choice
          baudRateValue=BAUD38400;
          PortListener(portName);
          if (port->open(QIODevice::ReadWrite) == true) {
          if (!(port->lineStatus() & LS_DSR))
          Q_UNUSED(port->lineStatus())
          }
          else {
          qDebug() << "device failed to open:" << port->errorString();
          }
          }
          void Seriallib::PortListener(const QString & portName)
          {
          this->port = new QextSerialPort(portName, QextSerialPort::EventDriven);
          port->setBaudRate(baudRateValue);
          port->setFlowControl(FLOW_OFF);
          port->setParity(PAR_NONE);
          port->setDataBits(DATA_8);
          port->setStopBits(STOP_1);
          port->setTimeout(10);
          }
          unsigned int Seriallib::onReadyRead()
          {
          unsigned int l_nValue=0;short int counterLoop=0;
          while(1){
          counterLoop++;
          if (port->bytesAvailable()) {
          QByteArray l_arrValue = port->readAll();
          l_nValue = l_arrValue.toHex().toUInt(0,16);
          qDebug()<<"onReadyRead :"<<hex<<l_nValue;
          break;
          }
          if(counterLoop==10000){
          //emit Error(true);
          break;
          }
          }
          return l_nValue;
          }
          QByteArray Seriallib::onReadyRead(QByteArray l_arrValue)
          {
          while(1){
          if (port->bytesAvailable()) {
          l_arrValue = port->readAll();
          break;
          }
          }
          return l_arrValue;
          }

          unsigned int Seriallib::onReadyWrite(unsigned int cmd){

              QByteArray xData;
              xData.append(cmd);
              port->write(xData);
              xData.clear();
              return 1;
          

          }
          unsigned int Seriallib::onCloseSerial(){
          port->close();
          return 1;
          }@

          two read functions are given, one directly wait nad read the port content and another will wait for specified loop count and if data not comes it breaks.

          ~Ravivarman~

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            May be this can help you : http://code.google.com/p/qtterm/

            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
            • Unsolved