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. Inconsistent behavior of QSerialPort on Debian
QtWS25 Last Chance

Inconsistent behavior of QSerialPort on Debian

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtserialportlinuxescpos
23 Posts 3 Posters 7.7k 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
    Hjunior
    wrote on 25 Jan 2016, 17:11 last edited by Hjunior
    #1

    I want to communicate with Epson TM-H6000iii via EscPos by using QSerialPort 5.5. It cancels printing on serial.close. When I debugged it can't catch the reason. After spending days I found this case:

    Reboot machine
    Run the application. (Printer cancels printing)
    Debug the application and put breakpoint on serial.close(); (Printer behaves as expected)
    Now run the application again. (Printer will NEVER STOP PRINTING again on serial.close)
    To sum up: if I debug serial.close line once then no problem at all.

    Any idea?

    Also i posted this at
    http://stackoverflow.com/questions/34994668/inconsistent-behavior-of-qserialport-on-debian
    I use Debian based Lubuntu 14.04

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Jan 2016, 21:41 last edited by
      #2

      Hi and welcome to devnet,

      You should also add which parameters you use for your serial port.

      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
        Hjunior
        wrote on 27 Jan 2016, 10:20 last edited by Hjunior
        #3

        Hello.

        These are the parameters:

            serial = new QSerialPort(this);
            serial->setPortName(portName);
            serial->setBaudRate(QSerialPort::Baud19200);
            serial->setDataBits(QSerialPort::Data8);
            serial->setParity(QSerialPort::NoParity);
            serial->setStopBits(QSerialPort::OneStop);
            serial->setFlowControl(QSerialPort::HardwareControl);
        

        And i write the bytes to serial port by using:

        bool SerialUtil::writeWait(QByteArray request, const QString name){
            if (serial->write(request)<request.length())
                return false;
            return serial->waitForBytesWritten(3000);
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 27 Jan 2016, 21:34 last edited by
          #4

          What device do you use to connect to the RS232 port of the printer ?

          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 29 Jan 2016, 15:54
          0
          • S SGaist
            27 Jan 2016, 21:34

            What device do you use to connect to the RS232 port of the printer ?

            H Offline
            H Offline
            Hjunior
            wrote on 29 Jan 2016, 15:54 last edited by Hjunior
            #5

            @SGaist As i said My printer is Epson TM-H6000III (M147G) and it is connected to my PC (Intel Atom CPU, 32bit, 4GB Ram) with 9pin to 25pin cable. Im using ttyS4 port which is recognized by lubuntu 14.04 as UART16550. The setup works if i put breakpoint on serial.close and start a debug session once. Then regardless of running or debugging the application it works fine. After rebooting the PC everything is reset. It doesnt work until i debug it. Cant understand whats going on.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 29 Jan 2016, 22:10 last edited by
              #6

              That I understood, what I was asking was about what you had between your printer and computer. You could be using an USB to Serial Port converter but from your description it seems to be an integrated serial port, correct ?

              Do you have any other program that you can use to communicate with your printer ? To see if they also suffer from that strange behavior.

              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 30 Jan 2016, 10:22
              0
              • S SGaist
                29 Jan 2016, 22:10

                That I understood, what I was asking was about what you had between your printer and computer. You could be using an USB to Serial Port converter but from your description it seems to be an integrated serial port, correct ?

                Do you have any other program that you can use to communicate with your printer ? To see if they also suffer from that strange behavior.

                H Offline
                H Offline
                Hjunior
                wrote on 30 Jan 2016, 10:22 last edited by
                #7

                @SGaist Yes im using PC's serial port thats correct, no usb in the setup. No there is no any other program working other than QtCreator. Im sure.

                Is QSerialPort extended from QextSerialPort. Are they same? Shall i try it? I must solve this problem. Or any other idea?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mrdebug
                  wrote on 30 Jan 2016, 15:10 last edited by
                  #8

                  Can you try serial->setFlowControl(); none?
                  I'm using QSerialPort intensively in Debian and I assure it's working perfectly.

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

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 30 Jan 2016, 20:15 last edited by
                    #9

                    No QSerialPort and QextSerialPort are two different things.

                    My question wasn't about having two applications running at the same time. Just if you had the possibility to test the communication with your printer with another application to ensure that the port parameters are correct and the port is working correctly.

                    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
                      Hjunior
                      wrote on 31 Jan 2016, 10:33 last edited by Hjunior
                      #10

                      Hmm, I see. Since it is a RS232 based printer i have no other program by this way. But it has linux driver to work with CUPS. I can test with it tomorrow and will post the results.

                      Actually, i want to ask you about my design. I have a BaseSerialDevice class and QSerialPort is a private pointer stored in BaseSerialDevice.h and created in createPort@BaseSerialDevice.cpp.
                      Then I have an EscPos class which extends BaseSerialDevice and calls createPort in constructor. I have 2 more classes extending the same BaseSerialDevice as same as EscPos. They working without any issue. At a time all of the 3 ports must be open and work. The other 2 has no problem. I checked the IRQs and tried several things but nothing changed. One more idea is they are all attached to MainWindow so they are in same thread. May this be the issue? Or is the setup issue? Or has QSerialPort a hidden bug?

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 31 Jan 2016, 20:40 last edited by
                        #11

                        From your description, are you opening the same port 3 times ?

                        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
                          Hjunior
                          wrote on 1 Feb 2016, 07:48 last edited by Hjunior 2 Jan 2016, 10:17
                          #12

                          No friend they use base same class. The instances are set to use DIFFERENT PORTS as ttyS1,ttyS4,ttyS6

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 3 Feb 2016, 22:05 last edited by
                            #13

                            All of them physical ports of your computer or converter like usb to serial ?

                            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 Feb 2016, 12:50
                            0
                            • S SGaist
                              3 Feb 2016, 22:05

                              All of them physical ports of your computer or converter like usb to serial ?

                              H Offline
                              H Offline
                              Hjunior
                              wrote on 4 Feb 2016, 12:50 last edited by
                              #14

                              @SGaist Yes all of them are phsical ports of my computer. NO usb to serial.

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 4 Feb 2016, 20:29 last edited by
                                #15

                                Does it also happen if you change devices e.g. exchange the devices from ttyS1 and ttyS6.

                                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 15 Feb 2016, 08:12
                                0
                                • S SGaist
                                  4 Feb 2016, 20:29

                                  Does it also happen if you change devices e.g. exchange the devices from ttyS1 and ttyS6.

                                  H Offline
                                  H Offline
                                  Hjunior
                                  wrote on 15 Feb 2016, 08:12 last edited by
                                  #16

                                  @SGaist No difference.

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 15 Feb 2016, 21:50 last edited by
                                    #17

                                    Does the devies need the DTR to be set ?

                                    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 21 Feb 2016, 14:05
                                    0
                                    • S SGaist
                                      15 Feb 2016, 21:50

                                      Does the devies need the DTR to be set ?

                                      H Offline
                                      H Offline
                                      Hjunior
                                      wrote on 21 Feb 2016, 14:05 last edited by
                                      #18

                                      @SGaist Yes the device uses Hardware flow control and in the technical manual says it uses DTR/DSR.

                                      1 Reply Last reply
                                      0
                                      • S Offline
                                        S Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on 21 Feb 2016, 20:37 last edited by
                                        #19

                                        Silly question but, did you set DTR in your application ?

                                        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
                                          Hjunior
                                          wrote on 12 May 2016, 14:23 last edited by
                                          #20

                                          Hello again,

                                          I finally figured out how this occurs.

                                          BaseSerialDevice.cpp

                                          class BaseSerialDevice : public QObject
                                          {
                                              Q_OBJECT
                                          ....
                                          protected:
                                              QSerialPort *serial;
                                          ....
                                          

                                          Problematic.cpp

                                          class Problematic : public BaseSerialDevice
                                          {
                                              Q_OBJECT
                                          ...
                                          

                                          MainWindow.h

                                          ...
                                          private:
                                              Problematic worksLikeACharm;
                                          

                                          Everything works as expected if defined as a NON-POINTER but if;
                                          MainWindow.h

                                          ...
                                          private:
                                              Problematic* notWorksSo;
                                          

                                          then in MainWindow.cpp's constructor:

                                          notWorksSo = new Problematic(parent()); 
                                          or 
                                          notWorksSo = new Problematic(NULL); 
                                          or 
                                          notWorksSo = new Problematic;
                                          

                                          the problem occurs as defined at the start of this topic. And same situation occurs if we use QSocket as same architecture.

                                          I tested it from scratch at least 6 times. Im sure of that case.

                                          And Cant believe and cant understand why?

                                          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