Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. RS485 Half Duplex Communication
QtWS25 Last Chance

RS485 Half Duplex Communication

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
17 Posts 5 Posters 1.9k Views
  • 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.
  • H Offline
    H Offline
    HSKW
    wrote on 19 May 2021, 13:39 last edited by
    #1

    Hello,

    We are using Yocto BSP (based on Poky) and have developed a QT/QML based application. We are using Qt version 5.9.4.

    1. This Qt application is running on a linux based board which is connected to a processor over RS485 half duplex.

    2. This application has following configuration for half duplex communication:
      int fd;
      fd = open ("/dev/ttymxc2", O_RDWR | O_SYNC);
      struct serial_rs485 rs485conf;
      rs485conf.flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND;
      if (ioctl(fd, TIOCSRS485, &rs485conf) != 0)
      {
      return false;
      } else{
      return true;
      }

    3. Application sends about 250 bytes of data and receives response from end processor within 100 ms.

    4. We are using QSerialPort class for serial communication and have subscribed/connected to “bytesWritten” signal to confirm that Santino board application transfers complete data to end processor.

    5. We are observing some queer behavior in this communication.

    6. We observed that sometimes, even though complete 250 bytes of data is sent from our device (bytesWritten signal received with 250 and no error received), some old packets (which were sent earlier and for whose response was also received) are dumped on Serial port. This is visible only on Serial Port communication monitor tool like Docklight. Application logs never show anything extra bytes written to Serial Port.

    7. We are making sure that serial buffer is cleared using clear() call before sending any data packet and flushing using flush() after sending the data packet over serial port.

    8. Please note this doesn’t happen always, but randomly.

    Is this a known issue where QSerialPort or QIODevice class dumps something on its own on serial Port?
    Or are we doing something wrong?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 19 May 2021, 18:07 last edited by
      #2

      Hi and welcome to devnet,

      Why are you mixing ioctl and QSerialPort ?

      The 5.9 series is pretty outdated, would it be possible to run a more recent version of Qt ?

      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
      1
      • H Offline
        H Offline
        HSKW
        wrote on 20 May 2021, 03:12 last edited by
        #3

        That's the issue, we cannot upgrade the Qt version.
        But do we know if its a known issue of Qt 5.9?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 20 May 2021, 19:52 last edited by
          #4

          Which exact version are you using ?
          You did not answer my question about mixing ioctl and QSerialPort.

          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
          • H Offline
            H Offline
            HSKW
            wrote on 21 May 2021, 05:30 last edited by
            #5

            Qt version used is 5.9.4
            I didn't get what problem we can get by mixing ioctl and QSerialPort? And how we would be able to make same configuration as done using ioctl with QSerialPort.

            S 1 Reply Last reply 21 May 2021, 18:47
            0
            • M Offline
              M Offline
              mrdebug
              wrote on 21 May 2021, 16:15 last edited by
              #6

              In my honest opinion this is not a problem related to QSerialPort. The 485 bus uses the enable (sometimes called direction) signal to write or read from bus.
              When that signal is not managed directly by the 485 transiver we normally write a kernel driver so, after that, everithing has to work perfecly.
              I suggest you to check who and how is managing the enable signal.
              After that some devices make an echo in the bus to manage the anticollision feature.
              If you send something and after that you receive back the same row of bytes that means that none has disturbed the comminication. If you receive a byte row different from that you have trasmit, that meas that someone in the bus has disturb the communication so you have to resend.

              Need programmers to hire?
              www.labcsp.com
              www.denisgottardello.it
              GMT+1
              Skype: mrdebug

              H 1 Reply Last reply 27 May 2021, 05:24
              1
              • H HSKW
                21 May 2021, 05:30

                Qt version used is 5.9.4
                I didn't get what problem we can get by mixing ioctl and QSerialPort? And how we would be able to make same configuration as done using ioctl with QSerialPort.

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 21 May 2021, 18:47 last edited by
                #7

                @HSKW said in RS485 Half Duplex Communication:

                Qt version used is 5.9.4
                I didn't get what problem we can get by mixing ioctl and QSerialPort? And how we would be able to make same configuration as done using ioctl with QSerialPort.

                The problem is not the mixing but how your are doing it. You're opening the same file twice so there might things that might get lost in between. You should open it with QSerialPort and then use the handle that it provides to call your ioctl.

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

                H 1 Reply Last reply 4 Jun 2021, 14:54
                1
                • M mrdebug
                  21 May 2021, 16:15

                  In my honest opinion this is not a problem related to QSerialPort. The 485 bus uses the enable (sometimes called direction) signal to write or read from bus.
                  When that signal is not managed directly by the 485 transiver we normally write a kernel driver so, after that, everithing has to work perfecly.
                  I suggest you to check who and how is managing the enable signal.
                  After that some devices make an echo in the bus to manage the anticollision feature.
                  If you send something and after that you receive back the same row of bytes that means that none has disturbed the comminication. If you receive a byte row different from that you have trasmit, that meas that someone in the bus has disturb the communication so you have to resend.

                  H Offline
                  H Offline
                  HSKW
                  wrote on 27 May 2021, 05:24 last edited by
                  #8

                  @mrdebug
                  Can you please explain how we can configure RS485 half duplex using QSerialPort? We searched through Qt documentation, but couldn't find anything.

                  Thanks.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrdebug
                    wrote on 27 May 2021, 05:44 last edited by
                    #9

                    Hi, QSerialPort manages the rs485 interfaces as a normal full duplex interface. The enable (direction) signal must be manged by the transceiver or by a specific kernel driver.

                    Need programmers to hire?
                    www.labcsp.com
                    www.denisgottardello.it
                    GMT+1
                    Skype: mrdebug

                    1 Reply Last reply
                    1
                    • S SGaist
                      21 May 2021, 18:47

                      @HSKW said in RS485 Half Duplex Communication:

                      Qt version used is 5.9.4
                      I didn't get what problem we can get by mixing ioctl and QSerialPort? And how we would be able to make same configuration as done using ioctl with QSerialPort.

                      The problem is not the mixing but how your are doing it. You're opening the same file twice so there might things that might get lost in between. You should open it with QSerialPort and then use the handle that it provides to call your ioctl.

                      H Offline
                      H Offline
                      HSKW
                      wrote on 4 Jun 2021, 14:54 last edited by HSKW 6 Apr 2021, 14:55
                      #10

                      @SGaist
                      Can you please let me know how to set RS485 mode with half duplex by opening with QserialPort and then using the handle for ioctl?

                      Also, just an update on the issue:

                      1. Yocto BSP with Kernel version 4.1.15, Qt version is 5.9.4
                      2. It is observed that after exchanging some packets over RS485, even though Qt application is not sending or receiving anything, still on Docklight(connected to monitor serial communication) 4096 bytes of data (current byte sent - 4096) are seen.
                      3. Looking at the signal over logic analyzer, we found that TX_ENABLE line remains high in such a case till these old 4096 bytes are dumped.
                      4. We think that somehow kernel driver's TX buffer is getting corrupted and that is getting dumped, causing TX_ENABLE line to remain high.

                      Do we know if this as an known issue? Or is our application causing the TX buffer corruption - which we don't think, as we are clearing the buffer before sending data over SErialPort using clear() call and also calling flush() after sending data. Moreover, we always get bytesWritten signal indicating complete bytes written before we send next request.

                      any help is highly appreciated.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 4 Jun 2021, 19:40 last edited by
                        #11

                        Use the handle returned by QSerialPort::handle to call your ioctls on.

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

                        H 2 Replies Last reply 7 Jun 2021, 07:15
                        2
                        • S SGaist
                          4 Jun 2021, 19:40

                          Use the handle returned by QSerialPort::handle to call your ioctls on.

                          H Offline
                          H Offline
                          HSKW
                          wrote on 7 Jun 2021, 07:15 last edited by
                          #12

                          @SGaist Thanks we will try this.

                          1 Reply Last reply
                          0
                          • S SGaist
                            4 Jun 2021, 19:40

                            Use the handle returned by QSerialPort::handle to call your ioctls on.

                            H Offline
                            H Offline
                            HSKW
                            wrote on 9 Jun 2021, 04:52 last edited by
                            #13

                            @SGaist Thanks. We tried this approach, but we are still seeing old data getting pushed to serial port and application doesn't get any indication/event for data getting written.

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mrdebug
                              wrote on 9 Jun 2021, 09:44 last edited by mrdebug 6 Sept 2021, 09:45
                              #14

                              I don't know which is your problem but I assure QSerialPort works perfectly, since 5.9 release up to now because I use it in a lot of projects, with half (485) and full duplex interfaces, in Linux, Windows, Mac and imx devices.
                              You should search the problem somewehere.
                              If the behaviour happens only with QSerialPort still the problem is somewhere.
                              If you want to make a test using something else than Qt you could find interesting this:
                              https://github.com/denisgottardello/ComPortServer
                              A console based application to test the serial interface and to convert it in a tcp socket, based on fpc. You shouldn't have problem to use it in you device.

                              Need programmers to hire?
                              www.labcsp.com
                              www.denisgottardello.it
                              GMT+1
                              Skype: mrdebug

                              1 Reply Last reply
                              1
                              • B Offline
                                B Offline
                                Beppe
                                wrote on 28 Dec 2023, 09:32 last edited by
                                #15

                                HI

                                We too have the same problem

                                We use QT 5.7 and instead of using QSerialPort we use open() write() and read()

                                Usually the communication is correct, then suddenly part of the packet is resent or even the same packet many times, in short I have to send nine bytes and instead up to eighty bytes come out.

                                Did you have a solution for this problem?

                                Ciao, Beppe

                                1 Reply Last reply
                                0
                                • hskoglundH Online
                                  hskoglundH Online
                                  hskoglund
                                  wrote on 29 Dec 2023, 02:23 last edited by
                                  #16

                                  Hi, perhaps you could work around the bug by stuffing the data inside packets with a sequence number? So when the same data is randomly retransmitted the receiver can safely discard it because it already has that packet.

                                  M 1 Reply Last reply 13 Jan 2024, 19:54
                                  0
                                  • hskoglundH hskoglund
                                    29 Dec 2023, 02:23

                                    Hi, perhaps you could work around the bug by stuffing the data inside packets with a sequence number? So when the same data is randomly retransmitted the receiver can safely discard it because it already has that packet.

                                    M Offline
                                    M Offline
                                    mrdebug
                                    wrote on 13 Jan 2024, 19:54 last edited by
                                    #17

                                    QtSerialPort can't resend the same packet automatically. Have the device or the 485 converter support anti collision? This problem sounds like an 485 anti collision behaviour.

                                    Need programmers to hire?
                                    www.labcsp.com
                                    www.denisgottardello.it
                                    GMT+1
                                    Skype: mrdebug

                                    1 Reply Last reply
                                    1

                                    • Login

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