PDA

View Full Version : serial port terminal using PyQT and PySerial



bishop
18th July 2011, 13:17
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).






import sys
import serial
import re, itertools
import _winreg as winreg
from PyQt4 import QtCore, QtGui
from datalogger_gui import Ui_Form


global ser,num,serportnum,comports
comports=[]
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.scan, QtCore.SIGNAL("clicked()"),self.enumerate_serial_ports)
QtCore.QObject.connect(self.ui.connect, QtCore.SIGNAL("clicked()"),self.connect_to_port)
QtCore.QObject.connect(self.ui.disconnect, QtCore.SIGNAL("clicked()"),self.disconnect_from_port)
QtCore.QObject.connect(self.ui.comdropdown, QtCore.SIGNAL('activated(int)'),self.connect_to_po rt)
# QtCore.QObject.connect(self.ui.comdropdown, QtCore.SIGNAL('activated(int)'),self.set_baudrate)




def disconnect_from_port(self):
ser.close()
def enumerate_serial_ports(self):

path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)
except WindowsError:
raise IterationError
#self.ui.statustextEdit.append('ports')
for i in itertools.count():
try:
val = winreg.EnumValue(key, i)
self.ui.statustextEdit.append(str(val[1]))
comports.append(str(val[1]))
except EnvironmentError:
break
self.ui.comdropdown.addItems(comports)
BAUDRATES=list()
BAUDRATES =[50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
9600, 19200, 38400, 57600, 115200]
self.ui.bauddropdown.addItems(BAUDRATES)
#def set_baudrate(self,baud):
def connect_to_port(self,num):
portno=comports(num)
ser=serial.Serial(portno,1200,timeout=0)
self.ui.statustextEdit.append('connected')
self.ui.statustextEdit.append(str(num))

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())

rksanjiv
27th October 2017, 11:33
Hello

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

Thanks
Kane

d_stranz
27th October 2017, 20:55
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!