pySerial: write in a blocking mode
Grant Edwards
grante at visi.com
Tue Mar 28 18:44:14 EST 2006
On 2006-03-28, Alejandro <alejandro.weinstein at gmail.com> wrote:
> Hi:
>
> I'm using pySerial to talk to a RS232 to RS485 converter. In order to
> control the converter, I need to control the DTR line to enable/disable
> de RS485 driver. In particular, I need to :
>
> write a character to the serial port
> set the DTR line to level 1 _after_ the last bit of the character is
> send
>
> So I tried this (ser is the serial port object):
>
> ser.write(x)
> ser.setDTR(1)
ser.write(x)
ser.drainOutput()
ser.setDTR(1)
> The problem with this is that the ser.write function returns before the
> character is send, and thus, the DTR line is set too soon. (I checked
> this behaivour with an osciloscope).
>
> I thought that seting the writeTimeout parameter could help, but then I
> realized that the write function wait "up to this time", so it doesn't
> work.
>
> Then I tried waiting some time with time.sleep() after ser.write, but
> the shortest time for time.sleep is to big, and non deterministic, so I
> think this is not an option.
Linux is not a real-time operating system. The
ser.drainOutput() call is going to have the same granularity
and non-determinism as time.sleep().
It sounds like you need a serial board that supports
half-duplex operation.
--
Grant Edwards grante Yow! Hand me a pair of
at leather pants and a CASIO
visi.com keyboard -- I'm living
for today!
More information about the Python-list
mailing list