Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Set DTR and RTS from code
HvdB last edited by HvdB
Hi there, I am new to Qt5 programming, but do have some Python 3 programming experience. I used to do quite a bit of programming in Delphi, but I now want to switch to Python.
The issue at hand is the behaviour of the DTR and RTS outputs, which seems to differ in the Delphi and even the pyserial implementation. I use the two signal lines together as power supply to power a small PIC microcontroller interface and as said before programs using Delphi, or pyserial work straight away, but all the coding samples using QtSerialPort fail to run. I have tried many variants (dataTerminalReady=False, and/or setDataTerminalReady(True) both in False and True) but none work... I have read quite a bit about issues with the DTR/RTS behaviour in QtSerialPort and wonder whether it might be better to resort to using pyserial?
OS is Windows 10 64 bit and the serial interface is based on the FTDI USB chip. Qt version is 5.14 and Python version is the 3.7.7. 64 bit version.
Can anybody provide some guidance on this topic? Many thanks!
Denni 0 Banned last edited by
Okay my project works with a serial device through a serial port but I never even considered using Qt5 for this as Qt5 is really meant for handling your GUI (aka front-end) and communicating with a Serial Port is the back-end which should have nothing to do with your front-end -- look up discussions and or documentation on MVC methodology.
Now with that said use the serial and serial.tools libraries that are part of python along with these 2 libraries you will want to use the binascii library in particular the unhexlify and hexlify methods
Once you start working with the proper tools setup in the proper MVC layout you will find everything works much better ;-)
If you need more detailed help with this just message me directly and/or post more detailed questions and I can probably help get up and running
HvdB last edited by
Hi Denni, thank you for answering my primary question, whether to consider pyserial rather than QtSerialPort. QtSerialPort just seemed to be a neat solution for the serial connectivity, but I will now look at using pyserial and am hopeful that will work as expected. I also checked out the MVC methodology which indeed is an interesting concept, but I think a bit of overkill for my home project.
I will just keep the topic alive still for some time, just in case somebody has a solution...
@HvdB Qt is not only GUI. Qt has more: networking, serial port, SQL, ...
So, I don't see how using QSerialPort will break MVC...
Either you use QSerialPort or serial.tools from Python is a detail and your preference.
Denni 0 Banned last edited by Denni 0
Using Qt to handle something that has nothing to do with the GUI is adding a completely unnecessary additional layer of complexity to a program. Further the communication through a serial port to a serial device is best handled with the least amount of complexity as additional complexity traditionally slows down the interactions. Further you want to be closer to the hardware level and ideally that would mean coding this interface in just straight C and have APIs that you can call from your Python program but coding it in straight Python is not to much more removed from the hardware level so it can work just fine. Now I am not sure how Qt handles the serial port communications and frankly I find it pointless to try and figure it out heck it might just use the
Python serial and serial.tools libraries. Now since most applications dealing with a serial port device will need the same interface you create regardless then why not K.I.S.S. (Keep It Simple and Smart) It as opposed to M.I.C.C. (Make It Complicated and Crappy -- pronounced Miss) It because those are you only options. Still I do not consider the latter to be a real option because when one is done K.I.S.S.ing it one can easily plug it into any python program one is writing that needs to communicate with a serial device via a serial port regardless of the front-end you are using for that user interface because the MVC approach here keeps the two separate and autonomous and thus not inter-dependent. Its the difference between welding a module permanently in place versus bolting one securely in place so in case you want to use it else where or change the module you can easily do so. Aka the whole concept of object oriented programming
Btw @HvdB I have done this using the
Python serial and serial.tools librariesand have a working module that communicates to a serial device through a serial port if you are interested in that I can share it with you just PM me. Also MVC is actually rather simplistic and could easily be worked into your home project and actually helps make more manageable code once you fully understand its basics
HvdB last edited by
@Denni-0 Denni thank you for your further explanations and offer to assist, but I prefer to try myself first. If I get stuck I will gladly get back to you!