|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help! My serial IO exception handler not working
I am trying to use the following code to enable me to catch when another program is using the serial port, and pop-up a standard error window:
Code:
def OpenSerial():
global ser
try:
ser = serial.Serial()
except:
tkMessageBox.showerror("Serial Port Error", "Could not get serial port")
else:
if ser.isOpen():
ser.close()
ser.baudrate = 9600
ser.port = 'COM1'
ser.open()
ser.setDTR()
#self.StartThread()
tkMessageBox.showinfo("Serial Port Status","COM on %s [%s, %s%s%s%s%s]" % (
ser.portstr,
ser.baudrate,
ser.bytesize,
ser.parity,
ser.stopbits,
ser.rtscts and ' RTS/CTS' or '',
ser.xonxoff and ' Xon/Xoff' or '',
)
)
The part showing a succesfully opened COM port works like I want it to (the "else" portion). Anyone have any ideas as to what I'm doing wrong? I am using Python 2.3 and Pyserial 2.1 |
|
#2
|
||||
|
||||
|
You will only get an exception when you try to open/read/write the port.
Until you attempt to grab the port with the open method the serial module cannot know which port you will be communicationg with. grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Help! My serial IO exception handler not working |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|