Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 30th, 2004, 02:47 PM
elesys elesys is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Atlanta
Posts: 5 elesys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to elesys
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

Reply With Quote
  #2  
Old August 9th, 2004, 03:57 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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 ***

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Help! My serial IO exception handler not working


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway