pySerial: write in a blocking mode

pdalet philippe.dalet at voila.fr
Wed Mar 29 10:19:38 CEST 2006


Hi

I have developped a python script to control a rs232c rs485 converter,
named pyRS485
with pythoncard on windows.

ftp-champo.ac-toulouse.fr/pub/btseo/pdalet/python/
python 2.4 Electronics Applications 20050902.exe

The best solution is to send the last character with interrupt. when
the TDR is empty
an interrupt is generated. An interrupt program is executed  to change
the state of dtr. Not evident on Windows and linux.

I have used temporisation, with different values for a slow pc and
speed pc.

Philippe Marie dit Dalet
FIGEAC
FRANCE


Grant Edwards a écrit :

> 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