Cross-platform serial port access

David Brown dav-nospam-id at westco-nospam-ntrol.com
Thu Mar 22 10:59:00 EST 2001


Grant Edwards wrote in message ...
>In article <99d274$ogv$1 at news.netpower.no>, David Brown wrote:
>
>>I am relatively new to Python, but am planning to use it for a
>>number of small programs that should be able to run both on
>>Windows (for initial development and testing) and Linux (once
>>we get a server running properly). Some of these programs will
>>need to communicate with external devices using a serial port -
>>is this going to work in a portable fashion using Python?
>
>Currently, serial port stuff in Python is not portable between
>Mac/MS/Unix.

I suppose it should be easy enough to make a small wrapper around the
different platforms' code.

>
>>Does anyone know if Linux supports RTS toggle handshaking
>>(i.e., the RTS line is high while transmitting, for convenient
>>connection to RS-485 convertors),
>
>Not with the standard PC serial port driver.  I hacked the
>16x50 driver to do RTS toggle several years ago, but it never
>worked reliably.  It's very difficult to do it reliably in
>software at high baud rates.
>
>Your best bet is to buy a board that supports RTS toggle in
>hardware or use a 232-485 converter that handles it
>automatically by detecting the presence of data.  The only
>board I've used under Linux that supported hardware RTS toggle
>was Cyclades Y series 8-port board.  I believe that RTS toggle
>support doesn't work in their newer boards, so you might have
>to look around.
>

This is definitely a shame.  The RTS toggle works well under NT (no idea
about Win9x) - I have written a Delphi program that uses it to run a RS-485
convertor at 57600.  I don't know for sure how fast RTS is turned off after
the last byte - the other nodes on the bus wait 10 ms before answering
anyway.

I guess under Linux I would have to toggle RTS manually.  Turning it on
before sending is easy enough, it is turning it off at the right time that
is more of a hassle.  I suppose I would have to calculate how long the
sending would take, sleep for that time, then turn it off.  If the process
or thread in question was fairly high priority, this should work with
reasonable accuracy.

So-called "intelligent" RS-485 convertors that read the incomming data and
change direction appropriately have their own problems.  We have delivered
systems that communicated at 300 baud, and "intelligent" convertors
frequently do not work at such slow rates.  Additionally, they generally
need configured with DIP-switches and the like, which is an extra hassle if
you need to change the baud rate.  Simple RTS-controlled convertors are much
easier in that respect.

Although it is not really Python-specific, do you know if there are serial
drivers for Linux that simulate 9-bit UARTs (i.e., swapping the parity bit
from space to mark as appropriate)?

Thanks for your help.







More information about the Python-list mailing list