Results 1 to 3 of 3

Thread: serial port terminal using PyQT and PySerial

  1. #1
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default serial port terminal using PyQT and PySerial

    I am trying to build a serial port terminal using PyQT and PySerial. I am facing a problem in calling a variable list from one function to another. I am passing the available com ports to a list (comports) and populating the QCombobox of available com ports. and when the required com port is selected from QCombobox it is sending the index of the com port from the list.however when i am trying to access the list in an another function(connect to port) it is giving an error(TypeError: 'list' object is not callable).


    Qt Code:
    1. import sys
    2. import serial
    3. import re, itertools
    4. import _winreg as winreg
    5. from PyQt4 import QtCore, QtGui
    6. from datalogger_gui import Ui_Form
    7.  
    8.  
    9. global ser,num,serportnum,comports
    10. comports=[]
    11. class MyForm(QtGui.QMainWindow):
    12. def __init__(self, parent=None):
    13. QtGui.QWidget.__init__(self, parent)
    14. self.ui = Ui_Form()
    15. self.ui.setupUi(self)
    16. QtCore.QObject.connect(self.ui.scan, QtCore.SIGNAL("clicked()"),self.enumerate_serial_ports)
    17. QtCore.QObject.connect(self.ui.connect, QtCore.SIGNAL("clicked()"),self.connect_to_port)
    18. QtCore.QObject.connect(self.ui.disconnect, QtCore.SIGNAL("clicked()"),self.disconnect_from_port)
    19. QtCore.QObject.connect(self.ui.comdropdown, QtCore.SIGNAL('activated(int)'),self.connect_to_port)
    20. # QtCore.QObject.connect(self.ui.comdropdown, QtCore.SIGNAL('activated(int)'),self.set_baudrate)
    21.  
    22.  
    23.  
    24.  
    25. def disconnect_from_port(self):
    26. ser.close()
    27. def enumerate_serial_ports(self):
    28.  
    29. path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'
    30. try:
    31. key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)
    32. except WindowsError:
    33. raise IterationError
    34. #self.ui.statustextEdit.append('ports')
    35. for i in itertools.count():
    36. try:
    37. val = winreg.EnumValue(key, i)
    38. self.ui.statustextEdit.append(str(val[1]))
    39. comports.append(str(val[1]))
    40. except EnvironmentError:
    41. break
    42. self.ui.comdropdown.addItems(comports)
    43. BAUDRATES=list()
    44. BAUDRATES =[50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
    45. 9600, 19200, 38400, 57600, 115200]
    46. self.ui.bauddropdown.addItems(BAUDRATES)
    47. #def set_baudrate(self,baud):
    48. def connect_to_port(self,num):
    49. portno=comports(num)
    50. ser=serial.Serial(portno,1200,timeout=0)
    51. self.ui.statustextEdit.append('connected')
    52. self.ui.statustextEdit.append(str(num))
    53.  
    54. if __name__ == "__main__":
    55. app = QtGui.QApplication(sys.argv)
    56. myapp = MyForm()
    57. myapp.show()
    58. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by bishop; 18th July 2011 at 13:24.

  2. #2
    Join Date
    Oct 2017
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: serial port terminal using PyQT and PySerial

    Hello

    please provide the file" datalogger_gui.py" so that it can be tested.

    Thanks
    Kane

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: serial port terminal using PyQT and PySerial

    please provide the file" datalogger_gui.py" so that it can be tested.
    You can't be serious. The original post is more than 6 years old!
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Serial Port communication
    By mgurbuz in forum Qt Programming
    Replies: 12
    Last Post: 22nd January 2011, 02:38
  2. serial port programming in qt
    By sar_van81 in forum Qt Programming
    Replies: 46
    Last Post: 13th June 2007, 12:27
  3. Serial Port
    By b1 in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2007, 02:05
  4. serial port and USB communication
    By shamik in forum Qt Programming
    Replies: 5
    Last Post: 4th December 2006, 10:40
  5. Serial Port access in Qt
    By Doug Broadwell in forum Newbie
    Replies: 1
    Last Post: 30th November 2006, 09:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.