[Tutor] Serial communication ...
Emile van Sebille
emile at fenx.com
Mon Sep 13 20:40:08 CEST 2010
On 9/13/2010 8:36 AM Markus Hubig said...
> Hi @all!
>
> I'm about to write a class for serial communication on Win32 and Linux which
> provides a method called "talk" to send something over the serial line,
> wait for
> the answer and returns it. My problem is, that I don't know how long the
> answer
> will be (ok max 260 bytes but most answers are much smaller).
>
> This is what I have now, please leave some comments:
>
> 1. Will this work on Win32 (with select)?
> 2. Should I better use twisted.internet.serialport?
> 3. Will self.read(260)block until it reads the full 260 bytes?
>
You're subclassing Serial -- the answers to your questions depend on
what that is. So, what is it? Does it support windows? Has anyone
compared/contrasted it to twisted.internet.serialport? What does its
read do? And finally, perhaps, does it have it's own support
group/list? You'll probably get better answers directly from there than
here.
HTH,
Emile
> class SerialDevice(Serial):
>
> def __init__(self,port):
> Serial.__init__(self)
> self.port = port
> self.baudrate = 57600
> self.bytesize = EIGHTBITS
> self.parity = PARITY_ODD
> self.stopbits = STOPBITS_TWO
> self.timeout = 0
> self.xonxoff = 0
> self.rtscts = 0
> self.dsrdtr = 0
> self.open()
> self.flush()
>
> def _write(self, packet):
> fileno = self.fileno()
> while True:
> readable, writeable, excepts = select( [], [fileno], [], 0.2 )
> if fileno in writeable:
> time.sleep(0.1)
> length = self.write(packet)
> break
> return length
>
> def _read(self):
> fileno = self.fileno()
> while True:
> readable, writeable, excepts = select( [], [fileno], [], 0.2 )
> if fileno in readable:
> time.sleep(0.1)
> packet = self.read(260)
> break
> return packet
>
> def talk(self, packet):
> self._write(packet)
> responce = self._read()
> return responce
>
> Thank you, Markus
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list