serial and threads
Peter Hansen
peter at engcorp.com
Tue Aug 17 07:30:38 EDT 2004
Silke wrote:
> I'm trying to write a program in python using the modules
> 'serialwin32' and 'thread' to create one thread that writes to a
> serial port and another one that reads from it at 'the same time'. My
> definitions are
>
> def NetworkToSerial(input):
> s.write(binascii.unhexlify(input))
> print "SENT: %s" % input
>
> def SerialToNetwork():
> result = s.read(1)
> print "RECEIVED:"
> print binascii.hexlify(result)
>
> and I call them with
>
> thread.start_new_thread(NetworkToSerial, (command,))
> thread.start_new_thread(SerialToNetwork, ())
>
> The first one seems to run fine, but for the second one I get the
> error message 'ClearCommError', 'the handle is invalid'.
How do you open the serial port and pass the "handle" to
the two threads? Or are you just using a global "s"?
More information about the Python-list
mailing list