Serial Port communication

Warren Postma embed at NOSPAM.geocities.com
Mon Sep 25 15:40:10 CEST 2000


The serial api I think is minimal, and therefore a good start is:

(A) Follow all sematics for Python FILE objects (Read, Write methods etc)
(B) Allow introspection of the com ports, in a Pythonic manner
(C) Would it be possible to also support socket-like semantics?

Anyways, here is  starter API description:

devicelist=serial.Enum()
# returns a list of device names. on win32, the
# names are [ "com1", "com2", ... ]
# on linux, the names are
# ["/dev/ttyS0", "/dev/ttyS1", ... ]
# on bsd and other unices, the names
# are [ .... ???? .... ]

bpsRates = serial.EnumBps(<port#>)
# returns valid bps rates for the given
# port. on windows machines, we should
# support bps rates higher than 115200
# if the serial hardware allows
# (ie 16650)
# returns [ 300,600,1200, ... 115200, ... ]

# in the api below, port numbers start at ZERO, and refer
# to the devices as enumerated above.

serial.Open(<Port#>,[<BpsRate>,<WordLen>,<Parity>,<StopBits>] )


x=serial.IsOpen(<Port#>) # returns true if port is open

serial.Close(<Port#>)

data=serial.Read(<Port#>,<#Bytes>)

data=serial.ReadLine(<Port#>,<#Bytes>[,<terminatingchar>])

serial.Write(<Port#>,<#Bytes>)

n = serial.InWaiting(<Port#>)
#  reads number of bytes waiting in the
# incoming buffer

data=serial.WaitFor(<Port#>,<string>,<timeout>)

It should raise exceptions on error conditions, so it never returns a
failure
status code.


Warren Postma






More information about the Python-list mailing list