0

I am trying to decide on a technology for developing a desktop application that can interface with the serial port. I have looked into python and it looks like a console based app would not be difficult - http://pyserial.sourceforge.net/ , and I have also looked at PyQt, which would fulfill the GUI portion of my project.

But is it possible to include 3rd party modules like PySerial in PyQt?

Clint
  • 2,871
  • 2
  • 25
  • 28
  • 1
    I'm not seeing the connection here. What makes you think you wouldn't be able to use PySerial and PyQT in the same script? Have you tried it and it didn't work? – Jeremiah Jul 26 '12 at 19:55
  • Maybe I don't understand the fundamental concept behind PyQt. I figured that it would somehow compile my python code into an executable. Maybe I am wrong and it bundles a python interpreter inside the app. If the former is true, I am betting there are plenty of third party libraries that don't compile to machine code. Is that an incorrect assumption? – Clint Jul 30 '12 at 15:41
  • No, that's not how PyQt works at all. It's a regular Python library. – Jeremiah Jul 30 '12 at 16:46

1 Answers1

1

PyQt and pyserial play nice together (in fact, I'm using them in one of my apps.) The examples on the pyserial website are mostly simple console-like examples, but there's no reason you cannot take data from any of the pyserial objects and use them in PyQt. You could, for instance, take data that you received over a serial port and push it into a QByteArray or NumPy array or anything similar as fits your fancy.

A couple of caveats: if you use Serial.readline(), it is blocking until it gets a newline (\n). This could be bad for your GUI. If you must use readline() instead of read(), I recommend putting your pyserial related activities in a separate thread. How you do this is up to you, but I'd recommend using Qt's built in threading. You can then do data conversions to Qt types and such inside the thread. More info on threading in pyqt.

Edit: almost forgot. If anyone cares, you can use PyQt to write console apps too. Just use QCoreApplication instead of QApplication. Not quite sure why one would do that in python, however, unless you were really fond of Qt's data types... in this case you could use PyQt and pyserial to write a pure console app :D

Community
  • 1
  • 1
troy.unrau
  • 1,142
  • 2
  • 12
  • 26