def port_button(self):
self.ser = serial.Serial()
self.ser.baudrate = 19200
self.ser.port = port_id
self.ser.timeout = 6
self.ser
try:
self.ser.open()
self.button1.configure(state=NORMAL) #allow button to be pushed
except serial.SerialException:
print "No connection to the device could be established"
self.button1.configure(state=DISABLED) #allow button to be pushed
self.Wrong_port()
self.ser.close()
我正在尝试编写代码,如果我为串行通信选择了错误的端口,它将显示错误消息,而不是程序关闭。
我更新了我的解决方案,这对我有用!!!