diff options
author | nobody <nobody@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2003-03-19 02:33:55 +0000 |
---|---|---|
committer | nobody <nobody@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2003-03-19 02:33:55 +0000 |
commit | d753d70c9841174cc935008631012d60b549b3a8 (patch) | |
tree | 210bcfe125f57fb3238f79d43e1a7b491fc4e42c | |
parent | 49a8ecf01ee3800a46ad53f11abef5ebf198d8e4 (diff) | |
download | pyserial-git-release0_1.tar.gz |
This commit was manufactured by cvs2svn to create tag 'release0_1'.release0_1
-rw-r--r-- | CVSROOT/checkoutlist | 13 | ||||
-rw-r--r-- | CVSROOT/commitinfo | 15 | ||||
-rw-r--r-- | CVSROOT/config | 14 | ||||
-rw-r--r-- | CVSROOT/cvswrappers | 23 | ||||
-rw-r--r-- | CVSROOT/editinfo | 21 | ||||
-rw-r--r-- | CVSROOT/loginfo | 26 | ||||
-rw-r--r-- | CVSROOT/modules | 26 | ||||
-rw-r--r-- | CVSROOT/notify | 12 | ||||
-rw-r--r-- | CVSROOT/rcsinfo | 13 | ||||
-rw-r--r-- | CVSROOT/taginfo | 20 | ||||
-rw-r--r-- | CVSROOT/verifymsg | 21 | ||||
-rw-r--r-- | pyserial/CHANGES.txt | 69 | ||||
-rw-r--r-- | pyserial/LICENSE.txt | 61 | ||||
-rw-r--r-- | pyserial/MANIFEST | 13 | ||||
-rw-r--r-- | pyserial/README.txt | 155 | ||||
-rw-r--r-- | pyserial/examples/enhancedserial.py | 62 | ||||
-rw-r--r-- | pyserial/examples/miniterm.py | 135 | ||||
-rw-r--r-- | pyserial/examples/scan.py | 28 | ||||
-rw-r--r-- | pyserial/examples/tcp_serial_redirect.py | 119 | ||||
-rw-r--r-- | pyserial/examples/test.py | 159 | ||||
-rw-r--r-- | pyserial/serial/__init__.py | 21 | ||||
-rw-r--r-- | pyserial/serial/serialjava.py | 197 | ||||
-rw-r--r-- | pyserial/serial/serialposix.py | 388 | ||||
-rw-r--r-- | pyserial/serial/serialutil.py | 65 | ||||
-rw-r--r-- | pyserial/serial/serialwin32.py | 274 | ||||
-rw-r--r-- | pyserial/serial/sermsdos.py | 229 | ||||
-rw-r--r-- | pyserial/setup.py | 17 |
27 files changed, 0 insertions, 2196 deletions
diff --git a/CVSROOT/checkoutlist b/CVSROOT/checkoutlist deleted file mode 100644 index b04b350..0000000 --- a/CVSROOT/checkoutlist +++ /dev/null @@ -1,13 +0,0 @@ -# The "checkoutlist" file is used to support additional version controlled -# administrative files in $CVSROOT/CVSROOT, such as template files. -# -# The first entry on a line is a filename which will be checked out from -# the corresponding RCS file in the $CVSROOT/CVSROOT directory. -# The remainder of the line is an error message to use if the file cannot -# be checked out. -# -# File format: -# -# [<whitespace>]<filename><whitespace><error message><end-of-line> -# -# comment lines begin with '#' diff --git a/CVSROOT/commitinfo b/CVSROOT/commitinfo deleted file mode 100644 index b19e7b7..0000000 --- a/CVSROOT/commitinfo +++ /dev/null @@ -1,15 +0,0 @@ -# The "commitinfo" file is used to control pre-commit checks. -# The filter on the right is invoked with the repository and a list -# of files to check. A non-zero exit of the filter program will -# cause the commit to be aborted. -# -# The first entry on a line is a regular expression which is tested -# against the directory that the change is being committed to, relative -# to the $CVSROOT. For the first match that is found, then the remainder -# of the line is the name of the filter to run. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name "ALL" appears as a regular expression it is always used -# in addition to the first matching regex or "DEFAULT". diff --git a/CVSROOT/config b/CVSROOT/config deleted file mode 100644 index ff43ec0..0000000 --- a/CVSROOT/config +++ /dev/null @@ -1,14 +0,0 @@ -# Set this to "no" if pserver shouldn't check system users/passwords -#SystemAuth=no - -# Put CVS lock files in this directory rather than directly in the repository. -#LockDir=/var/lock/cvs - -# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top -# level of the new working directory when using the `cvs checkout' -# command. -#TopLevelAdmin=no - -# Set `LogHistory' to `all' or `TOFEWGCMAR' to log all transactions to the -# history file, or a subset as needed (ie `TMAR' logs all write operations) -#LogHistory=TOFEWGCMAR diff --git a/CVSROOT/cvswrappers b/CVSROOT/cvswrappers deleted file mode 100644 index 0accaf1..0000000 --- a/CVSROOT/cvswrappers +++ /dev/null @@ -1,23 +0,0 @@ -# This file affects handling of files based on their names. -# -# The -t/-f options allow one to treat directories of files -# as a single file, or to transform a file in other ways on -# its way in and out of CVS. -# -# The -m option specifies whether CVS attempts to merge files. -# -# The -k option specifies keyword expansion (e.g. -kb for binary). -# -# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers) -# -# wildcard [option value][option value]... -# -# where option is one of -# -f from cvs filter value: path to filter -# -t to cvs filter value: path to filter -# -m update methodology value: MERGE or COPY -# -k expansion mode value: b, o, kkv, &c -# -# and value is a single-quote delimited value. -# For example: -#*.gif -k 'b' diff --git a/CVSROOT/editinfo b/CVSROOT/editinfo deleted file mode 100644 index d78886c..0000000 --- a/CVSROOT/editinfo +++ /dev/null @@ -1,21 +0,0 @@ -# The "editinfo" file is used to allow verification of logging -# information. It works best when a template (as specified in the -# rcsinfo file) is provided for the logging procedure. Given a -# template with locations for, a bug-id number, a list of people who -# reviewed the code before it can be checked in, and an external -# process to catalog the differences that were code reviewed, the -# following test can be applied to the code: -# -# Making sure that the entered bug-id number is correct. -# Validating that the code that was reviewed is indeed the code being -# checked in (using the bug-id number or a seperate review -# number to identify this particular code set.). -# -# If any of the above test failed, then the commit would be aborted. -# -# Actions such as mailing a copy of the report to each reviewer are -# better handled by an entry in the loginfo file. -# -# One thing that should be noted is the the ALL keyword is not -# supported. There can be only one entry that matches a given -# repository. diff --git a/CVSROOT/loginfo b/CVSROOT/loginfo deleted file mode 100644 index 5a59f0a..0000000 --- a/CVSROOT/loginfo +++ /dev/null @@ -1,26 +0,0 @@ -# The "loginfo" file controls where "cvs commit" log information -# is sent. The first entry on a line is a regular expression which must match -# the directory that the change is being made to, relative to the -# $CVSROOT. If a match is found, then the remainder of the line is a filter -# program that should expect log information on its standard input. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name ALL appears as a regular expression it is always used -# in addition to the first matching regex or DEFAULT. -# -# You may specify a format string as part of the -# filter. The string is composed of a `%' followed -# by a single format character, or followed by a set of format -# characters surrounded by `{' and `}' as separators. The format -# characters are: -# -# s = file name -# V = old version number (pre-checkin) -# v = new version number (post-checkin) -# -# For example: -#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog -# or -#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog diff --git a/CVSROOT/modules b/CVSROOT/modules deleted file mode 100644 index cb9e9ef..0000000 --- a/CVSROOT/modules +++ /dev/null @@ -1,26 +0,0 @@ -# Three different line formats are valid: -# key -a aliases... -# key [options] directory -# key [options] directory files... -# -# Where "options" are composed of: -# -i prog Run "prog" on "cvs commit" from top-level of module. -# -o prog Run "prog" on "cvs checkout" of module. -# -e prog Run "prog" on "cvs export" of module. -# -t prog Run "prog" on "cvs rtag" of module. -# -u prog Run "prog" on "cvs update" of module. -# -d dir Place module in directory "dir" instead of module name. -# -l Top-level directory only -- do not recurse. -# -# NOTE: If you change any of the "Run" options above, you'll have to -# release and re-checkout any working directories of these modules. -# -# And "directory" is a path to a directory relative to $CVSROOT. -# -# The "-a" option specifies an alias. An alias is interpreted as if -# everything on the right of the "-a" had been typed on the command line. -# -# You can encode a module within a module by using the special '&' -# character to interpose another module into the current module. This -# can be useful for creating a module that consists of many directories -# spread out over the entire source repository. diff --git a/CVSROOT/notify b/CVSROOT/notify deleted file mode 100644 index 34f0bc2..0000000 --- a/CVSROOT/notify +++ /dev/null @@ -1,12 +0,0 @@ -# The "notify" file controls where notifications from watches set by -# "cvs watch add" or "cvs edit" are sent. The first entry on a line is -# a regular expression which is tested against the directory that the -# change is being made to, relative to the $CVSROOT. If it matches, -# then the remainder of the line is a filter program that should contain -# one occurrence of %s for the user to notify, and information on its -# standard input. -# -# "ALL" or "DEFAULT" can be used in place of the regular expression. -# -# For example: -#ALL mail %s -s "CVS notification" diff --git a/CVSROOT/rcsinfo b/CVSROOT/rcsinfo deleted file mode 100644 index 49e59f4..0000000 --- a/CVSROOT/rcsinfo +++ /dev/null @@ -1,13 +0,0 @@ -# The "rcsinfo" file is used to control templates with which the editor -# is invoked on commit and import. -# -# The first entry on a line is a regular expression which is tested -# against the directory that the change is being made to, relative to the -# $CVSROOT. For the first match that is found, then the remainder of the -# line is the name of the file that contains the template. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name "ALL" appears as a regular expression it is always used -# in addition to the first matching regex or "DEFAULT". diff --git a/CVSROOT/taginfo b/CVSROOT/taginfo deleted file mode 100644 index 274a46d..0000000 --- a/CVSROOT/taginfo +++ /dev/null @@ -1,20 +0,0 @@ -# The "taginfo" file is used to control pre-tag checks. -# The filter on the right is invoked with the following arguments: -# -# $1 -- tagname -# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d -# $3 -- repository -# $4-> file revision [file revision ...] -# -# A non-zero exit of the filter program will cause the tag to be aborted. -# -# The first entry on a line is a regular expression which is tested -# against the directory that the change is being committed to, relative -# to the $CVSROOT. For the first match that is found, then the remainder -# of the line is the name of the filter to run. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name "ALL" appears as a regular expression it is always used -# in addition to the first matching regex or "DEFAULT". diff --git a/CVSROOT/verifymsg b/CVSROOT/verifymsg deleted file mode 100644 index 86f747c..0000000 --- a/CVSROOT/verifymsg +++ /dev/null @@ -1,21 +0,0 @@ -# The "verifymsg" file is used to allow verification of logging -# information. It works best when a template (as specified in the -# rcsinfo file) is provided for the logging procedure. Given a -# template with locations for, a bug-id number, a list of people who -# reviewed the code before it can be checked in, and an external -# process to catalog the differences that were code reviewed, the -# following test can be applied to the code: -# -# Making sure that the entered bug-id number is correct. -# Validating that the code that was reviewed is indeed the code being -# checked in (using the bug-id number or a seperate review -# number to identify this particular code set.). -# -# If any of the above test failed, then the commit would be aborted. -# -# Actions such as mailing a copy of the report to each reviewer are -# better handled by an entry in the loginfo file. -# -# One thing that should be noted is the the ALL keyword is not -# supported. There can be only one entry that matches a given -# repository. diff --git a/pyserial/CHANGES.txt b/pyserial/CHANGES.txt deleted file mode 100644 index 0ad854c..0000000 --- a/pyserial/CHANGES.txt +++ /dev/null @@ -1,69 +0,0 @@ -Version 1.0 13 Feb 2002 - First public release. - Split from the pybsl application (see mspgcc.sourceforge.net) - - New Features: - - Added Jython support - -Version 1.1 14 Feb 2002 - Bugfixes: - - Win32, when not specifying a timeout - - Typos in the Docs - - New Features: - - added serialutil which provides a base class for the Serial - objects. - - - readline, readlines, writelines and flush are now supported - see README.txt for deatils. - -Version 1.11 14 Feb 2002 - Same as 1.1 but added missing files. - -Version 1.12 18 Feb 2002 - Removed unneded constants to fix RH7.x problems. - -Version 1.13 09 Apr 2002 - Added alternate way for enabling rtscts (CNEW_RTSCTS is tried too) - If port opening fails, a SerialException is raised on all platforms - -Version 1.14 29 May 2002 - added examples to archive - added non-blocking mode for timeout=0 (tnx Mat Martineau) - - Bugfixes: - - win32 does now return the remaining characters on timeout - -Version 1.15 04 Jun 2002 - Bugfixes (win32): - - removed debug messages - - compatibility to win9x improved - -Version 1.16 02 Jul 2002 - added implementation of RI and corrected RTS/CTS on Win32 - -Version 1.17 03 Jul 2002 - silly mix of two versions in win32 code corrected - -Version 1.18 06 Dec 2002 - Bugfixes (general): - - remove the mapping of flush to the destructive flushOutput as this - is not the expected behaviour - - readline: EOL character for lines can be chosen idea by John Florian - Bugfixes (posix): - - cygwin port numbering fixed - - test each and every constant for it's existence in termios module, - use default if not existent (fix for Bug item #640214) - - wrong exception on nonexitstent ports with /dev file. bug report - by Louis Cordier - Bugfixes (win32): - - RTS/CTS handling as sugested in Bug #635072 - - bugfix of timeouts brought up by Markus Hoffrogge - -Version 1.19 19 Mar 2003 - Bugfixes (posix): - - removed dgux entry which actualy had a wrong comment and is probably not in use anywhere - Bugfixes (win32): - - added int() conversion, [Bug 702120] - - remove code to set control lines in close methond of win32 version. [Bug 669625] - diff --git a/pyserial/LICENSE.txt b/pyserial/LICENSE.txt deleted file mode 100644 index 72f0b89..0000000 --- a/pyserial/LICENSE.txt +++ /dev/null @@ -1,61 +0,0 @@ -Copyright (c) 2001 Chris Liechti <cliechti@gmx.net>; -All Rights Reserved. - -This is the Python license. In short, you can use this product in -commercial and non-commercial applications, modify it, redistribute it. -A notification to the author when you use and/or modify it is welcome. - - -TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING THIS SOFTWARE -=================================================================== - -LICENSE AGREEMENT ------------------ - -1. This LICENSE AGREEMENT is between the copyright holder of this -product, and the Individual or Organization ("Licensee") accessing -and otherwise using this product in source or binary form and its -associated documentation. - -2. Subject to the terms and conditions of this License Agreement, -the copyright holder hereby grants Licensee a nonexclusive, -royalty-free, world-wide license to reproduce, analyze, test, -perform and/or display publicly, prepare derivative works, distribute, -and otherwise use this product alone or in any derivative version, -provided, however, that copyright holders License Agreement and -copyright holders notice of copyright are retained in this product -alone or in any derivative version prepared by Licensee. - -3. In the event Licensee prepares a derivative work that is based on -or incorporates this product or any part thereof, and wants to make -the derivative work available to others as provided herein, then -Licensee hereby agrees to include in any such work a brief summary of -the changes made to this product. - -4. The copyright holder is making this product available to Licensee on -an "AS IS" basis. THE COPYRIGHT HOLDER MAKES NO REPRESENTATIONS OR -WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, -THE COPYRIGHT HOLDER MAKES NO AND DISCLAIMS ANY REPRESENTATION OR -WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR -THAT THE USE OF THIS PRODUCT WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. - -5. THE COPYRIGHT HOLDER SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER -USERS OF THIS PRODUCT FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL -DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE -USING THIS PRODUCT, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE -POSSIBILITY THEREOF. - -6. This License Agreement will automatically terminate upon a material -breach of its terms and conditions. - -7. Nothing in this License Agreement shall be deemed to create any -relationship of agency, partnership, or joint venture between the -copyright holder and Licensee. This License Agreement does not grant -permission to use trademarks or trade names from the copyright holder -in a trademark sense to endorse or promote products or services of -Licensee, or any third party. - -8. By copying, installing or otherwise using this product, Licensee -agrees to be bound by the terms and conditions of this License -Agreement. - diff --git a/pyserial/MANIFEST b/pyserial/MANIFEST deleted file mode 100644 index 99e248c..0000000 --- a/pyserial/MANIFEST +++ /dev/null @@ -1,13 +0,0 @@ -README.txt -LICENSE.txt -CHANGES.txt -setup.py -serial\__init__.py -serial\serialjava.py -serial\serialposix.py -serial\serialwin32.py -serial\serialutil.py -examples\miniterm.py -examples\tcp_serial_redirect.py -examples\test.py -examples\scan.py diff --git a/pyserial/README.txt b/pyserial/README.txt deleted file mode 100644 index 698ad33..0000000 --- a/pyserial/README.txt +++ /dev/null @@ -1,155 +0,0 @@ -pySerial --------- -This module capsulates the access for the serial port. It provides backends -for standard Python running on Windows, Linux, BSD (possibly any POSIX -compilant system) and Jython. The module named "serial" automaticaly selects -the appropriate backend. - -It is released under a free software license, see LICENSE.txt for more -details. - -Project Homepage: pyserial.sourceforge.net -(C) 2001-2003 Chris Liechti <cliechti@gmx.net> - - -Features --------- -- same class based interface on all supported platforms -- port numbering starts at zero, no need to know the platform dependant port - name in the user program -- port name can be specified if access through numbering is inappropriate -- support for different bytesizes, stopbits, parity and flow control - with RTS/CTS and/or xon/xoff -- working with or without receive timeout, blocking or non-blocking -- file like API with "read" and "write" ("readline" etc. also supported) -- The files in this package are 100% pure Python. - They depend on non standard but common packages on Windows (win32all) and - Jython (JavaComm). POSIX (Linux, BSD) uses only modules from the standard - Python distribution) -- The port is set up for binary transmission. No NULL byte stripping, CR-LF - translation etc. (which are many times enabled for POSIX.) This makes this - module universally useful. - - -Requirements ------------- -- Python 2.0 or newer (1.5.2 untested) -- win32all extensions on Windows -- "Java Communications" (JavaComm) extension for Java/Jython - - -Installation ------------- -Extract files from the archive, open a shell/console in that directory and -let Distutils do the rest: "python setup.py install" - -The files get installed in the "Lib/site-packages" directory in newer -Python versions. - -Serial to USB adapters -Such adapters are reported to work under Mac OSX and Windows. They are -mapped to a normal COM port under Windows, but on Mac OSX they have -special device names like "/dev/cu.USA19QW11P1.1" (built after this scheme: -/dev/[cu|tty].USA<adaptername><USB-part>P<serial-port>.1) either use these -names for the serial ports or create a link to the common device names -like "ln -s /dev/cu.USA19QW11P1.1 /dev/cuaa0" "ln -s /dev/cu.USA19QW21P1.1 -/dev/cuaa1" etc. -But be aware that the device file disappears as soon as you unplug the USB -adapter. - - - -Short introduction ------------------- -Open port 0 at "9600,8,N,1", no timeout ->>> import serial ->>> ser = serial.Serial(0) #open first serial port ->>> print ser.portstr #check which port was realy used ->>> ser.write("hello") #write a string ->>> ser.close() #close port - -Open named port at "19200,8,N,1", 1s timeout ->>> ser = serial.Serial('/dev/ttyS1', 19200, timeout=1) ->>> x = ser.read() #read one byte ->>> s = ser.read(10) #read up to ten bytes (timeout) ->>> line = ser.readline() #read a \n terminated line ->>> ser.close() - -Open second port at "38400,8,E,1", non blocking HW handshaking ->>> ser = serial.Serial(1, 38400, timeout=0, -... parity=serial.PARITY_EVEN, rtscts=1) ->>> s = ser.read(100) #read up to one hunded bytes -... #or as much is in the buffer - -Be carefully when using "readline". Do specify a timeout when -opening the serial port otherwise it could block forever if -no newline character is received. Also note that "readlines" only -works with a timeout. "readlines" depends on having a timeout -and interprets that as EOF (end of file). It raises an exception -if the port is not opened correctly. - - -Parameters for the Serial class -------------------------------- -ser = serial.Serial( - port, #number of device, numbering starts at - #zero. if everything fails, the user - #can specify a device string, note - #that this isn't portable anymore - baudrate=9600, #baudrate - bytesize=EIGHTBITS, #number of databits - parity=PARITY_NONE, #enable parity checking - stopbits=STOPBITS_ONE, #number of stopbits - timeout=None, #set a timeout value, None for waiting forever - xonxoff=0, #enable software flow control - rtscts=0, #enable RTS/CTS flow control -) - -The port is immediately opened on object creation. -Options for read timeout: -timeout=None #wait forever -timeout=0 #non-blocking mode (return immediately on read) -timeout=x #set timeout to x seconds (float allowed) - -Serial object Methods ---------------------- -close() #close port immediately -setBaudrate(baudrate) #change baudarte on an open port -inWaiting() #return the number of chars in the receive buffer -read(size=1) #read "size" characters -write(s) #write the string to the port -flushInput() #flush input buffer -flushOutput() #flush output buffer -sendBreak() #send break condition -setRTS(level=1) #set RTS line to specified logic level -setDTR(level=1) #set DTR line to specified logic level -getCTS() #return the state of the CTS line -getDSR() #return the state of the DSR line -getRI() #return the state of the RI line -getCD() #return the state of the CD line - -Constants ---------- -parity: - serial.PARITY_NONE - serial.PARITY_EVEN - serial.PARITY_ODD -stopbits: - serial.STOPBITS_ONE - serial.STOPBITS_TWO -bytesize: - serial.FIVEBITS - serial.SIXBITS - serial.SEVENBITS - serial.EIGHTBITS - - -References ----------- -- Python: http://www.python.org -- Jython: http://www.jython.org -- win32all: http://starship.python.net/crew/mhammond/ - and http://www.activestate.com/Products/ActivePython/win32all.html -- Java@IBM http://www-106.ibm.com/developerworks/java/jdk/ - (JavaComm links are on the download page for the respective platform jdk) -- Java@SUN http://java.sun.com/products/ diff --git a/pyserial/examples/enhancedserial.py b/pyserial/examples/enhancedserial.py deleted file mode 100644 index 2c81ae1..0000000 --- a/pyserial/examples/enhancedserial.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python -"""Enhanced Serial Port class -part of pyserial (http://pyserial.sf.net) (C)2002 cliechti@gmx.net - -another implementation of the readline and readlines method. -this one should be more efficient because a bunch of characters are read -on each access, but the drawback is that a timeout must be specified to -make it work (enforced by the class __init__). - -this class could be enhanced with a read_until() method and more -like found in the telnetlib. -""" - -from serial import Serial - -class EnhancedSerial(Serial): - def __init__(self, *args, **kwargs): - #ensure that a reasonable timeout is set - timeout = kwargs.get('timeout',0.1) - if timeout < 0.01: timeout = 0.1 - kwargs['timeout'] = timeout - Serial.__init__(self, *args, **kwargs) - self.buf = '' - - def readline(self, maxsize=None, timeout=1): - """maxsize is ignored, timeout in seconds is the max time that is way for a complete line""" - tries = 0 - while 1: - self.buf += self.read(512) - pos = self.buf.find('\n') - if pos >= 0: - line, self.buf = self.buf[:pos+1], self.buf[pos+1:] - return line - tries += 1 - if tries * self.timeout > timeout: - break - line, self.buf = self.buf, '' - return line - - def readlines(self, sizehint=None, timeout=1): - """read all lines that are available. abort after timout - when no more data arrives.""" - lines = [] - while 1: - line = self.readline(timeout=timeout) - if line: - lines.append(line) - if not line or line[-1:] != '\n': - break - return lines - -if __name__=='__main__': - #do some simple tests with a Loopback HW (see test.py for details) - PORT = 0 - #test, only with Loopback HW (shortcut RX/TX pins (3+4 on DSUB 9 and 25) ) - s = EnhancedSerial(PORT) - #write out some test data lines - s.write('\n'.join("hello how are you".split())) - #and read them back - print s.readlines() - #this one should print an empty list - print s.readlines(timeout=0.4) diff --git a/pyserial/examples/miniterm.py b/pyserial/examples/miniterm.py deleted file mode 100644 index 43b4fa8..0000000 --- a/pyserial/examples/miniterm.py +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env python - -#very simple serial terminal -#(C)2002 Chris Liechti >cliecht@gmx.net> - -#input characters are sent directly, received characters are displays as is -#baudrate and echo configuartion is done through globals - - -import sys, os, serial, threading, getopt -#EXITCHARCTER = '\x1b' #ESC -EXITCHARCTER = '\x04' #ctrl+d - -#first choosea platform dependant way to read single characters from the console -if os.name == 'nt': - import msvcrt - def getkey(): - while 1: - if echo: - z = msvcrt.getche() - else: - z = msvcrt.getch() - if z == '\0' or z == '\xe0': #functions keys - msvcrt.getch() - else: - return z - -elif os.name == 'posix': - #XXX: Untested code drrived from the Python FAQ.... - import termios, TERMIOS, sys, os - fd = sys.stdin.fileno() - old = termios.tcgetattr(fd) - new = termios.tcgetattr(fd) - new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO - new[6][TERMIOS.VMIN] = 1 - new[6][TERMIOS.VTIME] = 0 - termios.tcsetattr(fd, TERMIOS.TCSANOW, new) - s = '' # We'll save the characters typed and add them to the pool. - def getkey(): - c = os.read(fd, 1) - if echo: sys.stdout.write(c) - return c - def clenaup_console(): - termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old) - sys.exitfunc = clenaup_console #terminal modes have to be restored on exit... - -else: - raise "Sorry no implementation for your platform (%s) available." % sys.platform - - -def reader(): - """loop forever and copy serial->console""" - while 1: - sys.stdout.write(s.read()) - -def writer(): - """loop and copy console->serial until EOF character is found""" - while 1: - c = getkey() - if c == EXITCHARCTER: break #exit on esc - s.write(c) #send character - if convert_outgoing_cr and c == '\r': - s.write('\n') - if echo: sys.stdout.write('\n') - - -#print a short help message -def usage(): - print >>sys.stderr, """USAGE: %s [options] - Simple Terminal Programm for the serial port. - - options: - -p, --port=PORT: port, a number, defualt = 0 or a device name - -b, --baud=BAUD: baudrate, default 9600 - -r, --rtscts: enable RTS/CTS flow control (default off) - -x, --xonxoff: enable software flow control (default off) - -e, --echo: enable local echo (default off) - -c, --cr: disable CR -> CR+LF translation - - """ % sys.argv[0] - -if __name__ == '__main__': - #parse command line options - try: - opts, args = getopt.getopt(sys.argv[1:], - "hp:b:rxec", - ["help", "port=", "baud=", "rtscts", "xonxoff", "echo", "cr"]) - except getopt.GetoptError: - # print help information and exit: - usage() - sys.exit(2) - - port = 0 - baudrate = 9600 - echo = 0 - convert_outgoing_cr = 1 - rtscts = 0 - xonxoff = 0 - for o, a in opts: - if o in ("-h", "--help"): #help text - usage() - sys.exit() - elif o in ("-p", "--port"): #specified port - try: - port = int(a) - except ValueError: - port = a - elif o in ("-b", "--baud"): #specified baudrate - try: - baudrate = int(a) - except ValueError: - raise ValueError, "Baudrate must be a integer number" - elif o in ("-r", "--rtscts"): - rtscts = 1 - elif o in ("-x", "--xonxoff"): - xonxoff = 1 - elif o in ("-e", "--echo"): - echo = 1 - elif o in ("-c", "--cr"): - convert_outgoing_cr = 0 - - try: - s = serial.Serial(port, baudrate, rtscts=rtscts, xonxoff=xonxoff) - except: - print "could not open port" - sys.exit(1) - print "--- Miniterm --- type Ctrl-D to quit" - #start serial->console thread - r = threading.Thread(target=reader) - r.setDaemon(1) - r.start() - #enter console->serial loop - writer() - - print "\n--- exit ---" diff --git a/pyserial/examples/scan.py b/pyserial/examples/scan.py deleted file mode 100644 index b34aba3..0000000 --- a/pyserial/examples/scan.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -"""Scan for serial ports -part of pyserial (http://pyserial.sf.net) (C)2002 cliechti@gmx.net - -the scan function of this module tries to open each port number -from 0 to 255 and it builds a list of those ports where this was -successful. -""" - -from serial import Serial -from serial.serialutil import SerialException - -def scan(): - """scan for available ports. return a list of tuples (num, name)""" - available = [] - for i in range(256): - try: - s = Serial(i) - available.append( (i, s.portstr)) - s.close() #explicit close 'cause of delayed GC in java - except SerialException: - pass - return available - -if __name__=='__main__': - print "Found ports:" - for n,s in scan(): - print "(%d) %s" % (n,s) diff --git a/pyserial/examples/tcp_serial_redirect.py b/pyserial/examples/tcp_serial_redirect.py deleted file mode 100644 index 0816ad8..0000000 --- a/pyserial/examples/tcp_serial_redirect.py +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env python - -#(C)2002 Chris Liechti >cliecht@gmx.net> -#redirect data from a TCP/IP connection to a serial port and vice versa -#requires python 2.2 'cause socket.sendall is used - -#this program is a hack - do not use it as an example of clean -#threading programming! it's only an example for pyserial. - -import sys, os, serial, threading, getopt, socket, time - -def reader(): - """loop forever and copy serial->console""" - global connection - while 1: - try: - if connection: - connection.sendall(s.read(s.inWaiting())) - else: - time.sleep(0.2) #lower CPU usage... - except socket.error, msg: - print msg - if connection: connection.close() - connection = None - except: - pass - -def writer(): - """loop forever and copy console->serial""" - global connection - try: - while 1: - s.write(connection.recv(1024)) - except socket.error, msg: - print msg - - -#print a short help message -def usage(): - print >>sys.stderr, """USAGE: %s [options] - Simple Terminal Programm for the serial port. - - options: - -p, --port=PORT: serial port, a number, defualt = 0 or a device name - -b, --baud=BAUD: baudrate, default 9600 - -r, --rtscts: enable RTS/CTS flow control (default off) - -x, --xonxoff: enable software flow control (default off) - -P, --localport: TCP/IP port on which to run the server (default 7777) - """ % sys.argv[0] - -if __name__ == '__main__': - connection = None - - #parse command line options - try: - opts, args = getopt.getopt(sys.argv[1:], - "hp:b:rxec", - ["help", "port=", "baud=", "rtscts", "xonxoff", "echo", "cr"]) - except getopt.GetoptError: - # print help information and exit: - usage() - sys.exit(2) - - port = 0 - baudrate = 9600 - rtscts = 0 - xonxoff = 0 - localport = 7777 - for o, a in opts: - if o in ("-h", "--help"): #help text - usage() - sys.exit() - elif o in ("-p", "--port"): #specified port - try: - port = int(a) - except ValueError: - port = a - elif o in ("-b", "--baud"): #specified baudrate - try: - baudrate = int(a) - except ValueError: - raise ValueError, "Baudrate must be a integer number" - elif o in ("-r", "--rtscts"): - rtscts = 1 - elif o in ("-x", "--xonxoff"): - xonxoff = 1 - elif o in ("-P", "--localport"): - try: - localport = int(a) - except ValueError: - raise ValueError, "local port must be an integer number" - - print "--- TCP/IP to Serial redirector --- type Ctrl-C / BREAK to quit" - #start serial->tcp/ip thread - r = threading.Thread(target=reader) - r.setDaemon(1) - r.start() - - try: - s = serial.Serial(port, baudrate, rtscts=rtscts, xonxoff=xonxoff) - except: - print "could not open port" - sys.exit(1) - - srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - srv.bind( ('', localport) ) - srv.listen(1) - while 1: - try: - connection, addr = srv.accept() - print 'Connected by', addr - #enter console->serial loop - writer() - except socket.error, msg: - print msg - if connection: connection.close() - connection = None - - print "\n--- exit ---" diff --git a/pyserial/examples/test.py b/pyserial/examples/test.py deleted file mode 100644 index ec8d13a..0000000 --- a/pyserial/examples/test.py +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/env python -"""Some Tests for the serial module. -part of pyserial (http://pyserial.sf.net) (C)2002 cliechti@gmx.net - -intended to be run on different platforms, to ensure portability of -the code. - -for all these tests a simple hardware is required. -Loopback HW adapter: -shortcut these pin pairs: - TX <-> RX - RTS <-> CTS - DTR <-> DSR - -on a 9 pole DSUB these are the pins (2-3) (4-6) (7-8) - -""" - -import unittest, threading, time -import serial - -#of which port should the tests be performed: -PORT=0 - - -class Test4_Nonblocking(unittest.TestCase): - """Test with timeouts""" - timeout=0 - def setUp(self): - self.s = serial.Serial(PORT,timeout=self.timeout) - def tearDown(self): - self.s.close() - - def test0_Messy(self): - """NonBlocking (timeout=0)""" - #this is only here to write out the message in verbose mode - #because Test3 and Test4 print the same messages - - def test1_ReadEmpty(self): - """timeout: After port open, the input buffer must be empty""" - self.failUnless(self.s.read(1)=='', "expected empty buffer") - def test2_Loopback(self): - """timeout: each sent character should return (binary test). - this is also a test for the binary capability of a port.""" - for c in map(chr,range(256)): - self.s.write(c) - time.sleep(0.02) #there might be a small delay until the character is ready (especialy on win32) - self.failUnless(self.s.inWaiting()==1, "expected exactly one character for inWainting()") - self.failUnless(self.s.read(1)==c, "expected an '%s' which was written before" % c) - self.failUnless(self.s.read(1)=='', "expected empty buffer after all sent chars are read") - def test2_LoopbackTimeout(self): - """timeout: test the timeout/immediate return. - partial results should be returned.""" - self.s.write("HELLO") - time.sleep(0.02) #there might be a small delay until the character is ready (especialy on win32) - #read more characters as are available to run in the timeout - self.failUnless(self.s.read(10)=='HELLO', "expected an 'HELLO' which was written before") - self.failUnless(self.s.read(1)=='', "expected empty buffer after all sent chars are read") - - -class Test3_Timeout(Test4_Nonblocking): - """Same tests as the NonBlocking ones but this time with timeout""" - timeout=1 - def test0_Messy(self): - """Blocking (timeout=1)""" - #this is only here to write out the message in verbose mode - #because Test3 and Test4 print the same messages - -class SendEvent(threading.Thread): - def __init__(self, serial, delay=1): - threading.Thread.__init__(self) - self.serial = serial - self.delay = delay - self.x = threading.Event() - self.stopped = 0 - self.start() - def run(self): - time.sleep(self.delay) - if not self.stopped: - self.serial.write("E") - self.x.set() - def isSet(self): - return self.x.isSet() - def stop(self): - self.stopped = 1 - self.x.wait() - -class Test1_Forever(unittest.TestCase): - """Tests a port with no timeout. These tests require that a - character is sent after some time to stop the test, this is done - through the SendEvent class and the Loopback HW.""" - def setUp(self): - self.s = serial.Serial(PORT,timeout=None) - self.event = SendEvent(self.s) - def tearDown(self): - self.event.stop() - self.s.close() - - def test2_ReadEmpty(self): - """no timeout: after port open, the input buffer must be empty (read). - a character is sent after some time to terminate the test (SendEvent).""" - c = self.s.read(1) - if not (self.event.isSet() and c =='E'): - self.fail("expected marker") - -class Test2_Forever(unittest.TestCase): - """Tests a port with no timeout""" - def setUp(self): - self.s = serial.Serial(PORT,timeout=None) - def tearDown(self): - self.s.close() - - def test1_inWaitingEmpty(self): - """no timeout: after port open, the input buffer must be empty (inWaiting)""" - self.failUnless(self.s.inWaiting()==0, "expected empty buffer") - - def test2_Loopback(self): - """no timeout: each sent character should return (binary test). - this is also a test for the binary capability of a port.""" - for c in map(chr,range(256)): - self.s.write(c) - time.sleep(0.02) #there might be a small delay until the character is ready (especialy on win32) - self.failUnless(self.s.inWaiting()==1, "expected exactly one character for inWainting()") - self.failUnless(self.s.read(1)==c, "expected an '%s' which was written before" % c) - self.failUnless(self.s.inWaiting()==0, "expected empty buffer after all sent chars are read") - - -class Test0_DataWires(unittest.TestCase): - """Test modem control lines""" - def setUp(self): - self.s = serial.Serial(PORT) - def tearDown(self): - self.s.close() - - def test1_RTS(self): - """Test RTS/CTS""" - self.s.setRTS(0) - self.failUnless(self.s.getCTS()==0, "CTS -> 0") - self.s.setRTS(1) - self.failUnless(self.s.getCTS()==1, "CTS -> 1") - - def test2_DTR(self): - """Test DTR/DSR""" - self.s.setDTR(0) - self.failUnless(self.s.getDSR()==0, "DSR -> 0") - self.s.setDTR(1) - self.failUnless(self.s.getDSR()==1, "DSR -> 1") - - def test3_RI(self): - """Test RI""" - self.failUnless(self.s.getRI()==0, "RI -> 0") - -if __name__ == '__main__': - import sys - print __doc__ - print "testing port", PORT - sys.argv.append('-v') - # When this module is executed from the command-line, run all its tests - unittest.main() diff --git a/pyserial/serial/__init__.py b/pyserial/serial/__init__.py deleted file mode 100644 index 75bb07f..0000000 --- a/pyserial/serial/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -#portable serial port access with python -#this is a wrapper module for different platform implementations -# -# (C)2001-2002 Chris Liechti <cliechti@gmx.net> -# this is distributed under a free software license, see license.txt - -import sys, os, string -VERSION = string.split("$Revision: 1.2 $")[1] #extract CVS version - -#chose an implementation, depending on os -if os.name == 'nt': #sys.platform == 'win32': - from serialwin32 import * -elif os.name == 'posix': - from serialposix import * -elif os.name == 'java': - from serialjava import * -else: - raise "Sorry no implementation for your platform available." - -#no "mac" implementation. someone want's to write it? i have no access to a mac. diff --git a/pyserial/serial/serialjava.py b/pyserial/serial/serialjava.py deleted file mode 100644 index a0d48a6..0000000 --- a/pyserial/serial/serialjava.py +++ /dev/null @@ -1,197 +0,0 @@ -#!jython -#module for serial IO for Jython and JavaComm -#see __init__.py -# -#(C) 2002 Chris Liechti <cliechti@gmx.net> -# this is distributed under a free software license, see license.txt - -import sys, os, string, javax.comm -import serialutil - -VERSION = string.split("$Revision: 1.6 $")[1] #extract CVS version - -PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK, PARITY_SPACE = (0,1,2,3,4) -STOPBITS_ONE, STOPBITS_TWO, STOPBITS_ONE_HALVE = (1, 2, 3) -FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS = (5,6,7,8) - - -portNotOpenError = ValueError('port not open') - -def device(portnumber): - enum = javax.comm.CommPortIdentifier.getPortIdentifiers() - ports = [] - while enum.hasMoreElements(): - el = enum.nextElement() - if el.getPortType() == javax.comm.CommPortIdentifier.PORT_SERIAL: - ports.append(el) - return ports[portnumber] - -class Serial(serialutil.FileLike): - def __init__(self, - port, #number of device, numbering starts at - #zero. if everything fails, the user - #can specify a device string, note - #that this isn't portable anymore - baudrate=9600, #baudrate - bytesize=EIGHTBITS, #number of databits - parity=PARITY_NONE, #enable parity checking - stopbits=STOPBITS_ONE, #number of stopbits - timeout=None, #set a timeout value, None for waiting forever - xonxoff=0, #enable software flow control - rtscts=0, #enable RTS/CTS flow control - ): - - if type(port) == type(''): #strings are taken directly - portId = javax.comm.CommPortIdentifier.getPortIdentifier(port) - else: - portId = device(port) #numbers are transformed to a comportid obj - self.portstr = portId.getName() - try: - self.sPort = portId.open("python serial module", 10) - except Exception, msg: - self.sPort = None - raise serialutil.SerialException, "could not open port: %s" % msg - self.instream = self.sPort.getInputStream() - self.outstream = self.sPort.getOutputStream() - self.sPort.enableReceiveTimeout(30) - if bytesize == FIVEBITS: - self.databits = javax.comm.SerialPort.DATABITS_5 - elif bytesize == SIXBITS: - self.databits = javax.comm.SerialPort.DATABITS_6 - elif bytesize == SEVENBITS: - self.databits = javax.comm.SerialPort.DATABITS_7 - elif bytesize == EIGHTBITS: - self.databits = javax.comm.SerialPort.DATABITS_8 - else: - raise ValueError, "unsupported bytesize" - - if stopbits == STOPBITS_ONE: - self.jstopbits = javax.comm.SerialPort.STOPBITS_1 - elif stopbits == STOPBITS_ONE_HALVE: - self.jstopbits = javax.comm.SerialPort.STOPBITS_1_5 - elif stopbits == STOPBITS_TWO: - self.jstopbits = javax.comm.SerialPort.STOPBITS_2 - else: - raise ValueError, "unsupported number of stopbits" - - if parity == PARITY_NONE: - self.jparity = javax.comm.SerialPort.PARITY_NONE - elif parity == PARITY_EVEN: - self.jparity = javax.comm.SerialPort.PARITY_EVEN - elif parity == PARITY_ODD: - self.jparity = javax.comm.SerialPort.PARITY_ODD - elif parity == PARITY_MARK: - self.jparity = javax.comm.SerialPort.PARITY_MARK - elif parity == PARITY_SPACE: - self.jparity = javax.comm.SerialPort.PARITY_SPACE - else: - raise ValueError, "unsupported parity type" - - jflowin = jflowout = 0 - if rtscts: - jflowin = jflowin | javax.comm.SerialPort.FLOWCONTROL_RTSCTS_IN - jflowout = jflowout | javax.comm.SerialPort.FLOWCONTROL_RTSCTS_OUT - if xonxoff: - jflowin = jflowin | javax.comm.SerialPort.FLOWCONTROL_XONXOFF_IN - jflowout = jflowout | javax.comm.SerialPort.FLOWCONTROL_XONXOFF_OUT - - self.sPort.setSerialPortParams(baudrate, self.databits, self.jstopbits, self.jparity) - self.sPort.setFlowControlMode(jflowin | jflowout) - - self.timeout = timeout - if timeout >= 0: - self.sPort.enableReceiveTimeout(timeout*1000) - else: - self.sPort.disableReceiveTimeout() - - def close(self): - if self.sPort: - self.instream.close() - self.outstream.close() - self.sPort.close() - self.sPort = None - - def setBaudrate(self, baudrate): - """change baudrate after port is open""" - if not self.sPort: raise portNotOpenError - self.sPort.setSerialPortParams(baudrate, self.databits, self.jstopbits, self.jparity) - - - def inWaiting(self): - if not self.sPort: raise portNotOpenError - return self.instream.available() - - def write(self, data): - if not self.sPort: raise portNotOpenError - self.outstream.write(data) - - def read(self, size=1): - if not self.sPort: raise portNotOpenError - read = '' - if size > 0: - while len(read) < size: - x = self.instream.read() - if x == -1: - if self.timeout >= 0: - break - else: - read = read + chr(x) - return read - - def flushInput(self): - if not self.sPort: raise portNotOpenError - self.instream.skip(self.instream.available()) - - def flushOutput(self): - if not self.sPort: raise portNotOpenError - self.outstream.flush() - - def sendBreak(self): - if not self.sPort: raise portNotOpenError - self.sPort.sendBreak() - - def getDSR(self): - if not self.sPort: raise portNotOpenError - self.sPort.isDSR() - - def getCD(self): - if not self.sPort: raise portNotOpenError - self.sPort.isCD() - - def getRI(self): - if not self.sPort: raise portNotOpenError - self.sPort.isRI() - - def getCTS(self): - if not self.sPort: raise portNotOpenError - self.sPort.isCTS() - - def setDTR(self,on=1): - if not self.sPort: raise portNotOpenError - self.sPort.setDTR(on) - - def setRTS(self,on=1): - if not self.sPort: raise portNotOpenError - self.sPort.setRTS(on) - -if __name__ == '__main__': - s = Serial(0, - baudrate=19200, #baudrate - bytesize=EIGHTBITS, #number of databits - parity=PARITY_EVEN, #enable parity checking - stopbits=STOPBITS_ONE, #number of stopbits - timeout=3, #set a timeout value, None for waiting forever - xonxoff=0, #enable software flow control - rtscts=0, #enable RTS/CTS flow control - ) - s.setRTS(1) - s.setDTR(1) - s.flushInput() - s.flushOutput() - s.write('hello') - print repr(s.read(5)) - print s.inWaiting() - del s - - - diff --git a/pyserial/serial/serialposix.py b/pyserial/serial/serialposix.py deleted file mode 100644 index ff4cd39..0000000 --- a/pyserial/serial/serialposix.py +++ /dev/null @@ -1,388 +0,0 @@ -#!/usr/bin/env python -#module for serial IO for POSIX compatible systems, like Linux -#see __init__.py -# -#(C) 2001-2002 Chris Liechti <cliechti@gmx.net> -# this is distributed under a free software license, see license.txt -# -#parts based on code from Grant B. Edwards <grante@visi.com>: -# ftp://ftp.visi.com/users/grante/python/PosixSerial.py -# references: http://www.easysw.com/~mike/serial/serial.html - -import sys, os, fcntl, termios, struct, string, select -import serialutil - -VERSION = string.split("$Revision: 1.15 $")[1] #extract CVS version - -PARITY_NONE, PARITY_EVEN, PARITY_ODD = range(3) -STOPBITS_ONE, STOPBITS_TWO = (1, 2) -FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS = (5,6,7,8) - -#Do check the Python version as some constants have moved. -if (sys.hexversion < 0x020100f0): - import TERMIOS -else: - TERMIOS = termios - -if (sys.hexversion < 0x020200f0): - import FCNTL -else: - FCNTL = fcntl - -#try to detect the os so that a device can be selected... -plat = string.lower(sys.platform) - -if plat[:5] == 'linux': #Linux (confirmed) - def device(port): - return '/dev/ttyS%d' % port - -elif plat == 'cygwin': #cywin/win32 (confirmed) - def device(port): - return '/dev/com%d' % (port + 1) - -elif plat == 'openbsd3': #BSD (confirmed) - def device(port): - return '/dev/ttyp%d' % port - -elif plat[:3] == 'bsd' or \ - plat[:6] == 'netbsd' or \ - plat[:7] == 'freebsd' or \ - plat[:7] == 'openbsd' or \ - plat[:6] == 'darwin': #BSD (confirmed for freebsd4: cuaa%d) - def device(port): - return '/dev/cuaa%d' % port - -elif plat[:4] == 'irix': #IRIX® (not tested) - def device(port): - return '/dev/ttyf%d' % port - -elif plat[:2] == 'hp': #HP-UX (not tested) - def device(port): - return '/dev/tty%dp0' % (port+1) - -elif plat[:5] == 'sunos': #Solaris®/SunOS® (confirmed) - def device(port): - return '/dev/tty%c' % (ord('a')+port) - -else: - #platform detection has failed... - info = "sys.platform = %r\nos.name = %r\nserialposix.py version = %s" % (sys.platform, os.name, VERSION) - print """send this information to the author of this module: - -%s - -also add the device name of the serial port and where the -counting starts for the first serial port. -e.g. 'first serial port: /dev/ttyS0' -and with a bit luck you can get this module running... -""" - raise Exception, "this module does not run on this platform, sorry." - -#whats up with "aix", "beos", "sco", .... -#they should work, just need to know the device names. - - -# construct dictionaries for baud rate lookups -baudEnumToInt = {} -baudIntToEnum = {} -for rate in (0,50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600, - 19200,38400,57600,115200,230400,460800,500000,576000,921600, - 1000000,1152000,1500000,2000000,2500000,3000000,3500000,4000000 - ): - try: - i = eval('TERMIOS.B'+str(rate)) - baudEnumToInt[i]=rate - baudIntToEnum[rate] = i - except: - pass - - -#load some constants for later use. -#try to use values from TERMIOS, use defaults from linux otherwise -TIOCMGET = hasattr(TERMIOS, 'TIOCMGET') and TERMIOS.TIOCMGET or 0x5415 -TIOCMBIS = hasattr(TERMIOS, 'TIOCMBIS') and TERMIOS.TIOCMBIS or 0x5416 -TIOCMBIC = hasattr(TERMIOS, 'TIOCMBIC') and TERMIOS.TIOCMBIC or 0x5417 -TIOCMSET = hasattr(TERMIOS, 'TIOCMSET') and TERMIOS.TIOCMSET or 0x5418 - -#TIOCM_LE = hasattr(TERMIOS, 'TIOCM_LE') and TERMIOS.TIOCM_LE or 0x001 -TIOCM_DTR = hasattr(TERMIOS, 'TIOCM_DTR') and TERMIOS.TIOCM_DTR or 0x002 -TIOCM_RTS = hasattr(TERMIOS, 'TIOCM_RTS') and TERMIOS.TIOCM_RTS or 0x004 -#TIOCM_ST = hasattr(TERMIOS, 'TIOCM_ST') and TERMIOS.TIOCM_ST or 0x008 -#TIOCM_SR = hasattr(TERMIOS, 'TIOCM_SR') and TERMIOS.TIOCM_SR or 0x010 - -TIOCM_CTS = hasattr(TERMIOS, 'TIOCM_CTS') and TERMIOS.TIOCM_CTS or 0x020 -TIOCM_CAR = hasattr(TERMIOS, 'TIOCM_CAR') and TERMIOS.TIOCM_CAR or 0x040 -TIOCM_RNG = hasattr(TERMIOS, 'TIOCM_RNG') and TERMIOS.TIOCM_RNG or 0x080 -TIOCM_DSR = hasattr(TERMIOS, 'TIOCM_DSR') and TERMIOS.TIOCM_DSR or 0x100 -TIOCM_CD = hasattr(TERMIOS, 'TIOCM_CD') and TERMIOS.TIOCM_CD or TIOCM_CAR -TIOCM_RI = hasattr(TERMIOS, 'TIOCM_RI') and TERMIOS.TIOCM_RI or TIOCM_RNG -#TIOCM_OUT1 = hasattr(TERMIOS, 'TIOCM_OUT1') and TERMIOS.TIOCM_OUT1 or 0x2000 -#TIOCM_OUT2 = hasattr(TERMIOS, 'TIOCM_OUT2') and TERMIOS.TIOCM_OUT2 or 0x4000 -TIOCINQ = hasattr(TERMIOS, 'FIONREAD') and TERMIOS.FIONREAD or 0x541B - -TIOCM_zero_str = struct.pack('I', 0) -TIOCM_RTS_str = struct.pack('I', TIOCM_RTS) -TIOCM_DTR_str = struct.pack('I', TIOCM_DTR) - -portNotOpenError = ValueError('port not open') - -class Serial(serialutil.FileLike): - def __init__(self, - port, #number of device, numbering starts at - #zero. if everything fails, the user - #can specify a device string, note - #that this isn't portable anymore - baudrate=9600, #baudrate - bytesize=EIGHTBITS, #number of databits - parity=PARITY_NONE, #enable parity checking - stopbits=STOPBITS_ONE, #number of stopbits - timeout=None, #set a timeout value, None for waiting forever - xonxoff=0, #enable software flow control - rtscts=0, #enable RTS/CTS flow control - ): - """init comm port""" - self.fd = None - self.timeout = timeout - vmin = vtime = 0 #timeout is done via select - #open - if type(port) == type(''): #strings are taken directly - self.portstr = port - else: - self.portstr = device(port) #numbers are transformed to a os dependant string - try: - self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK) - except Exception, msg: - self.fd = None - raise serialutil.SerialException, "could not open port: %s" % msg - fcntl.fcntl(self.fd, FCNTL.F_SETFL, 0) #set blocking - try: - self.__tcgetattr() #read current settings - except termios.error, msg: #if a port is nonexistent but has a /dev file, it'll fail here - raise serialutil.SerialException, "could not open port: %s" % msg - #set up raw mode / no echo / binary - self.cflag = self.cflag | (TERMIOS.CLOCAL|TERMIOS.CREAD) - self.lflag = self.lflag & ~(TERMIOS.ICANON|TERMIOS.ECHO|TERMIOS.ECHOE|TERMIOS.ECHOK|TERMIOS.ECHONL| - TERMIOS.ECHOCTL|TERMIOS.ECHOKE|TERMIOS.ISIG|TERMIOS.IEXTEN) #|TERMIOS.ECHOPRT - self.oflag = self.oflag & ~(TERMIOS.OPOST) - if hasattr(TERMIOS, 'IUCLC'): - self.iflag = self.iflag & ~(TERMIOS.INLCR|TERMIOS.IGNCR|TERMIOS.ICRNL|TERMIOS.IUCLC|TERMIOS.IGNBRK) - else: - self.iflag = self.iflag & ~(TERMIOS.INLCR|TERMIOS.IGNCR|TERMIOS.ICRNL|TERMIOS.IGNBRK) - #setup baudrate - try: - self.ispeed = self.ospeed = baudIntToEnum[baudrate] - except: - raise ValueError,'invalid baud rate: %s' % baudrate - #setup char len - self.cflag = self.cflag & ~TERMIOS.CSIZE - if bytesize == 8: - self.cflag = self.cflag | TERMIOS.CS8 - elif bytesize == 7: - self.cflag = self.cflag | TERMIOS.CS7 - elif bytesize == 6: - self.cflag = self.cflag | TERMIOS.CS6 - elif bytesize == 5: - self.cflag = self.cflag | TERMIOS.CS5 - else: - raise ValueError,'invalid char len: '+str(clen) - #setup stopbits - if stopbits == STOPBITS_ONE: - self.cflag = self.cflag & ~(TERMIOS.CSTOPB) - elif stopbits == STOPBITS_TWO: - self.cflag = self.cflag | (TERMIOS.CSTOPB) - else: - raise ValueError,'invalid stopit specification:'+str(stopbits) - #setup parity - self.iflag = self.iflag & ~(TERMIOS.INPCK|TERMIOS.ISTRIP) - if parity == PARITY_NONE: - self.cflag = self.cflag & ~(TERMIOS.PARENB|TERMIOS.PARODD) - elif parity == PARITY_EVEN: - self.cflag = self.cflag & ~(TERMIOS.PARODD) - self.cflag = self.cflag | (TERMIOS.PARENB) - elif parity == PARITY_ODD: - self.cflag = self.cflag | (TERMIOS.PARENB|TERMIOS.PARODD) - else: - raise ValueError,'invalid parity: '+str(par) - #setup flow control - #xonxoff - if hasattr(TERMIOS, 'IXANY'): - if xonxoff: - self.iflag = self.iflag | (TERMIOS.IXON|TERMIOS.IXOFF|TERMIOS.IXANY) - else: - self.iflag = self.iflag & ~(TERMIOS.IXON|TERMIOS.IXOFF|TERMIOS.IXANY) - else: - if xonxoff: - self.iflag = self.iflag | (TERMIOS.IXON|TERMIOS.IXOFF) - else: - self.iflag = self.iflag & ~(TERMIOS.IXON|TERMIOS.IXOFF) - #rtscts - if hasattr(TERMIOS, 'CRTSCTS'): - if rtscts: - self.cflag = self.cflag | (TERMIOS.CRTSCTS) - else: - self.cflag = self.cflag & ~(TERMIOS.CRTSCTS) - elif hasattr(TERMIOS, 'CNEW_RTSCTS'): #try it with alternate constant name - if rtscts: - self.cflag = self.cflag | (TERMIOS.CNEW_RTSCTS) - else: - self.cflag = self.cflag & ~(TERMIOS.CNEW_RTSCTS) - #XXX should there be a warning if setting up rtscts (and xonxoff etc) fails?? - - #buffer - #vmin "minimal number of characters to be read. = for non blocking" - if vmin<0 or vmin>255: - raise ValueError,'invalid vmin: '+str(vmin) - self.cc[TERMIOS.VMIN] = vmin - #vtime - if vtime<0 or vtime>255: - raise ValueError,'invalid vtime: '+str(vtime) - self.cc[TERMIOS.VTIME] = vtime - #activate settings - self.__tcsetattr() - - def __tcsetattr(self): - """internal function to set port attributes""" - termios.tcsetattr(self.fd, TERMIOS.TCSANOW, [self.iflag,self.oflag,self.cflag,self.lflag,self.ispeed,self.ospeed,self.cc]) - - def __tcgetattr(self): - """internal function to get port attributes""" - self.iflag,self.oflag,self.cflag,self.lflag,self.ispeed,self.ospeed,self.cc = termios.tcgetattr(self.fd) - - def close(self): - """close port""" - if self.fd: - os.close(self.fd) - self.fd = None - - def setBaudrate(self, baudrate): - """change baudrate after port is open""" - if not self.fd: raise portNotOpenError - self.__tcgetattr() #read current settings - #setup baudrate - try: - self.ispeed = self.ospeed = baudIntToEnum[baudrate] - except: - raise ValueError,'invalid baud rate: %s' % baudrate - self.__tcsetattr() - - def inWaiting(self): - """how many character are in the input queue""" - #~ s = fcntl.ioctl(self.fd, TERMIOS.FIONREAD, TIOCM_zero_str) - s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str) - return struct.unpack('I',s)[0] - - def write(self, data): - """write a string to the port""" - if not self.fd: raise portNotOpenError - t = len(data) - d = data - while t>0: - n = os.write(self.fd, d) - d = d[n:] - t = t - n - - def read(self, size=1): - """read a number of bytes from the port. - the default is one (unlike files)""" - if not self.fd: raise portNotOpenError - read = '' - inp = None - if size > 0: - while len(read) < size: - #print "\tread(): size",size, "have", len(read) #debug - ready,_,_ = select.select([self.fd],[],[], self.timeout) - if not ready: - break #timeout - buf = os.read(self.fd, size-len(read)) - read = read + buf - if self.timeout >= 0 and not buf: - break #early abort on timeout - return read - - def flushInput(self): - """clear input queue""" - if not self.fd: - raise portNotOpenError - termios.tcflush(self.fd, TERMIOS.TCIFLUSH) - - def flushOutput(self): - """flush output""" - if not self.fd: - raise portNotOpenError - termios.tcflush(self.fd, TERMIOS.TCOFLUSH) - - def sendBreak(self): - """send break signal""" - if not self.fd: - raise portNotOpenError - termios.tcsendbreak(self.fd, 0) - - def drainOutput(self): - """internal - not portable!""" - if not self.fd: raise portNotOpenError - termios.tcdrain(self.fd) - - def nonblocking(self): - """internal - not portable!""" - if not self.fd: - raise portNotOpenError - fcntl.fcntl(self.fd, FCNTL.F_SETFL, FCNTL.O_NONBLOCK) - - def getDSR(self): - """read terminal status line""" - if not self.fd: raise portNotOpenError - s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) - return struct.unpack('I',s)[0] & TIOCM_DSR - - def getCD(self): - """read terminal status line""" - if not self.fd: raise portNotOpenError - s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) - return struct.unpack('I',s)[0] & TIOCM_CD - - def getRI(self): - """read terminal status line""" - if not self.fd: raise portNotOpenError - s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) - return struct.unpack('I',s)[0] & TIOCM_RI - - def getCTS(self): - """read terminal status line""" - if not self.fd: raise portNotOpenError - s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) - return struct.unpack('I',s)[0] & TIOCM_CTS - - def setDTR(self,on=1): - """set terminal status line""" - if not self.fd: raise portNotOpenError - if on: - fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str) - else: - fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_DTR_str) - - def setRTS(self,on=1): - """set terminal status line""" - if not self.fd: raise portNotOpenError - if on: - fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_RTS_str) - else: - fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_RTS_str) - -if __name__ == '__main__': - s = Serial(0, - baudrate=19200, #baudrate - bytesize=EIGHTBITS, #number of databits - parity=PARITY_EVEN, #enable parity checking - stopbits=STOPBITS_ONE, #number of stopbits - timeout=3, #set a timeout value, None for waiting forever - xonxoff=0, #enable software flow control - rtscts=0, #enable RTS/CTS flow control - ) - s.setRTS(1) - s.setDTR(1) - s.flushInput() - s.flushOutput() - s.write('hello') - print repr(s.read(5)) - print s.inWaiting() - del s diff --git a/pyserial/serial/serialutil.py b/pyserial/serial/serialutil.py deleted file mode 100644 index e3a4bdb..0000000 --- a/pyserial/serial/serialutil.py +++ /dev/null @@ -1,65 +0,0 @@ - -class SerialException(Exception): - pass - -class FileLike: - """An abstract file like class. - - This class implements readline and readlines based on read and - writelines based on write. - This class is used to provide the above functions for to Serial - port objects. - - Note that when the serial port was opened with _NO_ timeout that - readline blocks until it sees a newline (or the specified size is - reached) and that readlines would never return and therefore - refuses to work (it raises an exception in this case)! - """ - - def read(self, size): raise NotImplementedError - def write(self, s): raise NotImplementedError - - def readline(self, size=None, eol='\n'): - """read a line which is terminated with end-of-line (eol) character - ('\n' by default) or until timeout""" - line = '' - while 1: - c = self.read(1) - if c: - line += c #not very efficient but lines are usually not that long - if c == eol: - break - if size is not None and len(line) >= size: - break - else: - break - return line - - def readlines(self, sizehint=None, eol='\n'): - """read a list of lines, until timeout - sizehint is ignored""" - if self.timeout is None: - raise ValueError, "Serial port MUST have enabled timeout for this function!" - lines = [] - while 1: - line = self.readline(eol=eol) - if line: - lines.append(line) - if line[-1] != eol: #was the line received with a timeout? - break - else: - break - return lines - - def xreadlines(self, sizehint=None): - """just call readlines - here for compatibility""" - return self.readlines() - - def writelines(self, sequence): - for line in sequence: - self.write(line) - - def flush(self): - """flush of file like objects""" - pass - diff --git a/pyserial/serial/serialwin32.py b/pyserial/serial/serialwin32.py deleted file mode 100644 index b0145cc..0000000 --- a/pyserial/serial/serialwin32.py +++ /dev/null @@ -1,274 +0,0 @@ -#! python -#serial driver for win32 -#see __init__.py -# -#(C) 2001-2002 Chris Liechti <cliechti@gmx.net> -# this is distributed under a free software license, see license.txt - -import win32file # The base COM port and file IO functions. -import win32event # We use events and the WaitFor[Single|Multiple]Objects functions. -import win32con # constants. -import sys, string -import serialutil - -VERSION = string.split("$Revision: 1.18 $")[1] #extract CVS version - -PARITY_NONE, PARITY_EVEN, PARITY_ODD = range(3) -STOPBITS_ONE, STOPBITS_TWO = (1, 2) -FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS = (5,6,7,8) - -portNotOpenError = ValueError('port not open') - -#from winbase.h. these should realy be in win32con -MS_CTS_ON = 16 -MS_DSR_ON = 32 -MS_RING_ON = 64 -MS_RLSD_ON = 128 - -class Serial(serialutil.FileLike): - def __init__(self, - port, #number of device, numbering starts at - #zero. if everything fails, the user - #can specify a device string, note - #that this isn't portable anymore - baudrate=9600, #baudrate - bytesize=EIGHTBITS, #number of databits - parity=PARITY_NONE, #enable parity checking - stopbits=STOPBITS_ONE, #number of stopbits - timeout=None, #set a timeout value, None for waiting forever - xonxoff=0, #enable software flow control - rtscts=0, #enable RTS/CTS flow control - ): - """initialize comm port""" - - self.timeout = timeout - - if type(port) == type(''): #strings are taken directly - self.portstr = port - else: - self.portstr = 'COM%d' % (port+1) #numbers are transformed to a string - #self.portstr = '\\\\.\\COM%d' % (port+1) #WIN NT format?? - - try: - self.hComPort = win32file.CreateFile(self.portstr, - win32con.GENERIC_READ | win32con.GENERIC_WRITE, - 0, # exclusive access - None, # no security - win32con.OPEN_EXISTING, - win32con.FILE_ATTRIBUTE_NORMAL | win32con.FILE_FLAG_OVERLAPPED, - None) - except Exception, msg: - self.hComPort = None #'cause __del__ is called anyway - raise serialutil.SerialException, "could not open port: %s" % msg - # Setup a 4k buffer - win32file.SetupComm(self.hComPort, 4096, 4096) - - #Save original timeout values: - self.orgTimeouts = win32file.GetCommTimeouts(self.hComPort) - - #Set Windows timeout values - #timeouts is a tuple with the following items: - #(ReadIntervalTimeout,ReadTotalTimeoutMultiplier, - # ReadTotalTimeoutConstant,WriteTotalTimeoutMultiplier, - # WriteTotalTimeoutConstant) - if timeout is None: - timeouts = (0, 0, 0, 0, 0) - elif timeout == 0: - timeouts = (win32con.MAXDWORD, 0, 0, 0, 0) - else: - #timeouts = (0, 0, 0, 0, 0) #timeouts are done with WaitForSingleObject - #timeouts = (win32con.MAXDWORD, 0, 0, 0, 1000) #doesn't works - #timeouts = (timeout*1000, 0, timeout*1000, 0, 0) - timeouts = (0, 0, int(timeout*1000), 0, int(timeout*1000)) - win32file.SetCommTimeouts(self.hComPort, timeouts) - - #win32file.SetCommMask(self.hComPort, win32file.EV_RXCHAR | win32file.EV_TXEMPTY | - # win32file.EV_RXFLAG | win32file.EV_ERR) - win32file.SetCommMask(self.hComPort, - win32file.EV_RXCHAR | win32file.EV_RXFLAG | win32file.EV_ERR) - #win32file.SetCommMask(self.hComPort, win32file.EV_ERR) - - # Setup the connection info. - # Get state and modify it: - comDCB = win32file.GetCommState(self.hComPort) - comDCB.BaudRate = baudrate - - if bytesize == FIVEBITS: - comDCB.ByteSize = 5 - elif bytesize == SIXBITS: - comDCB.ByteSize = 6 - elif bytesize == SEVENBITS: - comDCB.ByteSize = 7 - elif bytesize == EIGHTBITS: - comDCB.ByteSize = 8 - - if parity == PARITY_NONE: - comDCB.Parity = win32file.NOPARITY - comDCB.fParity = 0 # Dis/Enable Parity Check - elif parity == PARITY_EVEN: - comDCB.Parity = win32file.EVENPARITY - comDCB.fParity = 1 # Dis/Enable Parity Check - elif parity == PARITY_ODD: - comDCB.Parity = win32file.ODDPARITY - comDCB.fParity = 1 # Dis/Enable Parity Check - - if stopbits == STOPBITS_ONE: - comDCB.StopBits = win32file.ONESTOPBIT - elif stopbits == STOPBITS_TWO: - comDCB.StopBits = win32file.TWOSTOPBITS - comDCB.fBinary = 1 # Enable Binary Transmission - # Char. w/ Parity-Err are replaced with 0xff (if fErrorChar is set to TRUE) - if rtscts: - comDCB.fRtsControl = win32file.RTS_CONTROL_HANDSHAKE - comDCB.fDtrControl = win32file.DTR_CONTROL_HANDSHAKE - else: - comDCB.fRtsControl = win32file.RTS_CONTROL_ENABLE - comDCB.fDtrControl = win32file.DTR_CONTROL_ENABLE - comDCB.fOutxCtsFlow = rtscts - comDCB.fOutxDsrFlow = rtscts - comDCB.fOutX = xonxoff - comDCB.fInX = xonxoff - comDCB.fNull = 0 - comDCB.fErrorChar = 0 - comDCB.fAbortOnError = 0 - - win32file.SetCommState(self.hComPort, comDCB) - - # Clear buffers: - # Remove anything that was there - win32file.PurgeComm(self.hComPort, - win32file.PURGE_TXCLEAR | win32file.PURGE_TXABORT | - win32file.PURGE_RXCLEAR | win32file.PURGE_RXABORT) - - #print win32file.ClearCommError(self.hComPort) #flags, comState = - - #self.overlapped = win32file.OVERLAPPED() - #self.overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None) - - def __del__(self): - self.close() - - def close(self): - """close port""" - if self.hComPort: - #Wait until data is transmitted, but not too long... (Timeout-Time) - #while 1: - # flags, comState = win32file.ClearCommError(hComPort) - # if comState.cbOutQue <= 0 or calcTimeout(startTime) > timeout: - # break - - #~ self.setRTS(0) #causes problem if HW handshake is enabled - #~ self.setDTR(0) - #Clear buffers: - win32file.PurgeComm(self.hComPort, - win32file.PURGE_TXCLEAR | win32file.PURGE_TXABORT | - win32file.PURGE_RXCLEAR | win32file.PURGE_RXABORT) - #Restore original timeout values: - win32file.SetCommTimeouts(self.hComPort, self.orgTimeouts) - #Close COM-Port: - win32file.CloseHandle(self.hComPort) - self.hComPort = None - - def setBaudrate(self, baudrate): - """change baudrate after port is open""" - if not self.hComPort: raise portNotOpenError - # Setup the connection info. - # Get state and modify it: - comDCB = win32file.GetCommState(self.hComPort) - comDCB.BaudRate = baudrate - win32file.SetCommState(self.hComPort, comDCB) - - def inWaiting(self): - """returns the number of bytes waiting to be read""" - flags, comstat = win32file.ClearCommError(self.hComPort) - return comstat.cbInQue - - def read(self, size=1): - "read num bytes from serial port" - if not self.hComPort: raise portNotOpenError - read = '' - if size > 0: - overlapped = win32file.OVERLAPPED() - overlapped.hEvent = win32event.CreateEvent(None, 1, 0, None) - if self.timeout == 0: - flags, comstat = win32file.ClearCommError(self.hComPort) - n = min(comstat.cbInQue, size) - if n > 0: - rc, buf = win32file.ReadFile(self.hComPort, win32file.AllocateReadBuffer(n), overlapped) - win32event.WaitForSingleObject(overlapped.hEvent, win32event.INFINITE) - read = str(buf) - else: - flags, comstat = win32file.ClearCommError(self.hComPort) - rc, buf = win32file.ReadFile(self.hComPort, win32file.AllocateReadBuffer(size), overlapped) - n = win32file.GetOverlappedResult(self.hComPort, overlapped, 1) - read = str(buf[:n]) - return read - - def write(self, s): - "write string to serial port" - if not self.hComPort: raise portNotOpenError - #print repr(s), - overlapped = win32file.OVERLAPPED() - overlapped.hEvent = win32event.CreateEvent(None, 1, 0, None) - err, n = win32file.WriteFile(self.hComPort, s, overlapped) - if err: #will be ERROR_IO_PENDING: - # Wait for the write to complete. - win32event.WaitForSingleObject(overlapped.hEvent, win32event.INFINITE) - - def flushInput(self): - if not self.hComPort: raise portNotOpenError - win32file.PurgeComm(self.hComPort, win32file.PURGE_RXCLEAR | win32file.PURGE_RXABORT) - - def flushOutput(self): - if not self.hComPort: raise portNotOpenError - win32file.PurgeComm(self.hComPort, win32file.PURGE_TXCLEAR | win32file.PURGE_TXABORT) - - def sendBreak(self): - if not self.hComPort: raise portNotOpenError - import time - win32file.SetCommBreak(self.hComPort) - #TODO: how to set the correct duration?? - time.sleep(0.020) - win32file.ClearCommBreak(self.hComPort) - - def setRTS(self,level=1): - """set terminal status line""" - if not self.hComPort: raise portNotOpenError - if level: - win32file.EscapeCommFunction(self.hComPort, win32file.SETRTS) - else: - win32file.EscapeCommFunction(self.hComPort, win32file.CLRRTS) - - def setDTR(self,level=1): - """set terminal status line""" - if not self.hComPort: raise portNotOpenError - if level: - win32file.EscapeCommFunction(self.hComPort, win32file.SETDTR) - else: - win32file.EscapeCommFunction(self.hComPort, win32file.CLRDTR) - - def getCTS(self): - """read terminal status line""" - if not self.hComPort: raise portNotOpenError - return MS_CTS_ON & win32file.GetCommModemStatus(self.hComPort) != 0 - - def getDSR(self): - """read terminal status line""" - if not self.hComPort: raise portNotOpenError - return MS_DSR_ON & win32file.GetCommModemStatus(self.hComPort) != 0 - - def getRI(self): - """read terminal status line""" - if not self.hComPort: raise portNotOpenError - return MS_RING_ON & win32file.GetCommModemStatus(self.hComPort) != 0 - - def getCD(self): - """read terminal status line""" - if not self.hComPort: raise portNotOpenError - return MS_RLSD_ON & win32file.GetCommModemStatus(self.hComPort) != 0 - -#Nur Testfunktion!! -if __name__ == '__main__': - print __name__ - s = Serial(0) - diff --git a/pyserial/serial/sermsdos.py b/pyserial/serial/sermsdos.py deleted file mode 100644 index c16d1bd..0000000 --- a/pyserial/serial/sermsdos.py +++ /dev/null @@ -1,229 +0,0 @@ -# sermsdos.py -# -# History: -# -# 3rd September 2002 Dave Haynes -# 1. First defined -# -# Although this code should run under the latest versions of -# Python, on DOS-based platforms such as Windows 95 and 98, -# it has been specifically written to be compatible with -# PyDOS, available at: -# http://www.python.org/ftp/python/wpy/dos.html -# -# PyDOS is a stripped-down version of Python 1.5.2 for -# DOS machines. Therefore, in making changes to this file, -# please respect Python 1.5.2 syntax. In addition, please -# limit the width of this file to 60 characters. -# -# Note also that the modules in PyDOS contain fewer members -# than other versions, so we are restricted to using the -# following: -# -# In module os: -# ------------- -# environ, chdir, getcwd, getpid, umask, fdopen, close, -# dup, dup2, fstat, lseek, open, read, write, O_RDONLY, -# O_WRONLY, O_RDWR, O_APPEND, O_CREAT, O_EXCL, O_TRUNC, -# access, F_OK, R_OK, W_OK, X_OK, chmod, listdir, mkdir, -# remove, rename, renames, rmdir, stat, unlink, utime, -# execl, execle, execlp, execlpe, execvp, execvpe, _exit, -# system. -# -# In module os.path: -# ------------------ -# curdir, pardir, sep, altsep, pathsep, defpath, linesep. -# - -import os -import sys -import string - -BAUD_RATES = { - 110: "11", - 150: "15", - 300: "30", - 600: "60", - 1200: "12", - 2400: "24", - 4800: "48", - 9600: "96", - 19200: "19"} - -(PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK, -PARITY_SPACE) = range(5) -(STOPBITS_ONE, STOPBITS_ONEANDAHALF, -STOPBITS_TWO) = (1, 1.5, 2) -FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS = (5,6,7,8) -(RETURN_ERROR, RETURN_BUSY, RETURN_RETRY, RETURN_READY, -RETURN_NONE) = ('E', 'B', 'P', 'R', 'N') -portNotOpenError = ValueError('port not open') - -class SerialException(Exception): - pass - -class Serial: - """ - port: number of device; numbering starts at - zero. if everything fails, the user can - specify a device string, note that this - isn't portable any more - baudrate: baud rate - bytesize: number of databits - parity: enable parity checking - stopbits: number of stopbits - timeout: set a timeout (None for waiting forever) - xonxoff: enable software flow control - rtscts: enable RTS/CTS flow control - retry: DOS retry mode - """ - def __init__(self, - port, - baudrate = 9600, - bytesize = EIGHTBITS, - parity = PARITY_NONE, - stopbits = STOPBITS_ONE, - timeout = None, - xonxoff = 0, - rtscts = 0, - retry = RETURN_RETRY - ): - - if type(port) == type(''): - #strings are taken directly - self.portstr = port - else: - #numbers are transformed to a string - self.portstr = 'COM%d' % (port+1) - - self.baud = BAUD_RATES[baudrate] - self.bytesize = str(bytesize) - - if parity == PARITY_NONE: - self.parity = 'N' - elif parity == PARITY_EVEN: - self.parity = 'E' - elif parity == PARITY_ODD: - self.parity = 'O' - elif parity == PARITY_MARK: - self.parity = 'M' - elif parity == PARITY_SPACE: - self.parity = 'S' - - self.stop = str(stopbits) - self.retry = retry - self.filename = "sermsdos.tmp" - - self._config(self.portstr, self.baud, self.parity, - self.bytesize, self.stop, self.retry, self.filename) - - def __del__(self): - self.close() - - def close(self): - pass - - def _config(self, port, baud, parity, data, stop, retry, - filename): - comString = string.join(("MODE ", port, ":" - , " BAUD= ", baud, " PARITY= ", parity - , " DATA= ", data, " STOP= ", stop, " RETRY= ", - retry, " > ", filename ), '') - os.system(comString) - - def setBaudrate(self, baudrate): - self._config(self.portstr, BAUD_RATES[baudrate], - self.parity, self.bytesize, self.stop, self.retry, - self.filename) - - def inWaiting(self): - """returns the number of bytes waiting to be read""" - raise NotImplementedError - - def read(self, num = 1): - "Read num bytes from serial port" - handle = os.open(self.portstr, - os.O_RDONLY | os.O_BINARY) - # print os.fstat(handle) - rv = os.read(handle, num) - os.close(handle) - return rv - - def write(self, s): - "Write string to serial port" - handle = os.open(self.portstr, - os.O_WRONLY | os.O_BINARY) - rv = os.write(handle, s) - os.close(handle) - return rv - - def flushInput(self): - raise NotImplementedError - - def flushOutput(self): - raise NotImplementedError - - def sendBreak(self): - raise NotImplementedError - - def setRTS(self,level=1): - """Set terminal status line""" - raise NotImplementedError - - def setDTR(self,level=1): - """Set terminal status line""" - raise NotImplementedError - - def getCTS(self): - """Eead terminal status line""" - raise NotImplementedError - - def getDSR(self): - """Eead terminal status line""" - raise NotImplementedError - - def getRI(self): - """Eead terminal status line""" - raise NotImplementedError - - def getCD(self): - """Eead terminal status line""" - raise NotImplementedError - - def readline(self, size=None): - raise NotImplementedError - - def readlines(self, sizehint=None): - raise NotImplementedError - - def xreadlines(self, sizehint=None): - raise NotImplementedError - - def writelines(self, sequence): - raise NotImplementedError - - def flush(self): - raise NotImplementedError - - def __repr__(self): - return string.join(( "<Serial>: ", self.portstr - , self.baud, self.parity, self.bytesize, self.stop, - self.retry , self.filename), ' ') - -if __name__ == '__main__': - print __name__ - s = Serial(0) - print s - - - - - - - - - - - - - diff --git a/pyserial/setup.py b/pyserial/setup.py deleted file mode 100644 index 7acfd30..0000000 --- a/pyserial/setup.py +++ /dev/null @@ -1,17 +0,0 @@ -# setup.py -from distutils.core import setup - -#windows installer: -# python setup.py bdist_wininst - -setup( - name="pyserial", - description="Python Serial Port Extension", - version="1.19", - author="Chris Liechti", - author_email="cliechti@gmx.net", - url="http://pyserial.sourceforge.net/", - packages=['serial'], - license="Python", - long_description="Python Serial Port Extension for Win32, Linux, BSD, Jython" -) |