Event objects Threading on Serial Port on Win32

elcinturapartida at yahoo.es elcinturapartida at yahoo.es
Thu Aug 18 14:06:38 CEST 2005


Hello all,

I am not sure if this question is about threading or serial i/o - it
has elements of both. I'm on WinXP (desktop) and WinNT (labtop), when I
run miniterm.py there is no problem both writing, reading, opening the
com port, no errors, etc.

But if I run wxTerminal.py when read from it nothing happens. It ran
without error and it seemed to write ok, If I run the code to do the
write, then I connect to the device through hyperterminal or wxterm,  I
get the response, so it seems the write is working ok, just very
strange. wxTerminal.py uses Event object to set the event of Threading
module. However wxTerminal.py doesn't loop while alive event is true.

class TerminalFrame(wxFrame):
    """Simple terminal program for wxPython""

    def __init__(self, *args, **kwds):
        self.serial = serial.Serial()
        self.serial.timeout = 0.5   #make sure that the alive event can
be checked from time to time
        self.settings = TerminalSetup() #placeholder for the settings
        self.thread = None
        self.alive = threading.Event()
	....

    def StartThread(self):
        """Start the receiver thread"""
        self.thread = threading.Thread(target=self.ComPortThread)
        self.thread.setDaemon(1)
        self.thread.start()
        self.alive.set()
	....

    def __attach_events(self):
	...
        self.Bind(EVT_SERIALRX, self.OnSerialRead)
        self.Bind(EVT_CLOSE, self.OnClose)
	....

    def ComPortThread(self):
        """Thread that handles the incomming traffic. Does the basic
input
           transformation (newlines) and generates an SerialRxEvent"""
        while self.alive.isSet():               #loop while alive event
is true
            print "Start self.alive.isSet"  <----------------- Don't
show in console.
            text = self.serial.read(1)          #read one, with timout
            if text:                            #check if not timeout


miniterm.py and wxTerminal.py are at http://pyserial.sourceforge.net/

Any advice will be much appreciated.

Thanks

David




More information about the Python-list mailing list