Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-65902

QSerialPort::write() issue with Linux

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 5.10.0
    • Serial Port
    • None
    • Linux Xubuntu 16.04

    Description

      Hello,

      I'm working on embedded system using an STM32 microcontroller. The micro has USB interface configured as CDC ACM Virtual COM.
      After /dev/ttyACM0 is opened by QSerialPort::open(), I sent a simple string to micro with QSerialPort::write():

      serial->write("who");

      This Function is called by microcontroller firmware when data are present in receive buffer:

      void USBD_CDC0_ACM_DataReceived(uint32_t len)
      {
         int32_t cnt;
         (void)(len);
          cnt = USBD_CDC_ACM_ReadData(0U, uart_rx_buf, 64);
          if (cnt > 0) {
                          osSignalSet(T_LED_Thread, 0x01);
          }
      {color:#205081}}

      With QT in Windows it works well: the function is called and in the uart_rx_buff variable the string "who" is present. cnt variable is 3.
      With QT in Linux it works diffent: the function is called for 3 times. uart_rx_buf contans one char sequentially "w" "h" "o" and cnt is always 1.

      I've done a simple mod in qserialport_unix.cpp:

       

      static inline void qt_set_common_props(termios *tio, QIODevice::OpenMode m)

      {
      #ifdef Q_OS_SOLARIS
           tio->c_iflag &= ~(IMAXBEL|IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
           tio->c_oflag &= ~OPOST;
           tio->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
           tio->c_cflag &= ~(CSIZE|PARENB);
           tio->c_cflag |= CS8;
      #else
          ::cfmakeraw(tio);
          //-------------------------------------------------------------------------------------
          // LINUX write raw resolved
          //-------------------------------------------------------------------------------------
          tio.c_cflag |= CREAD;
          tio.c_lflag &= (~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG));
          tio.c_iflag &= (~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY));
          tio.c_oflag &= (~OPOST);
          //-------------------------------------------------------------------------------------

      #endif

          tio->c_cflag |= CLOCAL;
          tio->c_cc[VTIME] = 0;
          tio->c_cc[VMIN] = 0;

          if (m & QIODevice::ReadOnly)
               tio->c_cflag |= CREAD;

      {color:#205081}}

      I took this settings from this old project : https://github.com/qextserialport/qextserialport/blob/master/src/qextserialport_unix.cpp

      With this setting it works well with microcontroller.
      I'm not an expert programmer, only an hobbyist, I don't now if is a right solution and how to reproduce bug without interfacing to the microcontroller but QSerialPort::write() works now.

      Thanks and sorry for my poor english.
      Regards, Massimo.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kuzulis Denis Shienkov
            pusillus max max
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes