URL
https://opencores.org/ocsvn/usb_dongle_fpga/usb_dongle_fpga/trunk
Subversion Repositories usb_dongle_fpga
Compare Revisions
- This comparison shows the changes necessary to convert path
/usb_dongle_fpga/tags/version_1_4/sw
- from Rev 21 to Rev 53
- ↔ Reverse comparison
Rev 21 → Rev 53
/dongle.py
0,0 → 1,708
#! /usr/bin/python |
# -*- coding: ISO-8859-1 -*- |
|
########################################################################## |
# LPC Dongle programming software |
# |
# Copyright (C) 2006 Artec Design |
# |
# This library is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This software is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
|
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the Free Software |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
########################################################################## |
|
#------------------------------------------------------------------------- |
# Project: LPC Dongle programming software |
# Name: dongle.py |
# Purpose: Executable command line tool |
# |
|
# Copyright: (c) 2006 by Artec Design |
# Licence: LGPL |
# |
# Created: 06 Oct. 2006 |
# History: 12 oct. 2006 Version 1.0 released |
# 22 Feb. 2007 Test options added to test PCB board |
# 14 Nov. 2007 Moved dongle spesific code to class Dongle from USPP |
# USPP is allmost standard now (standard USPP would work) |
# Artec USPP has serial open retry |
# 14 Nov. 2007 Improved help. |
#------------------------------------------------------------------------- |
|
import os |
import sys |
import string |
import time |
from sets import * |
from struct import * |
from Uspp.uspp import * |
|
#### global funcs #### |
def usage(s): |
print "Artec USB Dongle programming utility ver. 2.0" |
print "Usage:" |
print "Write file : ",s," [-vq] -c <name> <file> <offset>" |
print "Readback file : ",s," [-vq] -c <name> [-vq] -r <offset> <length> <file>" |
print "Options:" |
print " <file> <offset> When file and offset are given file will be written to dongle" |
print " file: File name to be written to dongle" |
print " offset: Specifies data writing starting point in bytes to 4M window" |
print " For ThinCan boot code the offset = 4M - filesize. To write" |
print " 256K file the offset must be 3840K" |
print " " |
print " -c <name> Indicate port name where the USB Serial Device is" |
print " name: COM port name in Windows or Linux Examples: COM3,/dev/ttyS3" |
print " See Device Manager in windows for USB Serial Port number" |
print " " |
print " -v Enable verbose mode. Displays more progress information" |
print " " |
print " -q Perform flash query to see if dongle flash is responding" |
print " " |
print " -r <offset> <length> <file> Readback data. Available window size is 4MB" |
print " offset: Hexademical offset byte addres inside 4MB window" |
print " length: Amount in bytes to read starting from offset. Example: 1M" |
print " use M for MegaBytes, K for KiloBytes, none for bytes" |
print " file: Filename where data will be written" |
print " " |
print " -e Erase device. Erases Full 4 MegaBytes" |
print "Board test options: " |
print " -t Marching one and zero test. Device must be empty" |
print " To test dongle erase the flash with command -e" |
print " Enables dongle memory tests to be executed by user" |
print " " |
print " -b Leave flash blanc after test. Used with option -t" |
print "" |
print "Examples:" |
print "" |
print " ",s," -c COM3 loader.bin 0 " |
print " ",s," -c /dev/ttyS3 boot.bin 3840K" |
print " ",s," -c COM3 -r 0x3C0000 256K flashcontent.bin" |
###################### |
|
|
class DongleMode: |
def __init__(self): |
self.v = 0 |
self.f = 0 |
self.d = 0 |
self.q = 0 |
self.r = 0 |
self.t = 0 |
self.e = 0 |
self.b = 0 |
self.filename="" |
self.portname="" |
self.address=-1 |
self.offset=-1 |
self.length=-1 |
|
def convParamStr(self,param): |
mult = 1 |
value = 0 |
str = param |
if str.find("K")>-1: |
mult = 1024 |
str=str.strip("K") |
if str.find("M")>-1: |
mult = 1024*1024 |
str=str.strip("M") |
try: |
if str.find("x")>-1: |
value = int(str,0)*mult #conver hex string to int |
else: |
value = int(str)*mult #conver demical string to int |
except ValueError: |
print "Bad parameter format given for: ",param |
|
return value |
|
|
|
|
class Dongle: |
def __init__(self,name, baud, timeout): #time out in millis 1000 = 1s baud like 9600, 57600 |
try: |
self.tty = SerialPort(name,timeout, baud) |
except SerialPortException , e: |
print "Unable to open port " + name |
sys.exit(); |
|
def testReturn(self,byteCount): |
i=0 |
while don.tty.inWaiting()<byteCount: |
i=i+1 |
if i==10000*byteCount: |
break |
if i==10000*byteCount: |
return 0 |
return don.tty.inWaiting() ## ret two bytes |
|
def getReturn(self,byteCount): |
i=0 |
while don.tty.inWaiting()<byteCount: |
i=i+1 |
if i==10000*byteCount: |
break |
if i==10000*byteCount: |
print "Dongle not communicating" |
sys.exit() |
return don.tty.read(byteCount) ## ret two bytes |
|
|
def write_command(self,command): |
lsb = command&0xff |
msb = (command>>8)&0xff |
self.write_2bytes(msb,lsb) |
|
def write_2bytes(self, msb,lsb): |
"""Write one word MSB,LSB to the serial port MSB first""" |
s = pack('BB', msb, lsb) |
self.tty.write(s) |
# Wait for the write to complete |
#WaitForSingleObject(overlapped.hEvent, INFINITE) |
|
def get_address_buf(self,address): #set word address |
lsbyte = address&0xff |
byte = (address>>8)&0xff |
msbyte = (address>>16)&0xff |
buffer = "" |
buffer += chr(lsbyte) |
buffer += chr(0xA0) |
buffer += chr(byte) |
buffer += chr(0xA1) |
buffer += chr(msbyte) |
buffer += chr(0xA2) |
evaluate = (address>>24) |
if evaluate != 0: |
print "Addressign fault. Too large address passed" |
sys.exit() |
return buffer |
|
|
def set_address(self,address): #set word address |
lsbyte = address&0xff |
byte = (address>>8)&0xff |
msbyte = (address>>16)&0xff |
evaluate = (address>>24) |
if evaluate != 0: |
print "Addressign fault. Too large address passed" |
sys.exit() |
self.write_2bytes(lsbyte,0xA0) #set internal address to dongle |
self.write_2bytes(byte,0xA1) #set internal address to dongle |
self.write_2bytes(msbyte,0xA2) #send query command |
|
def read_data(self,wordCount,address): |
command = 0 |
byteCount = wordCount<<1 #calc byte count |
if wordCount>0 : |
command = (command|wordCount)<<8; |
command = command|0xCD |
self.set_address(address) # send read address |
self.write_command(command) # send get data command |
return self.getReturn(byteCount) |
else: |
print "Word count can't be under 1" |
sys.exit() |
|
def read_status(self): |
don.write_command(0x0070) # 0x0098 //clear status |
command = 0 |
wordCount= 1 #calc byte count |
byteCount = wordCount<<1 |
command = (command|wordCount)<<8; |
command = command|0xCD |
self.write_command(command) # send get data command |
return self.getReturn(byteCount) |
|
|
def get_block_no(self,address): |
return address >> 16 # 16 bit mode block is 64Kwords |
|
def wait_on_busy(self): |
exit=0 |
while exit==0: |
buf=self.read_status() |
statReg = ord(buf[0]) #8 bit reg |
if statReg>>7 == 1: |
exit=1 |
|
def parse_status(self): # use only after wait on busy commad to get result of the operation |
exit = 0 |
buf=self.read_status() |
statReg = ord(buf[0]) #8 bit reg |
if (statReg>>5)&1 == 1: |
print "Block erase suspended" |
exit = 1 |
if (statReg>>4)&3 == 3: |
print "Error in command order" #if bits 4 and 5 are set then |
exit = 1 |
if (statReg>>4)&3 == 1: |
print "Error in setting lock bit" |
exit = 1 |
if (statReg>>3)&1 == 1: |
print "Low Programming Voltage Detected, Operation Aborted" |
exit = 1 |
if (statReg>>2)&1 == 1: |
print "Programming suspended" |
exit = 1 |
if (statReg>>1)&1 == 1: |
print "Block lock bit detected" |
exit = 1 |
if exit == 1: |
sys.exit() |
|
def erase_block(self,blockNo): |
blockAddress = blockNo << 16 |
command = 0x0020 |
self.set_address(blockAddress) |
self.write_command(command) #issue block erase |
command = 0x00D0 |
self.write_command(command) #issue block erase confirm |
self.wait_on_busy() |
self.parse_status() |
|
def buffer_write(self,wordCount,startAddress,buffer): |
# to speed up buffer writing compose all commands into one buffer |
# instead of multiple single writes this is needed as the FTDI chip |
# round lag is amazingly large with VCOM drivers |
#u = len(buffer) |
if len(buffer)<32: #don't ever make unaligned writes |
i=len(buffer) |
while len(buffer)<32: |
buffer += "\xff" |
adrBuf = self.get_address_buf(startAddress) #6 bytes total |
cmd_e8="" #8 bytes total |
cmd_e8+= chr(16) #make it always 16 wordCount |
cmd_e8+= chr(0xE8) |
cmd_wcnt="" #10 bytes total |
cmd_wcnt+= chr(0x00) |
cmd_wcnt+= chr(16-1) |
cmd_buf="" #12 bytes total |
cmd_buf+= chr(0x00) |
cmd_buf+= chr(0xD0) |
wr_buffer_cmd = adrBuf + cmd_e8 + cmd_wcnt + buffer + cmd_buf #44 bytes total |
self.write_buf_cmd(wr_buffer_cmd) |
# no wait needad as the FTDI chip is so slow |
|
def write_buf_cmd(self, buffer): |
"""Write one word MSB,LSB to the serial port MSB first""" |
a=0 |
s="" |
if (len(buffer) < 44): # if buffer is shorter than expected then pad with read array mode commands |
i=0 |
while i<len(buffer): |
print '0x%02x'%(ord(buffer[i])) |
i+=1 |
while(a < len(buffer)): |
if a < 10: |
s= pack('2c', buffer[a], buffer[a+1]) |
self.tty.write(s) |
elif a < len(buffer)-2: |
s= pack('2c', buffer[a+1], buffer[a]) |
self.tty.write(s) |
elif len(buffer)==2: |
s=pack('2c', buffer[a], buffer[a+1]) |
self.tty.write(s) |
else: |
s=pack('2c', buffer[a], chr(0xFF)) |
self.tty.write(s) |
a+=2 |
else: |
#first 10 bytes are in correct order + 32 data bytes are in wrong order and + 2 confirm bytes are in correct order |
s=pack('44c', |
buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], |
buffer[8], buffer[9], buffer[11], buffer[10], buffer[13], buffer[12], buffer[15], buffer[14], |
buffer[17], buffer[16], buffer[19], buffer[18], buffer[21], buffer[20], buffer[23], buffer[22], |
buffer[25], buffer[24], buffer[27], buffer[26], buffer[29], buffer[28], buffer[31], buffer[30], |
buffer[33], buffer[32], buffer[35], buffer[34], buffer[37], buffer[36], buffer[39], buffer[38], |
buffer[41], buffer[40], buffer[42], buffer[43] |
) |
self.tty.write(s) |
|
# Wait for the write to complete |
#WaitForSingleObject(overlapped.hEvent, INFINITE) |
n = 0 |
if sys.platform=='win32': |
while (n < 1024): |
n += 1; |
elif sys.platform=='linux2': |
#Linux FTDI VCP driver is way faster and needs longer grace time than windows driver |
while (n < 1024*7): |
n += 1; |
|
|
################## Main program ######################### |
|
|
last_ops = 0 |
mode = DongleMode() |
# PARSE ARGUMENTS |
for arg in sys.argv: |
if len(sys.argv) == 1: # if no arguments display help |
#usage(sys.argv[0]) |
usage("dongle.py") |
sys.exit() |
if arg in ("-h","--help","/help","/h"): |
#usage(sys.argv[0]) |
usage("dongle.py") |
sys.exit() |
if arg in ("-c"): |
last_ops = sys.argv.index(arg) + 1 #if remains last set of options from here start ordered strings |
i = sys.argv.index(arg) |
print "Opening port: "+sys.argv[i+1] |
mode.portname = sys.argv[i+1] # next element after -c open port for usage |
if arg[0]=="-" and arg[1]!="c": # if other opptions |
# parse all options in this |
last_ops = sys.argv.index(arg) #if remains last set of options from here start ordered strings |
ops = arg[1:]# get all besides the - sign |
for op in ops: |
if op=="q": |
mode.q = 1 |
if op=="v": |
mode.v = 1 |
if op=="f": |
mode.f = 1 |
if op=="d": |
mode.d = 1 |
if op=="r": |
mode.r = 1 |
if op=="t": |
mode.t = 1 |
if op=="e": |
mode.e = 1 |
if op=="b": |
mode.b = 1 |
else: |
i = sys.argv.index(arg) |
if i == last_ops + 1: |
if mode.r==1: |
mode.offset=mode.convParamStr(arg) |
else: |
mode.filename=arg |
if i == last_ops + 2: |
if mode.r==1: |
mode.length=mode.convParamStr(arg) |
else: |
mode.address=mode.convParamStr(arg) |
|
if i == last_ops + 3: |
if mode.r==1: |
mode.filename=arg |
else: |
print "Too many parameters provided" |
sys.exit() |
if i > last_ops + 3: |
print "Too many parameters provided" |
sys.exit() |
|
# END PARSE ARGUMENTS |
|
if mode.portname=="": |
print "No port name given see -h for help" |
sys.exit() |
else: |
# test PC speed to find sutable delay for linux driver |
# to get 250 us |
mytime = time.clock() |
n = 0 |
while (n < 100000): |
n += 1; |
k10Time = time.clock() - mytime # time per 10000 while cycles |
wait = k10Time/100000.0 # time per while cycle |
wait = (0.00025/wait) * 1.20 # count for 250us + safe margin |
# ok done |
reopened = 0 |
|
don = Dongle(mode.portname,115200,100) |
don.tty.wait = wait |
while 1: |
don.write_command(0x0050) # 0x0098 |
don.write_command(0x00C5) #send dongle check internal command |
don_ret=don.testReturn(2) |
if don_ret==2: |
break |
if reopened == 3: |
print 'Dongle connected, but does not communicate' |
sys.exit() |
reopened = reopened + 1 |
# reopen and do new cycle |
don = Dongle(mode.portname,115200,100) |
don.tty.wait = wait |
|
buf=don.getReturn(2) # two bytes expected to this command |
|
if ord(buf[1])==0x32 and ord(buf[0])==0x10: |
print "Dongle OK" |
else: |
print 'Dongle returned on open: %02x %02x '%(ord(buf[1]), ord(buf[0])) |
|
|
if mode.q == 1: # perform a query from dongle |
|
buf=don.read_data(4,0x0) # word count and word address |
don.write_command(0x0050) # 0x0098 |
don.write_command(0x0098) # 0x0098 |
buf=don.read_data(3,0x000010) # word count and word address |
if ord(buf[0])==0x51 and ord(buf[2])==0x52 and ord(buf[4])==0x59: |
buf=don.read_data(2,0x000000) # word count and word address |
print 'Query OK, Factory: 0x%02x device: 0x%02x '%(ord(buf[0]),ord(buf[2])) |
buf=don.read_data(2,0x000002) |
print 'lock bit is 0x%02x 0x%02x'%(ord(buf[0]),ord(buf[1])) |
else: |
print "Got bad query data:" |
print 'Query address 0x10 = 0x%02x%02x '%(ord(buf[1]),ord(buf[0])) |
print 'Query address 0x12 = 0x%02x%02x '%(ord(buf[3]),ord(buf[2])) |
print 'Query address 0x14 = 0x%02x%02x '%(ord(buf[5]),ord(buf[4])) |
print "Read byte count:",len(buf) |
|
don.write_command(0x00FF) # 0x0098 |
buf=don.read_data(4,0xff57c0>>1) # word count and word address |
|
print 'Data: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x '%(ord(buf[1]),ord(buf[0]),ord(buf[3]),ord(buf[2]),ord(buf[5]),ord(buf[4]),ord(buf[7]),ord(buf[6]) ) |
|
|
|
if mode.filename!="" and mode.address!=-1: |
#Calculate number of blocks and start of blocks |
size = 0 |
mode.address = mode.address>>1 #make word address |
try: |
f=open(mode.filename,"rb") |
f.seek(0,2) #seek to end |
size = f.tell() |
f.seek(0) #seek to start |
print 'File size %iK '%(size/1024) |
f.close() |
except IOError: |
print "IO Error on file open" |
sys.exit() |
#clear blockLock bits |
don.write_command(0x0060) # 0x0098 |
don.write_command(0x00D0) # 0x0098 |
don.wait_on_busy() |
don.parse_status() |
wordSize = (size+ (size&1))>> 1 # round byte count up and make word address |
endBlock = don.get_block_no(mode.address+wordSize - 1) |
startBlock = don.get_block_no(mode.address) |
i=startBlock |
print 'Erasing from block %i to %i '%(i,endBlock) |
while i <= endBlock: |
if mode.v == 1: |
print 'Erasing block %i '%(i) |
else: |
sys.stdout.write(".") |
sys.stdout.flush() |
don.erase_block(i) |
don.wait_on_busy() |
don.parse_status() #do this after programming all but uneaven ending |
i=i+1 |
if mode.v == 0: |
print " " |
#don.write_command(0x00FF) # 0x0098 |
#buf=don.read_data(4,0x000000) # word count and word address |
#print 'Data: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x '%(ord(buf[0]),ord(buf[1]),ord(buf[2]),ord(buf[3]),ord(buf[4]),ord(buf[5]),ord(buf[6]),ord(buf[7]) ) |
|
f=open(mode.filename,"rb") |
f.seek(0) #seek to start |
address= mode.address |
#don.set_address(address) |
print 'Writing %iK'%(size/1024) |
while 1: |
if (address/(1024*64) != (address-16)/(1024*64)) and address != mode.address: # get bytes from words if 512 |
if mode.v == 1: |
print 'Progress: %iK of %iK at 0x%06x'%((address-mode.address)/512,size/1024,address) |
else: |
sys.stdout.write(".") |
sys.stdout.flush() |
buf = f.read(32) #16 words is maximum write here bytes are read |
if len(buf)==32: |
don.buffer_write(16,address,buf) |
address = address + 16 |
elif len(buf)>0: |
don.parse_status() #do this after programming all but uneaven ending |
print "Doing an unaligned write..." |
length = len(buf) |
length = (length + (length&1))>> 1 #round up to get even word count |
buf = buf+"\xff" #pad just in case rounding took place |
don.buffer_write(len,address,buf) |
address = address + 16 #inc word address |
break |
else: |
break |
if mode.v == 0: |
print " " |
print "Write DONE!" |
don.parse_status() #do this after programming all but uneaven ending |
f.close() |
|
if mode.r == 1: # perform a readback |
if mode.offset!=-1 and mode.length!=-1 and mode.filename!="": |
mode.offset=mode.offset>>1 #make word offset |
mode.length= mode.length>>1 #make word length |
print 'Reading %iK'%(mode.length/512) |
try: |
f=open(mode.filename,"wb") |
don.write_command(0x00FF) # put flash to data read mode |
address = mode.offset # set word address |
while 1: |
if address/(1024*32) != (address-128)/(1024*32): # get K bytes from words if 512 |
if mode.v == 1: |
print 'Progress: %iK of %iK'%((address-mode.offset)/512,mode.length/512) |
else: |
sys.stdout.write(".") |
sys.stdout.flush() |
buf=don.read_data(128,address) # word count and byte address read 64 words to speed up |
f.write(buf) |
#print "from address:",address<<1," ", len(buf) |
if address+128 >= (mode.offset + mode.length): # 2+64 estimates the end to end in right place |
break |
address = address + 128 #this is word address |
f.close() |
if mode.v == 0: |
print " " |
print "Readback done!" |
except IOError: |
print "IO Error on file open" |
sys.exit() |
|
else: |
print "Some of readback parameters missing..." |
print mode.offset,mode.length, mode.filename |
sys.exit() |
|
if mode.t == 1: # perform dongle test |
print "Dongle TEST" |
if mode.e == 1: |
#Erase Dongle |
print "Erasing" |
don.write_command(0x0060) # 0x0098 |
don.write_command(0x00D0) # 0x0098 |
don.wait_on_busy() |
don.parse_status() |
endBlock = 31 |
startBlock = 0 |
i=startBlock |
while i <= endBlock: |
if mode.v == 1: |
print 'Erasing block %i '%(i) |
else: |
sys.stdout.write(".") |
sys.stdout.flush() |
don.erase_block(i) |
don.wait_on_busy() |
don.parse_status() #do this after programming all but uneaven ending |
i=i+1 |
if mode.v == 0: # add CRTL return to dots |
print "" |
#Do marching one test on data and address |
mode.length= 0 #make word length |
try: |
#Marching one test |
#--------------------------------------------------------------------------- |
address = 0x100000 # set word address |
data = 0x100000 |
while mode.length<20: # last address to test 0x20 0000 |
buf1=pack('BBBB', (0x000000FF&data),(0x0000FF00&data)>>8 ,(0x00FF0000&data)>>16 ,(0xFF0000&data)>>24 ) |
don.buffer_write(2,address,buf1) |
don.parse_status() #do this after programming all but uneaven ending |
don.write_command(0x00FF) # put flash to data read mode |
buf2=don.read_data(2,address) # word count and byte address read 64 words to speed up |
if buf1 != buf2: |
print 'IN %02x %02x %02x %02x '%(ord(buf1[3]), ord(buf1[2]),ord(buf1[1]), ord(buf1[0])) |
print 'OUT %02x %02x %02x %02x '%(ord(buf2[3]), ord(buf2[2]),ord(buf2[1]), ord(buf2[0])) |
print "Test FAIL!!!!!" |
sys.exit() |
address = address >> 1 |
if address == 0x2: |
address = address >> 1 # 0x2 is written and will return zero on read as write new write will fail |
data = data >> 1 |
mode.length = mode.length + 1 |
buf2=don.read_data(1,0) #read first byte |
if ord(buf2[0]) != 0xFF: |
print "Test FAIL (At least one address line const. 0)!!!!!" |
sys.exit() |
#----------------------------------------------------------------------- |
#Marching zero test |
address = 0xFFEFFFFF # set word address |
data = 0x100000 |
while mode.length<18: # last address to test 0x20 0000 |
buf1=pack('BBBB', (0x000000FF&data),(0x0000FF00&data)>>8 ,(0x00FF0000&data)>>16 ,(0xFF0000&data)>>24 ) |
don.buffer_write(2,address,buf1) |
don.parse_status() #do this after programming all but uneaven ending |
don.write_command(0x00FF) # put flash to data read mode |
buf2=don.read_data(2,address&0x1FFFFF) # word count and byte address read 64 words to speed up |
if buf1 != buf2: |
print 'IN %02x %02x %02x %02x '%(ord(buf1[3]), ord(buf1[2]),ord(buf1[1]), ord(buf1[0])) |
print 'OUT %02x %02x %02x %02x '%(ord(buf2[3]), ord(buf2[2]),ord(buf2[1]), ord(buf2[0])) |
print "Test FAIL!!!!!" |
sys.exit() |
address = (address >> 1)|0xFF000000 |
data = data >> 1 |
mode.length = mode.length + 1 |
buf2=don.read_data(1,0x1FFFFF) #read first byte |
if ord(buf2[0]) != 0xFF: |
print "Test FAIL (At least two address lines bonded)!!!!!" |
sys.exit() |
if mode.b == 1: |
#Erase Dongle |
print "Erasing" |
don.write_command(0x0060) # 0x0098 |
don.write_command(0x00D0) # 0x0098 |
don.wait_on_busy() |
don.parse_status() |
endBlock = 31 |
startBlock = 0 |
i=startBlock |
while i <= endBlock: |
if mode.v == 1: |
print 'Blanking block %i '%(i) |
else: |
sys.stdout.write(".") |
sys.stdout.flush() |
don.erase_block(i) |
don.wait_on_busy() |
don.parse_status() #do this after programming all but uneaven ending |
i=i+1 |
if mode.v == 0: |
print " " |
print "Test SUCCESSFUL!" |
sys.exit() |
except IOError: |
print "IO Error on file open" |
sys.exit() |
|
if mode.e == 1: # perform dongle test |
#Erase Dongle |
print "Erasing all" |
don.write_command(0x0060) # 0x0098 |
don.write_command(0x00D0) # 0x0098 |
don.wait_on_busy() |
don.parse_status() |
endBlock = 31 |
startBlock = 0 |
i=startBlock |
while i <= endBlock: |
if mode.v == 1: |
print 'Erasing block %i '%(i) |
else: |
sys.stdout.write(".") |
sys.stdout.flush() |
don.erase_block(i) |
don.wait_on_busy() |
don.parse_status() #do this after programming all but uneaven ending |
i=i+1 |
if mode.v == 0: # add CRTL return to dots |
print "" |
print "Erase done." |
|
########################################################## |
/Uspp/SerialPort_win.py
0,0 → 1,255
# -*- coding: ISO-8859-1 -*- |
|
########################################################################## |
# USPP Library (Universal Serial Port Python Library) |
# |
# Copyright (C) 2006 Isaac Barona <ibarona@gmail.com> |
# |
# This library is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This library is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
|
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the Free Software |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
########################################################################## |
|
#------------------------------------------------------------------------- |
# Project: USPP Library (Universal Serial Port Python Library) |
# Name: SerialPort_win.py |
# Purpose: Handle low level access to serial port in windows. |
# |
# Author: Isaac Barona Martinez <ibarona@gmail.com> |
|
# Licence: LGPL |
# |
# Created: 26 June 2001 |
# History: |
|
# Bug fix for Win2000, the file must not be open with |
# FILE_FLAG_OVERLAPPED |
# |
#------------------------------------------------------------------------- |
|
""" |
SerialPort_win.py - Handle low level access to serial port in windows. |
|
See also uspp module docstring. |
|
""" |
|
from win32file import * |
from win32event import * |
import win32con |
import exceptions |
|
class SerialPortException(exceptions.Exception): |
"""Exception raise in the SerialPort methods""" |
def __init__(self, args=None): |
self.args=args |
def __str__(self): |
return repr(self.args) |
|
class SerialPort: |
"""Encapsulate methods for accesing to a serial port.""" |
|
BaudRatesDic={110: CBR_110, |
300: CBR_300, |
600: CBR_600, |
1200: CBR_1200, |
2400: CBR_2400, |
4800: CBR_4800, |
9600: CBR_9600, |
19200: CBR_19200, |
38400: CBR_38400, |
57600: CBR_57600, |
115200: CBR_115200 |
} |
|
def __init__(self, dev, timeout=None, speed=115200, mode='232', params=None): |
"""Open the serial port named by the string 'dev' |
|
'dev' can be any of the following strings: 'COM1', 'COM2', ... 'COMX' |
|
'timeout' specifies the inter-byte timeout or first byte timeout |
(in miliseconds) for all subsequent reads on SerialPort. |
If we specify None time-outs are not used for reading operations |
(blocking reading). |
If 'timeout' is 0 then reading operations are non-blocking. It |
specifies that the reading operation is to return inmediately |
with the bytes that have already been received, even if |
no bytes have been received. |
|
'speed' is an integer that specifies the input and output baud rate to |
use. Possible values are: 110, 300, 600, 1200, 2400, 4800, 9600, |
19200, 38400, 57600 and 115200. |
If None a default speed of 9600 bps is selected. |
|
'mode' specifies if we are using RS-232 or RS-485. The RS-485 mode |
is half duplex and use the RTS signal to indicate the |
direction of the communication (transmit or recive). |
Default to RS232 mode (at moment, only the RS-232 mode is |
implemented). |
|
'params' is a list that specifies properties of the serial |
communication. |
If params=None it uses default values for the number of bits |
per byte (8), the parity (NOPARITY) and the number of stop bits (1) |
else params must be a list with three items setting up the |
these values in this order. |
|
""" |
|
self.__devName, self.__timeout, self.__speed=dev, timeout, speed |
self.__mode=mode |
self.__params=params |
self.__speed = 0 |
self.__reopen = 0 |
while 1: |
try: |
self.__handle=CreateFile (dev, |
win32con.GENERIC_READ|win32con.GENERIC_WRITE, |
0, # exclusive access |
None, # no security |
win32con.OPEN_EXISTING, |
win32con.FILE_ATTRIBUTE_NORMAL, |
None) |
break |
|
except: |
n=0 |
while (n < 2000000): |
n += 1; |
self.__reopen = self.__reopen + 1 |
if self.__reopen > 32: |
print "Port does not exist..." |
raise SerialPortException('Port does not exist...') |
break |
#sys.exit() |
self.__configure() |
|
def __del__(self): |
"""Close the serial port |
|
To close the serial port we have to do explicity: del s |
(where s is an instance of SerialPort) |
""" |
if self.__speed: |
try: |
CloseHandle(self.__handle) |
except: |
raise SerialPortException('Unable to close port') |
|
|
|
|
def __configure(self): |
"""Configure the serial port. |
|
Private method called in the class constructor that configure the |
serial port with the characteristics given in the constructor. |
""" |
if not self.__speed: |
self.__speed=115200 |
# Tell the port we want a notification on each char |
SetCommMask(self.__handle, EV_RXCHAR) |
# Setup a 4k buffer |
SetupComm(self.__handle, 4096, 4096) |
# Remove anything that was there |
PurgeComm(self.__handle, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR| |
PURGE_RXCLEAR) |
|
# Setup the timeouts parameters for the port |
# timeouts is a tuple with the following items: |
# [0] int : ReadIntervalTimeout |
# [1] int : ReadTotalTimeoutMultiplier |
# [2] int : ReadTotalTimeoutConstant |
# [3] int : WriteTotalTimeoutMultiplier |
# [4] int : WriteTotalTimeoutConstant |
|
if self.__timeout==None: |
timeouts= 0, 0, 0, 0, 0 |
elif self.__timeout==0: |
timeouts = win32con.MAXDWORD, 0, 0, 0, 1000 |
else: |
timeouts= self.__timeout, 0, self.__timeout, 0 , 1000 |
SetCommTimeouts(self.__handle, timeouts) |
|
# Setup the connection info |
dcb=GetCommState(self.__handle) |
dcb.BaudRate=SerialPort.BaudRatesDic[self.__speed] |
if not self.__params: |
dcb.ByteSize=8 |
dcb.Parity=NOPARITY |
dcb.StopBits=ONESTOPBIT |
else: |
dcb.ByteSize, dcb.Parity, dcb.StopBits=self.__params |
SetCommState(self.__handle, dcb) |
|
|
def fileno(self): |
"""Return the file descriptor for opened device. |
|
This information can be used for example with the |
select function. |
""" |
return self.__handle |
|
|
def read(self, num=1): |
"""Read num bytes from the serial port. |
|
If self.__timeout!=0 and != None and the number of read bytes is less |
than num an exception is generated because a timeout has expired. |
If self.__timeout==0 read is non-blocking and inmediately returns |
up to num bytes that have previously been received. |
""" |
|
(Br, buff) = ReadFile(self.__handle, num) |
if len(buff)<>num and self.__timeout!=0: # Time-out |
raise SerialPortException('Timeout') |
else: |
return buff |
|
|
def readline(self): |
"""Read a line from the serial port. Returns input once a '\n' |
character is found. |
|
""" |
|
s = '' |
while not '\n' in s: |
s = s+SerialPort.read(self,1) |
|
return s |
|
|
def write(self, s): |
"""Write the string s to the serial port""" |
overlapped=OVERLAPPED() |
overlapped.hEvent=CreateEvent(None, 0,0, None) |
WriteFile(self.__handle, s, overlapped) |
# Wait for the write to complete |
WaitForSingleObject(overlapped.hEvent, INFINITE) |
|
def inWaiting(self): |
"""Returns the number of bytes waiting to be read""" |
flags, comstat = ClearCommError(self.__handle) |
return comstat.cbInQue |
|
def flush(self): |
"""Discards all bytes from the output or input buffer""" |
PurgeComm(self.__handle, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR| |
PURGE_RXCLEAR) |
|
|
|
|
|
/Uspp/SerialPort_linux.py
0,0 → 1,343
# -*- coding: ISO-8859-1 -*- |
|
########################################################################## |
# USPP Library (Universal Serial Port Python Library) |
# |
# Copyright (C) 2006 Isaac Barona <ibarona@gmail.com> |
# |
# This library is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This library is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
|
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the Free Software |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
########################################################################## |
|
#------------------------------------------------------------------------ |
# Project: USPP Library (Universal Serial Port Python Library) |
# Name: SerialPort_linux.py |
# Purpose: Handle low level access to serial port in linux. |
# |
# Author: Isaac Barona Martinez <ibarona@gmail.com> |
|
# Licence: LGPL |
# |
# Created: 26 June 2001 |
# History: |
# 20 January 2002 : Damien Geranton <dgeranton@voila.fr> |
# - NCCS worry fixed. We must not use TERMIOS |
# - inWaiting call fixed. |
# 09 Sept 2005: Douglas Jones <dfj23@drexel.edu> |
# - readline method. |
# |
#------------------------------------------------------------------------- |
|
""" |
SerialPort_linux.py - Handle low level access to serial port in linux. |
|
See also uspp module docstring. |
|
|
""" |
|
import os |
from termios import * |
from struct import * |
import fcntl |
import exceptions |
import struct |
import array |
import time |
|
|
class SerialPortException(exceptions.Exception): |
"""Exception raise in the SerialPort methods""" |
def __init__(self, args=None): |
self.args=args |
def __str__(self): |
return repr(self.args) |
|
class SerialPort: |
"""Encapsulate methods for accesing to a serial port.""" |
|
BaudRatesDic={ |
110: B110, |
300: B300, |
600: B600, |
1200: B1200, |
2400: B2400, |
4800: B4800, |
9600: B9600, |
19200: B19200, |
38400: B38400, |
57600: B57600, |
115200: B115200 |
} |
buf = array.array('h', '\000'*4) |
|
def __init__(self, dev, timeout=None, speed=115200, mode='232', params=None): |
"""Open the serial port named by the string 'dev' |
|
'dev' can be any of the following strings: '/dev/ttyS0', '/dev/ttyS1', |
..., '/dev/ttySX' or '/dev/cua0', '/dev/cua1', ..., '/dev/cuaX'. |
|
'timeout' specifies the inter-byte timeout or first byte timeout |
(in miliseconds) for all subsequent reads on SerialPort. |
If we specify None time-outs are not used for reading operations |
(blocking reading). |
If 'timeout' is 0 then reading operations are non-blocking. It |
specifies that the reading operation is to return inmediately |
with the bytes that have already been received, even if |
no bytes have been received. |
|
'speed' is an integer that specifies the input and output baud rate to |
use. Possible values are: 110, 300, 600, 1200, 2400, 4800, 9600, |
19200, 38400, 57600 and 115200. |
If None a default speed of 9600 bps is selected. |
|
'mode' specifies if we are using RS-232 or RS-485. The RS-485 mode |
is half duplex and use the RTS signal to indicate the |
direction of the communication (transmit or recive). |
Default to RS232 mode (at moment, only the RS-232 mode is |
implemented). |
|
'params' is a list that specifies properties of the serial |
communication. |
If params=None it uses default values for the number of bits |
per byte (8), the parity (NOPARITY) and the number of stop bits (1) |
else params is the termios package mode array to use for |
initialization. |
|
""" |
|
self.__devName, self.__timeout, self.__speed=dev, timeout, speed |
self.__mode=mode |
self.__params=params |
self.__speed = 0 |
self.__reopen = 0 |
while 1: |
try: |
self.__handle=os.open(dev, os.O_RDWR) |
break |
|
except: |
n=0 |
while (n < 2000000): |
n += 1; |
self.__reopen = self.__reopen + 1 |
if self.__reopen > 32: |
print "Port does not exist..." |
raise SerialPortException('Port does not exist...') |
break |
|
self.__configure() |
|
def __del__(self): |
"""Close the serial port and restore its initial configuration |
|
To close the serial port we have to do explicity: del s |
(where s is an instance of SerialPort) |
""" |
if self.__speed: |
tcsetattr(self.__handle, TCSANOW, self.__oldmode) |
try: |
os.close(self.__handle) |
except IOError: |
raise SerialPortException('Unable to close port') |
|
|
def __configure(self): |
"""Configure the serial port. |
|
Private method called in the class constructor that configure the |
serial port with the characteristics given in the constructor. |
""" |
if not self.__speed: |
self.__speed=115200 |
|
# Save the initial port configuration |
self.__oldmode=tcgetattr(self.__handle) |
if not self.__params: |
# self.__params is a list of attributes of the file descriptor |
# self.__handle as follows: |
# [c_iflag, c_oflag, c_cflag, c_lflag, c_ispeed, c_ospeed, cc] |
# where cc is a list of the tty special characters. |
self.__params=[] |
# c_iflag |
self.__params.append(IGNPAR) |
# c_oflag |
self.__params.append(0) |
# c_cflag |
self.__params.append(CS8|CLOCAL|CREAD) |
# c_lflag |
self.__params.append(0) |
# c_ispeed |
self.__params.append(SerialPort.BaudRatesDic[self.__speed]) |
# c_ospeed |
self.__params.append(SerialPort.BaudRatesDic[self.__speed]) |
cc=[0]*NCCS |
if self.__timeout==None: |
# A reading is only complete when VMIN characters have |
# been received (blocking reading) |
cc[VMIN]=1 |
cc[VTIME]=0 |
elif self.__timeout==0: |
# Non-blocking reading. The reading operation returns |
# inmeditately, returning the characters waiting to |
# be read. |
cc[VMIN]=0 |
cc[VTIME]=0 |
else: |
# Time-out reading. For a reading to be correct |
# a character must be recieved in VTIME*100 seconds. |
cc[VMIN]=0 |
cc[VTIME]=self.__timeout/100 |
self.__params.append(cc) # c_cc |
|
tcsetattr(self.__handle, TCSANOW, self.__params) |
|
|
def fileno(self): |
"""Return the file descriptor for opened device. |
|
This information can be used for example with the |
select funcion. |
""" |
return self.__handle |
|
|
def __read1(self): |
"""Read 1 byte from the serial port. |
|
Generate an exception if no byte is read and self.timeout!=0 |
because a timeout has expired. |
""" |
byte = os.read(self.__handle, 1) |
if len(byte)==0 and self.__timeout!=0: # Time-out |
raise SerialPortException('Timeout') |
else: |
return byte |
|
|
def read(self, num=1): |
"""Read num bytes from the serial port. |
|
Uses the private method __read1 to read num bytes. If an exception |
is generated in any of the calls to __read1 the exception is reraised. |
""" |
s='' |
for i in range(num): |
s=s+SerialPort.__read1(self) |
|
return s |
|
|
def readline(self): |
"""Read a line from the serial port. Returns input once a '\n' |
character is found. |
Douglas Jones (dfj23@drexel.edu) 09/09/2005. |
""" |
|
s = '' |
while not '\n' in s: |
s = s+SerialPort.__read1(self) |
|
return s |
|
|
def write(self, s): |
"""Write the string s to the serial port""" |
|
os.write(self.__handle, s) |
|
def inWaiting(self): |
"""Returns the number of bytes waiting to be read""" |
data = struct.pack("L", 0) |
data=fcntl.ioctl(self.__handle, TIOCINQ, data) |
return struct.unpack("L", data)[0] |
|
def outWaiting(self): |
"""Returns the number of bytes waiting to be write |
mod. by J.Grauheding |
result needs some finetunning |
""" |
rbuf=fcntl.ioctl(self.__handle, TIOCOUTQ, self.buf) |
return rbuf |
|
def getlsr(self): |
"""Returns the status of the UART LSR Register |
J.Grauheding |
""" |
rbuf=fcntl.ioctl(self.__handle, TIOCSERGETLSR, self.buf) |
return ord(rbuf[0]) |
|
def get_temt(self): |
"""Returns the Tranmitterbuffer Empty Bit of LSR Register |
J.Grauheding |
test result against TIOCSER_TEMT |
""" |
rbuf=fcntl.ioctl(self.__handle, TIOCSERGETLSR, self.buf) |
return ord(rbuf[0]) & TIOSER_TEMT |
|
|
def flush(self): |
"""Discards all bytes from the output or input buffer""" |
tcflush(self.__handle, TCIOFLUSH) |
|
def rts_on(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, TIOCMGET, SerialPort.buf) |
SerialPort.buf[1] = ord(rbuf[3]) | TIOCM_RTS |
rbuf = fcntl.ioctl(self.__handle, TIOCMSET, SerialPort.buf) |
return rbuf |
|
def rts_off(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, TIOCMGET, self.buf) |
self.buf[1]=ord(rbuf[3]) & ~TIOCM_RTS |
rbuf = fcntl.ioctl(self.__handle, TIOCMSET, self.buf) |
return rbuf |
|
def dtr_on(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, TIOCMGET, SerialPort.buf) |
SerialPort.buf[1] = ord(rbuf[3]) | TIOCM_DTR |
rbuf = fcntl.ioctl(self.__handle, TIOCMSET, SerialPort.buf) |
return rbuf |
|
def dtr_off(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, TIOCMGET, self.buf) |
self.buf[1]=ord(rbuf[3]) & ~TIOCM_DTR |
rbuf = fcntl.ioctl(self.__handle, TIOCMSET, self.buf) |
return rbuf |
|
def cts(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, TIOCMGET, self.buf) |
return ord(rbuf[3]) & TIOCM_CTS |
|
def cd(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, TIOCMGET, self.buf) |
return ord(rbuf[3]) & TIOCM_CAR |
|
def dsr(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, TIOCMGET, self.buf) |
return ord(rbuf[2]) & (TIOCM_DSR>>8) |
|
def ri(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, TIOCMGET, self.buf) |
return ord(rbuf[3]) & TIOCM_RNG |
|
|
|
/Uspp/uspp.py
0,0 → 1,216
#! /usr/bin/env python |
# -*- coding: ISO-8859-1 -*- |
|
|
########################################################################## |
# USPP Library (Universal Serial Port Python Library) |
# |
# Copyright (C) 2006 Isaac Barona <ibarona@gmail.com> |
# |
# This library is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This library is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
|
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the Free Software |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
########################################################################## |
|
#------------------------------------------------------------------------- |
# Project: USPP Library (Universal Serial Port Python Library) |
# Name: uspp.py |
# Purpose: Main module. Imports the correct module for the platform |
# in which it is running. |
# |
# Author: Isaac Barona Martinez <ibarona@gmail.com> |
# Copyright: (c) 2006 by Isaac Barona Martinez |
# Licence: LGPL |
# |
# Created: 26 June 2001 |
# History: |
# 05/08/2001: Release version 0.1. |
# 24/02/2006: Final version 1.0. |
# |
#------------------------------------------------------------------------- |
|
|
""" |
USPP - Universal Serial Port Python Library |
|
This module exports a SerialPort class to access serial ports in |
different platforms (currently W9X and Linux) with the same code. |
|
When the library user import the uspp module, it automatically |
loads the correct class implementation for the platform in which |
is running. |
|
The public classes, exceptions and methods are the following: |
|
SerialPortException |
=================== |
Exception raised in the SerialPort methods. |
|
|
SerialPort |
========== |
Class that encapsulate methods to access serial ports. It has the |
following public methods: |
|
* __init__(self, dev, timeout=None, speed=None, mode='232', params=None) |
|
Create an object to access serial port 'dev' |
|
Arguments: |
|
dev: String that indicate the name of the port. Possible values are: |
In Linux: '/dev/ttyS0', '/dev/ttyS1', ..., '/dev/ttySX' or |
'/dev/cua0', '/dev/cua1', ..., '/dev/cuaX' |
In W9X: 'COM1', 'COM2', ..., 'COMX' |
|
timeout: specifies in milliseconds the inter-byte timeout. Possible |
values are: |
* None: For blocking readings. Time-outs are not used for reading |
operations. |
* 0: For non-blocking readings. The reading operation is to return |
inmediately with the characters that have already been received, |
even if no characters have been received. |
* >0: For time-out readings. A character must be read in less than |
this value. |
|
speed: integer that specifies the input and output baud rate to |
use. Possible values are: 110, 300, 600, 1200, 2400, 4800, 9600, |
19200, 38400, 57600 and 115200. |
If None a default speed of 9600 bps is selected. |
|
mode: string that specifies RS-232 or RS-485 mode. The RS-485 mode |
is half duplex and use the RTS signal to indicate the |
direction of the communication (transmit or recive). |
Posible values are: '232' or '485'. Default to RS232 mode (the |
only implemented just now). |
|
params: list that specifies properties of the serial communication. |
If params=None it uses default values for the number of bits |
per byte (8), the parity (NOPARITY) and the number of stop bits (1) |
else: |
* In W9X: params must be a list with three items setting up the |
these values in this order. |
* In Linux: params must is the termios package mode array to use |
for initialization. |
|
|
|
* __del__(self): |
|
Destroy the SerialPort object and close the serial port. It is a good |
idea that when you finish working with the serial port you explicity |
do: del tty (where tty is a SerialPort object). |
|
* fileno(self): |
|
Returns the file descriptor of the serial port. This information is |
sometimes necessary for example if you want to use the select function. |
|
* read(self, num=1): |
|
Read num bytes from the serial port. Depending the timeout value used in |
the inicialitation this operation can be: |
|
- Blocking (if timeout=None): The operation blocks until num bytes |
arrive the serial port. |
- Non-blocking (if timeout=0): The operation returns inmediatelly |
with as many as num bytes that were waiting in the serial port to be read. |
- Time-out (if timeout>0): A byte must arrive in less milliseconds than |
the specified. If the number of read bytes is less than num a |
SerialPortException is raised because a time-out has happened. |
|
* write(self, s): |
|
Write the string s to the serial port. |
|
* inWaiting(self): |
|
Returns the number of bytes waiting to be read. |
|
|
* flush(self): |
|
Discards all characters from the output or input buffer. |
|
|
|
NOTE ON CHARACTERS AND BYTES |
============================ |
|
The write and read methods of the SerialPort class expect data |
in string buffers. Do not think this library only works for |
ASCII communications. To interpret string elements as bytes (integer number) |
you only have to use the built-in ord() function. To convert a byte |
into a string element, use chr(). |
|
Example: Suppose you want to transmit the following three bytes: |
0x02, 0x10, 0x30. You only have to do: |
|
packet = '' |
packet = packet + chr(0x02) + chr(0x10) + chr(0x30) |
tty.write(packet) |
|
So, you can see the bytes you send or receive as integers or as characters |
depending the situation. |
|
|
|
""" |
|
|
|
__author__="Isaac Barona Martinez <ibarona@tid.es>" |
|
__copyright__=""" |
Copyright (C) 2001 Isaac Barona Martinez <ibarona@tid.es> |
|
This library is free software; you can redistribute it and/or |
modify it under the terms of the GNU General Public License |
as published by the Free Software Foundation; version 2 dated |
June, 1991. |
""" |
|
__version__="0.1" |
|
|
import sys |
drv_ok = 0 |
if sys.platform=='win32': |
print "Windows platform detected:" |
#try: |
# import notworking_d2xx |
# from D2xxPort_win import * |
# print "Using D2xx FTDI driver" |
# drv_ok = 1 |
#except ImportError: |
# print "pyUSB for fast COM not found (see http://bleyer.org/pyusb/)" |
|
if drv_ok == 0: |
try: |
from win32file import * |
from win32event import * |
from SerialPort_win import * |
print "Using VCP FTDI driver" |
except ImportError,SerialPortException: |
print "Python for winiows extensions for COM not found" |
print "(see https://sourceforge.net/projects/pywin32/)" |
print "Could not find any usable support for FTDI chip in python" |
print "Try installing python support from one of the links." |
sys.exit() |
|
|
elif sys.platform=='linux2': |
print "Linux platform detected:" |
from SerialPort_linux import * |
else: |
sys.exit('Sorry, no implementation for this platform yet') |
/Uspp/SerialPort_darwin.py
0,0 → 1,326
########################################################################## |
# USPP Library (Universal Serial Port Python Library) |
# |
# Copyright (C) 2006 Isaac Barona <ibarona@gmail.com> |
# |
# This library is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; either |
# version 2.1 of the License, or (at your option) any later version. |
# |
# This library is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
|
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the Free Software |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
########################################################################## |
|
#------------------------------------------------------------------------- |
# Project: USPP Library (Universal Serial Port Python Library) |
# Name: SerialPort_darwin.py |
# Purpose: Handle low level access to serial port in MacOS. |
# |
# Author: Isaac Barona Martinez <ibarona@gmail.com> |
|
# Licence: LGPL |
# |
# Created: 26 June 2001 |
# History: 06.02.2003 Modified and extended by J.Grauheding |
# <juergen.grauheding@a-city.de> |
# adapt it for Python 2.2 on Mac OS X |
# Douglas Jones (dfj23@drexel.edu) |
# - readline method. |
# |
#------------------------------------------------------------------------- |
|
""" |
SerialPort_darwin.py - Handle low level access to serial port in Mac OS X. |
|
See also uspp module docstring. |
|
|
""" |
|
import os |
import tty |
import termios |
import array |
import fcntl |
import exceptions |
import string |
|
class SerialPortException(exceptions.Exception): |
"""Exception raise in the SerialPort methods""" |
def __init__(self, args=None): |
self.args=args |
|
|
class SerialPort: |
"""Encapsulate methods for accesing to a serial port.""" |
|
BaudRatesDic={ |
50: termios.B50, |
75: termios.B75, |
110: termios.B110, |
134: termios.B134, |
150: termios.B150, |
200: termios.B200, |
300: termios.B300, |
600: termios.B600, |
1200: termios.B1200, |
1800: termios.B1800, |
2400: termios.B2400, |
4800: termios.B4800, |
9600: termios.B9600, |
19200: termios.B19200, |
38400: termios.B38400, |
57600: termios.B57600, |
115200: termios.B115200, |
230400: termios.B230400 |
} |
buf = array.array('h', '\000'*4) |
|
def __init__(self, dev, timeout=None, speed=None, mode='232', params=None): |
"""Open the serial port named by the string 'dev' |
|
'dev' can be any of the following strings: '/dev/ttyS0', '/dev/ttyS1', |
..., '/dev/ttySX' or '/dev/cua0', '/dev/cua1', ..., '/dev/cuaX'. |
|
'timeout' specifies the inter-byte timeout or first byte timeout |
(in miliseconds) for all subsequent reads on SerialPort. |
If we specify None time-outs are not used for reading operations |
(blocking reading). |
If 'timeout' is 0 then reading operations are non-blocking. It |
specifies that the reading operation is to return inmediately |
with the bytes that have already been received, even if |
no bytes have been received. |
|
'speed' is an integer that specifies the input and output baud rate to |
use. Possible values are: 110, 300, 600, 1200, 2400, 4800, 9600, |
19200, 38400, 57600 and 115200. |
If None a default speed of 9600 bps is selected. |
|
'mode' specifies if we are using RS-232 or RS-485. The RS-485 mode |
is half duplex and use the RTS signal to indicate the |
direction of the communication (transmit or recive). |
Default to RS232 mode (at moment, only the RS-232 mode is |
implemented). |
|
'params' is a list that specifies properties of the serial |
communication. |
If params=None it uses default values for the number of bits |
per byte (8), the parity (NOPARITY) and the number of stop bits (1) |
else params is the termios package mode array to use for |
initialization. |
|
""" |
self.__devName, self.__timeout, self.__speed=dev, timeout, speed |
self.__mode=mode |
self.__params=params |
try: |
self.__handle=os.open(dev, os.O_RDWR) |
except: |
raise SerialPortException('Unable to open port') |
|
self.__configure() |
|
def __del__(self): |
"""Close the serial port and restore its initial configuration |
|
To close the serial port we have to do explicity: del s |
(where s is an instance of SerialPort) |
""" |
|
termios.tcsetattr(self.__handle, termios.TCSANOW, self.__oldmode) |
|
try: |
os.close(self.__handle) |
except IOError: |
raise SerialPortException('Unable to close port') |
|
|
def __configure(self): |
"""Configure the serial port. |
|
Private method called in the class constructor that configure the |
serial port with the characteristics given in the constructor. |
""" |
if not self.__speed: |
self.__speed=9600 |
|
# Save the initial port configuration |
self.__oldmode=termios.tcgetattr(self.__handle) |
if not self.__params: |
# self.__params is a list of attributes of the file descriptor |
# self.__handle as follows: |
# [c_iflag, c_oflag, c_cflag, c_lflag, c_ispeed, c_ospeed, cc] |
# where cc is a list of the tty special characters. |
self.__params=[] |
# c_iflag |
self.__params.append(termios.IGNPAR) |
# c_oflag |
self.__params.append(0) |
# c_cflag |
self.__params.append(termios.CS8|termios.CLOCAL|termios.CREAD) |
# c_lflag |
self.__params.append(0) |
# c_ispeed |
self.__params.append(SerialPort.BaudRatesDic[self.__speed]) |
# c_ospeed |
self.__params.append(SerialPort.BaudRatesDic[self.__speed]) |
# XXX FIX: Theorically, it should be better to put: |
# cc=[0]*termios.NCCS |
# but it doesn't work because NCCS is 19 and self.__oldmode[6] |
|
cc=[0]*len(self.__oldmode[6]) |
if self.__timeout==None: |
# A reading is only complete when VMIN characters have |
# been received (blocking reading) |
cc[termios.VMIN]=1 |
cc[termios.VTIME]=0 |
elif self.__timeout==0: |
# Non-blocking reading. The reading operation returns |
# inmeditately, returning the characters waiting to |
# be read. |
cc[termios.VMIN]=0 |
cc[termios.VTIME]=0 |
else: |
# Time-out reading. For a reading to be correct |
# a character must be recieved in VTIME*100 seconds. |
cc[termios.VMIN]=0 |
cc[termios.VTIME]=self.__timeout/100 |
self.__params.append(cc) # c_cc |
|
termios.tcsetattr(self.__handle, termios.TCSANOW, self.__params) |
|
|
def fileno(self): |
"""Return the file descriptor for opened device. |
|
This information can be used for example with the |
select funcion. |
""" |
return self.__handle |
|
|
def setraw(self): |
tty.setraw(self.__handle) |
|
def setcbreak(self): |
tty.setcbreak(self.__handle) |
|
def __read1(self): |
"""Read 1 byte from the serial port. |
|
Generate an exception if no byte is read and self.timeout!=0 |
because a timeout has expired. |
""" |
byte = os.read(self.__handle, 1) |
if len(byte)==0 and self.__timeout!=0: # Time-out |
raise SerialPortException('Timeout') |
else: |
return byte |
|
|
def read(self, num=1): |
"""Read num bytes from the serial port. |
|
Uses the private method __read1 to read num bytes. If an exception |
is generated in any of the calls to __read1 the exception is reraised. |
""" |
s='' |
for i in range(num): |
s=s+SerialPort.__read1(self) |
|
return s |
|
|
def readline(self): |
"""Read a line from the serial port. Returns input once a '\n' |
character is found. |
Douglas Jones (dfj23@drexel.edu) 09/09/2005. |
""" |
|
s = '' |
while not '\n' in s: |
s = s+SerialPort.__read1(self) |
|
return s |
|
|
def write(self, s): |
"""Write the string s to the serial port""" |
|
os.write(self.__handle, s) |
|
def inWaiting(self): |
"""Returns the number of bytes waiting to be read |
mod. by J.Grauheding |
""" |
rbuf=fcntl.ioctl(self.__handle, termios.TIOCINQ, self.buf) |
return rbuf |
|
def outWaiting(self): |
"""Returns the number of bytes waiting to be write |
mod. by J.Grauheding |
""" |
rbuf=fcntl.ioctl(self.__handle, termios.TIOCOUTQ, self.buf) |
return rbuf |
|
|
def flush(self): |
"""Discards all bytes from the output or input buffer""" |
termios.tcflush(self.__handle, termios.TCIOFLUSH) |
|
def rts_on(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMGET, SerialPort.buf) |
SerialPort.buf[1] = ord(rbuf[3]) | termios.TIOCM_RTS |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMSET, SerialPort.buf) |
return rbuf |
|
def rts_off(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMGET, self.buf) |
self.buf[1]=ord(rbuf[3]) & ~termios.TIOCM_RTS |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMSET, self.buf) |
return rbuf |
|
def dtr_on(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMGET, SerialPort.buf) |
SerialPort.buf[1] = ord(rbuf[3]) | termios.TIOCM_DTR |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMSET, SerialPort.buf) |
return rbuf |
|
def dtr_off(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMGET, self.buf) |
self.buf[1]=ord(rbuf[3]) & ~termios.TIOCM_DTR |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMSET, self.buf) |
return rbuf |
|
def cts(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMGET, self.buf) |
return ord(rbuf[3]) & termios.TIOCM_CTS |
|
def cd(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMGET, self.buf) |
return ord(rbuf[3]) & termios.TIOCM_CAR |
|
def dsr(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMGET, self.buf) |
return ord(rbuf[2]) & (termios.TIOCM_DSR>>8) |
|
def ri(self): |
""" J.Grauheding """ |
rbuf = fcntl.ioctl(self.__handle, termios.TIOCMGET, self.buf) |
return ord(rbuf[3]) & termios.TIOCM_RNG |
|
|
/Uspp/Readme_es
0,0 → 1,199
USPP Library |
|
Universal Serial Port Python Library |
|
|
Copyright 2006 Isaac Barona <ibarona@gmail.com> |
|
|
Contenidos |
---------- |
|
|
|
|
5. Pre-requisitos |
|
|
8. Problemas pendientes |
9. Tareas pendientes |
10. Portado a otras plataformas |
11. Licencia |
12. Autor |
|
|
|
|
--------------- |
|
|
|
|
|
en C/C++) espero que pueda ser ampliada para que soporte otras plataformas. |
|
|
|
------------- |
|
|
microcontroladores, especialmente aquellos que pueden ser conectados a |
un ordenador para enviar y recibir datos. |
|
|
|
|
|
los desarrollos bajo diferentes arquitecturas. |
|
|
|
|
|
* Sio Module de Roger Rurnham (rburnham@cri-inc.com) |
* pyxal (Python X10 Abstraction Layer) de Les Smithson |
(lsmithson@open-networks.co.uk) |
|
|
propietaria o eran simples ejemplos de acceso al puerto serie bajo una |
determinada plataforma. |
|
|
|
|
|
|
|
|
|
|
|
------------------------------ |
|
Puedes encontrarla en: |
* http://ibarona.googlepages.com/uspp |
* http://www.telefonica.net/web/babur |
|
como un fichero tar.gz o como un fichero .zip. |
|
|
|
------------------ |
|
|
|
- acceso de alto nivel al puerto serie bajo diversas plataformas. |
|
carga las clases adecuadas para esa plataforma. |
- Orientado a objetos. |
|
que las operaciones sobre objetos de tipo fichero. |
- permite utilizar el puerto serie con diferentes velocidades y |
|
|
|
|
|
- lecturas en modo bloqueante, no bloqueante o con timeout. |
|
|
5. Pre-requisitos |
---------------- |
|
|
|
- Python 2.1 o superior |
|
|
|
|
------------------------------ |
|
|
|
|
|
|
|
|
del objeto para leer y escribir en el puerto serie. |
|
Ejemplo: |
|
>>> from uspp import * |
>>> tty=SerialPort("COM2", 1000, 9600) |
>>> # Abre el puerto serie COM2 a 9600 bps y con un timeout de 1 segundo. |
|
>>> # Ahora suponemos que recibimos el string 'abc' |
>>> tty.inWaiting() |
3 |
>>> tty.read() |
'a' |
>>> tty.inWaiting() |
2 |
>>> tty.read(2) |
'bc' |
|
|
|
|
|
|
|
----------------- |
|
|
Windows 2000 con Python 2.1+ y en un Linux (con el kernel 2.0.34) con Python |
2.1+. |
|
|
8. Problemas pendientes |
----------------------- |
|
|
|
|
9. Tareas pendientes |
-------------------- |
|
Esta es la lista de tareas pendientes: |
|
- implementar el modo RS-485. |
|
realmente multiplataforma. |
|
|
10. Portado a otras plataformas |
------------------------------- |
|
|
los siguientes pasos: |
|
* Crear un nuevo fichero en python llamado SerialPort_XXX.py en el que |
|
|
|
|
|
11. Licencia |
------------ |
|
|
http://www.gnu.org/copyleft/lesser.html o en el fichero lesser.txt que |
|
|
|
|
12. Autor |
--------- |
|
|
|
|
|
---------- |
|
0.1 - 01/09/2001 |
0.2 - 13/05/2003 |
1.0 - 24/02/2006 |
|
/Uspp/AUTHORS
0,0 → 1,4
|
|
Douglas Jones <dfj23@drexel.edu> |
J.Grauheding <juergen.grauheding@a-city.de> |
/Uspp/uspp_es.htm
0,0 → 1,629
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title>ibarona - USPP(Universal Serial Port Python Library)</title> |
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
|
<style type="text/css"> |
#g_title p, #g_footer p, #g_description p { |
margin: 0; |
} |
/* |
|
-- -- -- -- -- -- -- |
Browser Fixes |
-- -- -- -- -- -- -- |
|
This file uses CSS filtering methods to fix various |
layout bugs. |
|
Each of the following three imported files is a |
separate, browser-specific CSS file that keeps all |
hacks out of the main style sheet. |
|
Over time, as supporting these browsers no longer |
remains a priority, cleaning up the hacks is as |
easy as deleting the @import statement below, or |
simply no longer linking this file from the HTML. |
|
*/ |
|
/* |
fix ie6 "peekaboo bug" using the "holly hack". |
Note, this style only gets applied to ie6 |
*/ |
* html .wrapper { |
height: 0.1%; |
} |
|
/* |
* IE5 mac - overrides the IE/Win hack |
*/ |
|
/*\*//*/ |
|
* html #threecolumn div { |
height: auto; |
} |
|
/**/ |
|
|
/* |
* IE5/Win-specific CSS -ensures #container wraps all content on window resize |
*/ |
|
@media tty { |
i{content:"\";/*" "*/}} * html #container { height: 1%; } /*";} |
}/* */ |
/* Styling for editable elements. Eventually, this will be part of the style. */ |
.editable { |
border: 1px dashed blue; |
} |
|
#footer { |
clear: both; |
} |
|
/* Extra divs hidden by default. The custom CSS can override this though */ |
#extraDiv1, #extraDiv2, #extraDiv3, #extraDiv4, #extraDiv5, #extraDiv6 { |
display: none; |
} |
|
/* |
-- -- -- -- -- -- -- |
1 Column Layout |
-- -- -- -- -- -- -- |
*/ |
|
/* Center #container, constrain to 718px width |
----------------------------------------------- */ |
body { |
text-align: center; |
} |
#container { |
width: 718px; |
text-align: left; |
margin: 0 auto; |
} |
|
#main-content { |
overflow: hidden; |
} |
|
/** BEGIN CUSTOM SKIN **/ |
/* |
|
-- -- -- -- -- -- -- |
Base CSS |
-- -- -- -- -- -- -- |
|
This file simply removes default styling on most HTML elements in |
order to reduce the need to later override them. |
|
*/ |
|
h1,h2,h3,h4,h5,h6,pre,code,p {font-size: 1em;} |
dl,li,dt,dd,h1,h2,h3,h4,h5,h6,pre,form,body,html,p,blockquote,fieldset,input {margin: 0; padding: 0;} |
a img,:link img,:visited img {border: none;} |
address {font-style: normal;}/* |
|
-- -- -- -- -- -- -- |
Type Scheme: Deco |
-- -- -- -- -- -- -- |
|
*/ |
|
body { |
font: 76% Verdana, sans-serif; |
} |
|
h1, h2, h3, h4, h5, h6, p.description { |
font-family: "Trebuchet MS", Trebuchet, sans-serif; |
} |
h1 { |
font-size: 3em; |
font-weight: bold; |
letter-spacing: 2px; |
} |
h2 { |
font-size: 2em; |
font-weight: normal; |
} |
h3 { |
font-size: 1.5em; |
} |
h4 { |
font-size: 1.2em; |
letter-spacing: 0.2em; |
} |
h5 { |
font-size: 1.2em; |
} |
h6 { |
font-size: 1em; |
font-weight: bold; |
} |
|
p, td { |
line-height: 1.8em; |
} |
code, kbd { |
font-size: 1.25em; |
}/* |
|
-- -- -- -- -- -- -- |
STYLE: Micro |
-- -- -- -- -- -- -- |
|
*/ |
|
|
|
|
/* ie6win */ |
|
/* IE/Win fixes for various layouts |
----------------------------------------------- */ |
* html #onecolumn #header { |
margin-right: -3px; |
} |
* html #onecolumn #header, |
* html #twocolumn-left #header, * html #twocolumn-right #header, |
* html #twocolumn-liquid-left #header, * html #twocolumn-liquid-right #header { |
padding-bottom: 1px; |
} |
* html #twocolumn-left #main-content, * html #twocolumn-right #main-content { |
width: 459px; |
} |
* html #threecolumn #main-content { |
width: 409px; |
} |
|
/* ie5mac */ |
|
/*\*//*/ |
/* Undoing IE/Win fixes |
----------------------------------------------- */ |
* html #onecolumn #header { |
margin-right: 0; |
} |
* html #twocolumn-left #header, * html #twocolumn-right #header, |
* html #twocolumn-liquid-left #header, * html #twocolumn-liquid-right #header { |
padding-bottom: 0; |
} |
* html #twocolumn-left #main-content, * html #twocolumn-right #main-content { |
width: 479px; |
} |
* html #threecolumn #main-content { |
width: 429px; |
} |
/**/ |
|
@media tty { |
i{content:"\";/*" "*/}} td { font-size: 0.8em; } /*";} |
}/* */ |
|
|
|
/* Basic HTML style |
----------------------------------------------- */ |
body { |
font: 76% "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif; |
color: #000; |
background: #fff; |
margin: 0; |
padding: 0; |
} |
blockquote { |
margin: 1em 2em; |
font-style: italic; |
} |
caption { |
font-weight: bold; |
color: #444; |
background: #ccc; |
border-bottom: 0; |
padding: 0.3em 1em; |
} |
dd { |
margin: 1em 2em; |
} |
dl { |
margin: 2em 0; |
} |
dt { |
font-weight: bold; |
} |
hr { |
margin: 2em 0; |
color: #C7C7C7; |
background: #C7C7C7; |
border-color: #C7C7C7; |
border-style: none; |
height: 1px; |
} |
li { |
margin: 1em 0; |
} |
table { |
border: solid 1px #ccc; |
} |
td { |
vertical-align: top; |
padding: 0.5em; |
} |
th { |
text-align: left; |
color: #fff; |
background: #777; |
padding: 0.5em; |
} |
ol, ul { |
margin: 2em 0; |
padding-left: 1em; |
} |
|
|
|
/* Nested HTML elements, and basic classes |
----------------------------------------------- */ |
ol li { |
list-style-type: decimal; |
margin-left: 2em; |
} |
ul li { |
margin-left: 2em; |
list-style-type: square; |
} |
td p { |
margin-top: 0; |
} |
|
|
|
/* Set the stage with main layout tweaks |
----------------------------------------------- */ |
#container { |
border: solid 7px #999; |
border-left: 0; |
border-right: 0; |
padding-top: 1px; |
} |
#header { |
color: #04172D; |
border-top: solid 3px #777; |
padding: 0; |
margin: 0 0 1.5em 0; |
} |
#main-content .wrapper { |
margin: 0; |
} |
.description { |
font: normal 1em "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif; |
color: #444; |
background: #C7C7C7; |
padding: 3px 25px 2.2em 25px; |
margin: 0; |
line-height: 1; |
} |
#footer { |
clear: both; |
color: #999; |
padding: 0 1em 1em 1em; |
border-bottom: solid 3px #777; |
margin-bottom: 1px; |
} |
|
|
/* Content area offset |
----------------------------------------------- */ |
#main-content .wrapper { |
padding: 0 25px; |
} |
|
#main-content td p { |
margin: 0 0 1em 0; |
} |
|
|
|
/* Custom font definitions |
----------------------------------------------- */ |
p { |
margin: 1em 0; |
line-height: 1.5; |
} |
h1,h2,h3,h4,h5,h6 { |
font-family: "Trebuchet MS", arial, sans-serif; |
} |
h1 { |
color: #B2B2B2; |
font-size: 2.4em; |
letter-spacing: 0.2em; |
font-weight: normal; |
padding: 1em 25px 0 25px; |
} |
h2 { |
margin: 0 0 0.5em 0; |
color: #777; |
font-size: 1.4em; |
font-weight: normal; |
border-bottom: double 3px #C7C7C7; |
padding: 0 0 0.4em 0; |
} |
h3 { |
font-size: 1.2em; |
background: #eee; |
border: dotted 1px #C7C7C7; |
padding: 0.2em; |
} |
h4 { |
font-size: 1.2em; |
padding: 0 0 0.2em 0; |
margin: 0.6em 0 0 0.4em; |
color: #777; |
} |
h5 { |
border-bottom: dotted 1px #C7C7C7; |
} |
h6 { |
color: #777; |
border-left: solid 1.2em #777; |
padding-left: 0.6em; |
} |
|
a:link { |
color: #9db2df; |
} |
a:hover { |
text-decoration: none; |
border-bottom: 1px dotted #bb242d; |
background-color: #e0e0e0; |
} |
|
|
/* Sidebar |
----------------------------------------------- */ |
#sidebar h3, #sidebar-alternate h3 { |
margin: 0; |
color: #777; |
background: none; |
font-size: 1.4em; |
font-weight: normal; |
border: none; |
padding: 0; |
} |
|
#sidebar blockquote, #sidebar blockquote p, |
#sidebar-alternate blockquote, #sidebar-alternate blockquote p { |
margin-left: 0; |
margin-right: 0; |
} |
#sidebar blockquote { |
margin: 1em 0; |
padding: 0; |
} |
#adsense { |
text-align: center; |
} |
|
|
|
.editable { |
border: dashed 1px #c33; |
} |
|
|
|
|
/* Tweaks for Two-column Right layout |
----------------------------------------------- */ |
#twocolumn-right #sidebar .wrapper { |
margin: 0 10px; |
} |
|
|
|
/* Tweaks for Two-column Left layout |
----------------------------------------------- */ |
#twocolumn-left #sidebar .wrapper { |
margin: 0 10px; |
} |
|
|
/* Tweaks for Three-column layout |
----------------------------------------------- */ |
#threecolumn #sidebar .wrapper { |
margin: 0 10px; |
} |
#threecolumn #sidebar-alternate .wrapper { |
margin: 0 10px; |
} |
/* |
|
-- -- -- -- -- -- -- |
COLOR SCHEME: Blueprint |
-- -- -- -- -- -- -- |
|
*/ |
|
|
/* Basic HTML style |
----------------------------------------------- */ |
a:link { |
color: #445AA9; |
} |
a:visited { |
color: #283D88; |
} |
body { |
color: #283769; |
background: #ECEEF6; |
} |
caption { |
color: inherit; |
background: #ECEEF6; |
} |
hr { |
color: #C7C7C7; |
background: #C7C7C7; |
border-color: #C7C7C7; |
} |
table { |
background: #fff; |
border-color: #B3BCDC; |
} |
th { |
color: #fff; |
background: #445AA9; |
} |
|
|
|
/* Set the stage with main layout tweaks |
----------------------------------------------- */ |
#container { |
background-color: #F6F7FB; |
border-color: #6678B8; |
} |
#header { |
color: #445AA9; |
border-top-color: #6678B8; |
} |
.description { |
color: #445AA9; |
background: #C9D0E6; |
} |
#footer { |
color: #5064AE; |
border-bottom-color: #6678B8; |
} |
|
|
|
/* Custom font definitions |
----------------------------------------------- */ |
h1 { |
color: #445AA9; |
} |
h2 { |
color: #5064AE; |
border-bottom-color: #B3BCDC; |
} |
h3 { |
background: #ECEEF6; |
border-color: #C9D0E6; |
} |
h4 { |
border-bottom-color: #B3BCDC; |
color: #1A4292; |
} |
h5 { |
border-bottom-color: #C7C7C7; |
} |
h6 { |
color: #5064AE; |
border-left-color: #B3BCDC; |
} |
|
|
|
|
|
/* Sidebar |
----------------------------------------------- */ |
#sidebar h3, #sidebar-alternate h3 { |
color: #5064AE; |
background: none; |
} |
/** END CUSTOM SKIN **/ |
</style><!-- Hack to avoid flash of unstyled content in IE --> |
|
|
<script> </script></head><body id="onecolumn"> |
<div id="container"> |
<div class="wrapper"> |
<div id="header"> |
<div class="wrapper"> |
<h1 id="page-title"><div id="g_title">USPP(Universal Serial Port Python Library)</div></h1> |
<div style="clear: both;"></div> |
<p class="description"></p><div id="g_description"><p>Isaac Barona (ibarona@gmail.com) <br></p></div> |
<div style="clear: both;"></div> |
</div> |
</div> |
|
<div id="main-content"> |
<div class="wrapper"> |
<div class="content-item"><div id="g_body"><h2>Introduccion</h2><p>La |
librería USPP es un módulo desarrollado en Python para el acceso |
multiplataforma al puerto serie. En el momento, sólo funciona en Linux, |
Windows y MacOS, pero como está escrita completamente en Python |
(no es únicamente un recubrimiento en Python de una librería |
desarrollada en C/C++) espero que pueda ser ampliada para que |
soporte otras plataformas.<i><br><br></i></p><h2>Motivacion</h2><p> A |
mí me gusta mucho hacer pequeños cacharros electrónicos con |
microcontroladores, especialmente aquellos que pueden ser conectados a |
un ordenador para enviar y recibir datos. Hace un par de meses descubrí |
Python y realmente me encantó. Empezé a jugar con él y ví que podía |
utilizarlo para hacer prototipos de protocolos de comunicación entre el |
ordenador y los microcontroladores de manera mucho más fácil y |
rápida que utilizando C (que era el lenguaje que solía utilizar). Al |
mismo tiempo, estaba interesado en poder utilizar los desarrollos bajo |
diferentes arquitecturas. Empezé a buscar en la red módulos de Python |
que accedieran al puerto serie<br>y encontré los siguientes:<br><br> * win32comport_demo que viene junto a la extensión win32.<br> * Módulo win32comm de wheineman@uconect.net.<br> * Sio Module de Roger Rurnham (rburnham@cri-inc.com)<br> * pyxal (Python X10 Abstraction Layer) de Les Smithson <br> (lsmithson@open-networks.co.uk)<br><br>pero |
no eran multiplataforma, eran únicamente un recubrimiento de una |
librería propietaria o eran simples ejemplos de acceso al puerto serie |
bajo una determinada plataforma.<br>Por estas razones, y también |
por supuesto, por aprender más Python, decidí empezar este proyecto. |
Por supuesto, he utilizado los módulos indicados anteriormente como |
referencia para realizar mi librería y por tanto, me creo en la |
obligación de felicitar a sus autores por su excelente trabajo y por |
haberlo compartido con los demás.<br><br>Espero que disfrutes utilizándo el módulo uspp tanto como yo lo he hecho haciéndolo.</p><h2>Características </h2><p>Este módulo tiene las siguientes características destacadas:<br> </p><ul><li> acceso de alto nivel al puerto serie bajo diversas plataformas.</li><li>autodetecta la plataforma en la que se está ejecutando y carga las clases adecuadas para esa plataforma.</li><li>Orientado a objetos.</li><li>Las operaciones sobre el puerto serie tienen la misma semántica que las operaciones sobre objetos de tipo fichero.</li><li> permite utilizar el puerto serie con diferentes velocidades y características.</li><li>permite |
la utilización del puerto bajo dos modos de funcionamiento: RS-232 y |
RS-485 (de momento, sólo RS-232). En modo 485 la comunicación es |
half-duplex y se utiliza la línea RTS para controlar la dirección de la |
transferencia.</li><li>lecturas en modo bloqueante, no bloqueante o con timeout.</li></ul><h2>Prerequisitos</h2><p>Se necesita los siguiente para utilizar la librería:</p><ul><li>Python 2.1 o superior</li><li>En windows los módulos win32</li></ul><h2>Utilización y documentación<br></h2><p>Únicamente |
tienes que importar en tu programa el módulo uspp y automáticamente él |
se encarga de cargar las clases adecuadas para la plataforma en la que |
se está ejecutando el programa.<br><br>Lo primero de todo, tendrás que |
crear un objeto de tipo SerialPort con las características que desees. |
Si no se genera ninguna excepción del tipo SerialPortException, puedes |
utilizar los métodos de lectura y escritura<br>del objeto para leer y escribir en el puerto serie.<br><br>Ejemplo:</p><pre><tt><tt>>>> from uspp import *<br>>>> tty=SerialPort("COM2", 1000, 9600) <br>>>> # Opens COM2 at 9600 bps and with a read timeout of 1 second.<br>>>> tty.write("a") # Writes a character to the COM2 port<br>>>> # Now suppose we receive the string "abc"<br>>>> tty.inWaiting()<br>3<br>>>> tty.read()<br>'a'<br>>>> tty.inWaiting()<br>2<br>>>> tty.read(2)<br>'bc'</tt></tt></pre><pre><tt><tt> </tt></tt></pre><pre><br></pre><p><font face="arial,sans-serif" size="2">La |
documentación de las diferentes clases y métodos que componen el módulo |
puede encontrarse en el string de documentación del módulo uspp.</font></p><h2>Donde funciona<br></h2><p>La |
librería ha sido probada en una máquina con Windows 95, Windows XP y |
Windows 2000 con Python 2.1+ y en un Linux (con el kernel 2.0.34) con |
Python 2.1+.</p><h2>Portado a otras plataformas<br></h2><p></p><p> Si quieres portar la librería a otras plataformas sólo tienes que seguir los siguientes pasos:</p><ul><li>Crear |
un nuevo fichero en python llamado SerialPort_XXX.py en el que |
implementes las mismas clases y métodos públicos que aparecen en los |
módulos SerialPort_win y SerialPort_linux.</li><li>Añadir la nueva plataforma en el fichero uspp.py.<br></li></ul><h2> Licencia </h2><p>Este |
código se libera bajo la licencia "LGPL" que puedes encontrar en |
http://www.gnu.org/copyleft/lesser.html o en el fichero lesser.txt que |
acompaña a la librería. Si utilizas este software estaría muy |
agradecido de saberlo. </p><h2>Autor</h2><p>Esta librería ha sido creada por Isaac Barona Martínez <ibarona@gmail.com>.</p><h2>Versiones</h2><h3>Versión 1.0 - 24/02/2006 </h3><p>Mucho |
tiempo después de la versión 0.1 he tenido el tiempo suficiente de |
liberar la versión definitiva de la librería. Esta versión corrige los |
errores encontrados en la versión anterior, funciona en MacOS y ha sido |
ampliada.</p><p>La libería contiene más funciones en las versiones para Linux y MacOS que para Windows. </p><p>Tengo que agradecer a muchas personas su contribución a esta librería, especialmente a:</p><ul><li>Damien Geranton <dgeranton at voila.fr> </li><li>Douglas Jones <dfj23 at drexel.edu></li><li>J.Grauheding <juergen.grauheding at a-city.de></li></ul><p>Puedes descargar los ficheros desde aqui:</p><ul><li>Zip file: uspp-0_1.zip</li><li>tar.gz file: uspp-0_1.tar.gz</li></ul><h3> Version 0.1 - 01/09/2001 (Septiembre 2001)</h3><p> </p><p> </p></div></div> |
<div style="clear: both;"></div> |
</div> |
</div> |
|
<div id="footer"><div class="wrapper"> |
<hr> |
<p></p><div id="g_footer"> </div> |
<div style="clear: both;"></div> |
</div></div> |
|
</div> |
</div> |
|
|
<div id="extraDiv1"><span></span></div><div id="extraDiv2"><span></span></div> |
<div id="extraDiv3"><span></span></div><div id="extraDiv4"><span></span></div> |
<div id="extraDiv5"><span></span></div><div id="extraDiv6"><span></span></div> |
|
</body></html> |
/Uspp/__init__.py
--- Uspp/Copyright (nonexistent)
+++ Uspp/Copyright (revision 53)
@@ -0,0 +1,21 @@
+USPP Library (Universal Serial Port Python Library)
+
+Copyright (C) 2006 Artec Design
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+The complete text of the GNU Lesser General Public License can be found in
+the file 'lesser.txt'.
/Uspp/lesser.txt
0,0 → 1,504
GNU LESSER GENERAL PUBLIC LICENSE |
Version 2.1, February 1999 |
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc. |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Everyone is permitted to copy and distribute verbatim copies |
of this license document, but changing it is not allowed. |
|
[This is the first released version of the Lesser GPL. It also counts |
as the successor of the GNU Library Public License, version 2, hence |
the version number 2.1.] |
|
Preamble |
|
The licenses for most software are designed to take away your |
freedom to share and change it. By contrast, the GNU General Public |
Licenses are intended to guarantee your freedom to share and change |
free software--to make sure the software is free for all its users. |
|
This license, the Lesser General Public License, applies to some |
specially designated software packages--typically libraries--of the |
Free Software Foundation and other authors who decide to use it. You |
can use it too, but we suggest you first think carefully about whether |
this license or the ordinary General Public License is the better |
strategy to use in any particular case, based on the explanations below. |
|
When we speak of free software, we are referring to freedom of use, |
not price. Our General Public Licenses are designed to make sure that |
you have the freedom to distribute copies of free software (and charge |
for this service if you wish); that you receive source code or can get |
it if you want it; that you can change the software and use pieces of |
it in new free programs; and that you are informed that you can do |
these things. |
|
To protect your rights, we need to make restrictions that forbid |
distributors to deny you these rights or to ask you to surrender these |
rights. These restrictions translate to certain responsibilities for |
you if you distribute copies of the library or if you modify it. |
|
For example, if you distribute copies of the library, whether gratis |
or for a fee, you must give the recipients all the rights that we gave |
you. You must make sure that they, too, receive or can get the source |
code. If you link other code with the library, you must provide |
complete object files to the recipients, so that they can relink them |
with the library after making changes to the library and recompiling |
it. And you must show them these terms so they know their rights. |
|
We protect your rights with a two-step method: (1) we copyright the |
library, and (2) we offer you this license, which gives you legal |
permission to copy, distribute and/or modify the library. |
|
To protect each distributor, we want to make it very clear that |
there is no warranty for the free library. Also, if the library is |
modified by someone else and passed on, the recipients should know |
that what they have is not the original version, so that the original |
author's reputation will not be affected by problems that might be |
introduced by others. |
|
Finally, software patents pose a constant threat to the existence of |
any free program. We wish to make sure that a company cannot |
effectively restrict the users of a free program by obtaining a |
restrictive license from a patent holder. Therefore, we insist that |
any patent license obtained for a version of the library must be |
consistent with the full freedom of use specified in this license. |
|
Most GNU software, including some libraries, is covered by the |
ordinary GNU General Public License. This license, the GNU Lesser |
General Public License, applies to certain designated libraries, and |
is quite different from the ordinary General Public License. We use |
this license for certain libraries in order to permit linking those |
libraries into non-free programs. |
|
When a program is linked with a library, whether statically or using |
a shared library, the combination of the two is legally speaking a |
combined work, a derivative of the original library. The ordinary |
General Public License therefore permits such linking only if the |
entire combination fits its criteria of freedom. The Lesser General |
Public License permits more lax criteria for linking other code with |
the library. |
|
We call this license the "Lesser" General Public License because it |
does Less to protect the user's freedom than the ordinary General |
Public License. It also provides other free software developers Less |
of an advantage over competing non-free programs. These disadvantages |
are the reason we use the ordinary General Public License for many |
libraries. However, the Lesser license provides advantages in certain |
special circumstances. |
|
For example, on rare occasions, there may be a special need to |
encourage the widest possible use of a certain library, so that it becomes |
a de-facto standard. To achieve this, non-free programs must be |
allowed to use the library. A more frequent case is that a free |
library does the same job as widely used non-free libraries. In this |
case, there is little to gain by limiting the free library to free |
software only, so we use the Lesser General Public License. |
|
In other cases, permission to use a particular library in non-free |
programs enables a greater number of people to use a large body of |
free software. For example, permission to use the GNU C Library in |
non-free programs enables many more people to use the whole GNU |
operating system, as well as its variant, the GNU/Linux operating |
system. |
|
Although the Lesser General Public License is Less protective of the |
users' freedom, it does ensure that the user of a program that is |
linked with the Library has the freedom and the wherewithal to run |
that program using a modified version of the Library. |
|
The precise terms and conditions for copying, distribution and |
modification follow. Pay close attention to the difference between a |
"work based on the library" and a "work that uses the library". The |
former contains code derived from the library, whereas the latter must |
be combined with the library in order to run. |
|
GNU LESSER GENERAL PUBLIC LICENSE |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
|
0. This License Agreement applies to any software library or other |
program which contains a notice placed by the copyright holder or |
other authorized party saying it may be distributed under the terms of |
this Lesser General Public License (also called "this License"). |
Each licensee is addressed as "you". |
|
A "library" means a collection of software functions and/or data |
prepared so as to be conveniently linked with application programs |
(which use some of those functions and data) to form executables. |
|
The "Library", below, refers to any such software library or work |
which has been distributed under these terms. A "work based on the |
Library" means either the Library or any derivative work under |
copyright law: that is to say, a work containing the Library or a |
portion of it, either verbatim or with modifications and/or translated |
straightforwardly into another language. (Hereinafter, translation is |
included without limitation in the term "modification".) |
|
"Source code" for a work means the preferred form of the work for |
making modifications to it. For a library, complete source code means |
all the source code for all modules it contains, plus any associated |
interface definition files, plus the scripts used to control compilation |
and installation of the library. |
|
Activities other than copying, distribution and modification are not |
covered by this License; they are outside its scope. The act of |
running a program using the Library is not restricted, and output from |
such a program is covered only if its contents constitute a work based |
on the Library (independent of the use of the Library in a tool for |
writing it). Whether that is true depends on what the Library does |
and what the program that uses the Library does. |
|
1. You may copy and distribute verbatim copies of the Library's |
complete source code as you receive it, in any medium, provided that |
you conspicuously and appropriately publish on each copy an |
appropriate copyright notice and disclaimer of warranty; keep intact |
all the notices that refer to this License and to the absence of any |
warranty; and distribute a copy of this License along with the |
Library. |
|
You may charge a fee for the physical act of transferring a copy, |
and you may at your option offer warranty protection in exchange for a |
fee. |
|
2. You may modify your copy or copies of the Library or any portion |
of it, thus forming a work based on the Library, and copy and |
distribute such modifications or work under the terms of Section 1 |
above, provided that you also meet all of these conditions: |
|
a) The modified work must itself be a software library. |
|
b) You must cause the files modified to carry prominent notices |
stating that you changed the files and the date of any change. |
|
c) You must cause the whole of the work to be licensed at no |
charge to all third parties under the terms of this License. |
|
d) If a facility in the modified Library refers to a function or a |
table of data to be supplied by an application program that uses |
the facility, other than as an argument passed when the facility |
is invoked, then you must make a good faith effort to ensure that, |
in the event an application does not supply such function or |
table, the facility still operates, and performs whatever part of |
its purpose remains meaningful. |
|
(For example, a function in a library to compute square roots has |
a purpose that is entirely well-defined independent of the |
application. Therefore, Subsection 2d requires that any |
application-supplied function or table used by this function must |
be optional: if the application does not supply it, the square |
root function must still compute square roots.) |
|
These requirements apply to the modified work as a whole. If |
identifiable sections of that work are not derived from the Library, |
and can be reasonably considered independent and separate works in |
themselves, then this License, and its terms, do not apply to those |
sections when you distribute them as separate works. But when you |
distribute the same sections as part of a whole which is a work based |
on the Library, the distribution of the whole must be on the terms of |
this License, whose permissions for other licensees extend to the |
entire whole, and thus to each and every part regardless of who wrote |
it. |
|
Thus, it is not the intent of this section to claim rights or contest |
your rights to work written entirely by you; rather, the intent is to |
exercise the right to control the distribution of derivative or |
collective works based on the Library. |
|
In addition, mere aggregation of another work not based on the Library |
with the Library (or with a work based on the Library) on a volume of |
a storage or distribution medium does not bring the other work under |
the scope of this License. |
|
3. You may opt to apply the terms of the ordinary GNU General Public |
License instead of this License to a given copy of the Library. To do |
this, you must alter all the notices that refer to this License, so |
that they refer to the ordinary GNU General Public License, version 2, |
instead of to this License. (If a newer version than version 2 of the |
ordinary GNU General Public License has appeared, then you can specify |
that version instead if you wish.) Do not make any other change in |
these notices. |
|
Once this change is made in a given copy, it is irreversible for |
that copy, so the ordinary GNU General Public License applies to all |
subsequent copies and derivative works made from that copy. |
|
This option is useful when you wish to copy part of the code of |
the Library into a program that is not a library. |
|
4. You may copy and distribute the Library (or a portion or |
derivative of it, under Section 2) in object code or executable form |
under the terms of Sections 1 and 2 above provided that you accompany |
it with the complete corresponding machine-readable source code, which |
must be distributed under the terms of Sections 1 and 2 above on a |
medium customarily used for software interchange. |
|
If distribution of object code is made by offering access to copy |
from a designated place, then offering equivalent access to copy the |
source code from the same place satisfies the requirement to |
distribute the source code, even though third parties are not |
compelled to copy the source along with the object code. |
|
5. A program that contains no derivative of any portion of the |
Library, but is designed to work with the Library by being compiled or |
linked with it, is called a "work that uses the Library". Such a |
work, in isolation, is not a derivative work of the Library, and |
therefore falls outside the scope of this License. |
|
However, linking a "work that uses the Library" with the Library |
creates an executable that is a derivative of the Library (because it |
contains portions of the Library), rather than a "work that uses the |
library". The executable is therefore covered by this License. |
Section 6 states terms for distribution of such executables. |
|
When a "work that uses the Library" uses material from a header file |
that is part of the Library, the object code for the work may be a |
derivative work of the Library even though the source code is not. |
Whether this is true is especially significant if the work can be |
linked without the Library, or if the work is itself a library. The |
threshold for this to be true is not precisely defined by law. |
|
If such an object file uses only numerical parameters, data |
structure layouts and accessors, and small macros and small inline |
functions (ten lines or less in length), then the use of the object |
file is unrestricted, regardless of whether it is legally a derivative |
work. (Executables containing this object code plus portions of the |
Library will still fall under Section 6.) |
|
Otherwise, if the work is a derivative of the Library, you may |
distribute the object code for the work under the terms of Section 6. |
Any executables containing that work also fall under Section 6, |
whether or not they are linked directly with the Library itself. |
|
6. As an exception to the Sections above, you may also combine or |
link a "work that uses the Library" with the Library to produce a |
work containing portions of the Library, and distribute that work |
under terms of your choice, provided that the terms permit |
modification of the work for the customer's own use and reverse |
engineering for debugging such modifications. |
|
You must give prominent notice with each copy of the work that the |
Library is used in it and that the Library and its use are covered by |
this License. You must supply a copy of this License. If the work |
during execution displays copyright notices, you must include the |
copyright notice for the Library among them, as well as a reference |
directing the user to the copy of this License. Also, you must do one |
of these things: |
|
a) Accompany the work with the complete corresponding |
machine-readable source code for the Library including whatever |
changes were used in the work (which must be distributed under |
Sections 1 and 2 above); and, if the work is an executable linked |
with the Library, with the complete machine-readable "work that |
uses the Library", as object code and/or source code, so that the |
user can modify the Library and then relink to produce a modified |
executable containing the modified Library. (It is understood |
that the user who changes the contents of definitions files in the |
Library will not necessarily be able to recompile the application |
to use the modified definitions.) |
|
b) Use a suitable shared library mechanism for linking with the |
Library. A suitable mechanism is one that (1) uses at run time a |
copy of the library already present on the user's computer system, |
rather than copying library functions into the executable, and (2) |
will operate properly with a modified version of the library, if |
the user installs one, as long as the modified version is |
interface-compatible with the version that the work was made with. |
|
c) Accompany the work with a written offer, valid for at |
least three years, to give the same user the materials |
specified in Subsection 6a, above, for a charge no more |
than the cost of performing this distribution. |
|
d) If distribution of the work is made by offering access to copy |
from a designated place, offer equivalent access to copy the above |
specified materials from the same place. |
|
e) Verify that the user has already received a copy of these |
materials or that you have already sent this user a copy. |
|
For an executable, the required form of the "work that uses the |
Library" must include any data and utility programs needed for |
reproducing the executable from it. However, as a special exception, |
the materials to be distributed need not include anything that is |
normally distributed (in either source or binary form) with the major |
components (compiler, kernel, and so on) of the operating system on |
which the executable runs, unless that component itself accompanies |
the executable. |
|
It may happen that this requirement contradicts the license |
restrictions of other proprietary libraries that do not normally |
accompany the operating system. Such a contradiction means you cannot |
use both them and the Library together in an executable that you |
distribute. |
|
7. You may place library facilities that are a work based on the |
Library side-by-side in a single library together with other library |
facilities not covered by this License, and distribute such a combined |
library, provided that the separate distribution of the work based on |
the Library and of the other library facilities is otherwise |
permitted, and provided that you do these two things: |
|
a) Accompany the combined library with a copy of the same work |
based on the Library, uncombined with any other library |
facilities. This must be distributed under the terms of the |
Sections above. |
|
b) Give prominent notice with the combined library of the fact |
that part of it is a work based on the Library, and explaining |
where to find the accompanying uncombined form of the same work. |
|
8. You may not copy, modify, sublicense, link with, or distribute |
the Library except as expressly provided under this License. Any |
attempt otherwise to copy, modify, sublicense, link with, or |
distribute the Library is void, and will automatically terminate your |
rights under this License. However, parties who have received copies, |
or rights, from you under this License will not have their licenses |
terminated so long as such parties remain in full compliance. |
|
9. You are not required to accept this License, since you have not |
signed it. However, nothing else grants you permission to modify or |
distribute the Library or its derivative works. These actions are |
prohibited by law if you do not accept this License. Therefore, by |
modifying or distributing the Library (or any work based on the |
Library), you indicate your acceptance of this License to do so, and |
all its terms and conditions for copying, distributing or modifying |
the Library or works based on it. |
|
10. Each time you redistribute the Library (or any work based on the |
Library), the recipient automatically receives a license from the |
original licensor to copy, distribute, link with or modify the Library |
subject to these terms and conditions. You may not impose any further |
restrictions on the recipients' exercise of the rights granted herein. |
You are not responsible for enforcing compliance by third parties with |
this License. |
|
11. If, as a consequence of a court judgment or allegation of patent |
infringement or for any other reason (not limited to patent issues), |
conditions are imposed on you (whether by court order, agreement or |
otherwise) that contradict the conditions of this License, they do not |
excuse you from the conditions of this License. If you cannot |
distribute so as to satisfy simultaneously your obligations under this |
License and any other pertinent obligations, then as a consequence you |
may not distribute the Library at all. For example, if a patent |
license would not permit royalty-free redistribution of the Library by |
all those who receive copies directly or indirectly through you, then |
the only way you could satisfy both it and this License would be to |
refrain entirely from distribution of the Library. |
|
If any portion of this section is held invalid or unenforceable under any |
particular circumstance, the balance of the section is intended to apply, |
and the section as a whole is intended to apply in other circumstances. |
|
It is not the purpose of this section to induce you to infringe any |
patents or other property right claims or to contest validity of any |
such claims; this section has the sole purpose of protecting the |
integrity of the free software distribution system which is |
implemented by public license practices. Many people have made |
generous contributions to the wide range of software distributed |
through that system in reliance on consistent application of that |
system; it is up to the author/donor to decide if he or she is willing |
to distribute software through any other system and a licensee cannot |
impose that choice. |
|
This section is intended to make thoroughly clear what is believed to |
be a consequence of the rest of this License. |
|
12. If the distribution and/or use of the Library is restricted in |
certain countries either by patents or by copyrighted interfaces, the |
original copyright holder who places the Library under this License may add |
an explicit geographical distribution limitation excluding those countries, |
so that distribution is permitted only in or among countries not thus |
excluded. In such case, this License incorporates the limitation as if |
written in the body of this License. |
|
13. The Free Software Foundation may publish revised and/or new |
versions of the Lesser General Public License from time to time. |
Such new versions will be similar in spirit to the present version, |
but may differ in detail to address new problems or concerns. |
|
Each version is given a distinguishing version number. If the Library |
specifies a version number of this License which applies to it and |
"any later version", you have the option of following the terms and |
conditions either of that version or of any later version published by |
the Free Software Foundation. If the Library does not specify a |
license version number, you may choose any version ever published by |
the Free Software Foundation. |
|
14. If you wish to incorporate parts of the Library into other free |
programs whose distribution conditions are incompatible with these, |
write to the author to ask for permission. For software which is |
copyrighted by the Free Software Foundation, write to the Free |
Software Foundation; we sometimes make exceptions for this. Our |
decision will be guided by the two goals of preserving the free status |
of all derivatives of our free software and of promoting the sharing |
and reuse of software generally. |
|
NO WARRANTY |
|
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO |
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. |
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR |
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY |
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME |
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
|
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN |
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY |
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU |
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
DAMAGES. |
|
END OF TERMS AND CONDITIONS |
|
How to Apply These Terms to Your New Libraries |
|
If you develop a new library, and you want it to be of the greatest |
possible use to the public, we recommend making it free software that |
everyone can redistribute and change. You can do so by permitting |
redistribution under these terms (or, alternatively, under the terms of the |
ordinary General Public License). |
|
To apply these terms, attach the following notices to the library. It is |
safest to attach them to the start of each source file to most effectively |
convey the exclusion of warranty; and each file should have at least the |
"copyright" line and a pointer to where the full notice is found. |
|
<one line to give the library's name and a brief idea of what it does.> |
Copyright (C) <year> <name of author> |
|
This library is free software; you can redistribute it and/or |
modify it under the terms of the GNU Lesser General Public |
License as published by the Free Software Foundation; either |
version 2.1 of the License, or (at your option) any later version. |
|
This library is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
Lesser General Public License for more details. |
|
You should have received a copy of the GNU Lesser General Public |
License along with this library; if not, write to the Free Software |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
Also add information on how to contact you by electronic and paper mail. |
|
You should also get your employer (if you work as a programmer) or your |
school, if any, to sign a "copyright disclaimer" for the library, if |
necessary. Here is a sample; alter the names: |
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the |
library `Frob' (a library for tweaking knobs) written by James Random Hacker. |
|
<signature of Ty Coon>, 1 April 1990 |
Ty Coon, President of Vice |
|
That's all there is to it! |
|
|
/Uspp/Readme
0,0 → 1,190
USPP Library |
|
Universal Serial Port Python Library |
|
Copyright 2006 Isaac Barona <ibarona@gmail.com> |
|
|
Contents |
-------- |
1. Introduction |
2. Motivation |
3. Where can I find it |
4. Features |
5. Pre-requisites |
6. Usage and documentation |
7. Where does it work |
8. Known problems |
9. To-do list |
10. Porting to other platforms |
11. Licence |
12. Author |
13. Version |
|
|
1. Introduction |
--------------- |
|
USPP Library is a multi-platform Python module to access serial ports. At the |
moment, it only works in Windows, Linux and MacOS but as it is written entirely |
in Python (doesn't wrap any C/C++ library) I hope you can extend it to support |
any other platforms. |
|
|
2. Motivation |
------------- |
|
I like very much to make electronic widgets with microcontrollers, specially |
those that can be connected to the computer to send and receive data. |
Some months ago, I discovered Python and inmediatelly liked it a lot. |
I started playing with it and saw that I could use it to make prototypes of |
comunication protocols between computer and microcontrollers really |
fast and easily than using C. At the same time, I was interested in |
working over different platforms. |
I started looking for Python modules to access serial port and I found |
the following projects: |
|
* win32comport_demo from the win32 extension module |
* win32comm module of wheineman@uconect.net |
* Sio Module of Roger Rurnham (rburnham@cri-inc.com) |
* pyxal (Python X10 Abstraction Layer) of Les Smithson |
(lsmithson@open-networks.co.uk) |
|
but they were not multi-platform, were just a wrap of propietary libraries or |
were just simple examples of serial port access. |
For these reasons and also for learning more Python, I decided to start |
this project. Of course, I have used all this projects as reference to |
my module and so, I want to thanks the authors for their excellent work and |
for allowing us to study the code. |
I hope you enjoy using the uspp module as much as I am enjoying doing it. |
|
|
3. Where can I find it |
---------------------- |
|
You may find it at: |
* http://ibarona.googlepages.com/uspp |
* http://www.telefonica.net/web/babur |
|
as a tar.gz package or as a winzip file. |
|
|
4. Features |
----------- |
|
This module has the following features: |
|
- hight level access to serial port under several platforms. |
- autodetects the platform in which it is working and exports |
the correct classes for that platform. |
- object oriented approach. |
- file object semantic operations over the ports. |
- allows using the serial port with different speeds and |
characteristics. |
- RS-232 and RS-485 modes (now only RS-232). In RS-485 mode |
the communication is half-duplex and uses the RTS line |
to control the direction of the transference. |
- blocking, non-blocking or configurable timeout reads. |
|
|
5. Prerequisites |
---------------- |
|
You need the following to use the library: |
|
- Python 2.1 or better |
- In windows you need the win32 extension modules |
|
|
6. Usage and documentation |
-------------------------- |
|
You only have to import in your program the uspp module and automatically |
it loads the correct classes for the platform in which you are running |
the program. |
|
First of all you have to create a SerialPort object with the settings you |
want. If a SerialPortException is not generated then you just can |
use the read and write methods of the object to read and write to |
the serial port. |
|
Example: |
|
>>> from uspp import * |
>>> tty=SerialPort("COM2", 1000, 9600) |
>>> # Opens COM2 at 9600 bps and with a read timeout of 1 second. |
>>> tty.write("a") # Writes a character to the COM2 port |
>>> # Now suppose we receive the string "abc" |
>>> tty.inWaiting() |
3 |
>>> tty.read() |
'a' |
>>> tty.inWaiting() |
2 |
>>> tty.read(2) |
'bc' |
|
|
Documentation of the different classes and methods can be found on |
uspp module docstring. |
|
|
7. Where does it work |
--------------------- |
|
The library has been tested in Windows 95, Windows XP and Windows 2000 |
machines with Python 2.1+ and in a Linux (2.0.34 kernel) machine with |
Python 2.1+. |
|
|
8. Known problems |
----------------- |
|
|
|
|
9. To-do list |
------------- |
|
This is the to-do list: |
|
- implement RS-485 mode. |
- port the library to other platforms so that it can be really |
multi-platform. |
|
|
10. Porting to other platforms |
----------------------------- |
|
If you want to port the library to other platforms you only have to follow |
these steps: |
|
* Create a new python file called SerialPort_XXXX.py in which you |
implement the same public classes and methods found in the SerialPort_win |
and SerialPort_linux modules. |
* Append the new platform to the uspp.py file. |
|
|
11. Licence |
---------- |
|
This code is released under the "LGPL" that can be found in |
http://www.gnu.org/copyleft/lesser.html or in the lesser.txt file that |
is with the library. |
If you use this software, I'd like to know about it. |
|
|
12. Author |
--------- |
|
This library has been created by Isaac Barona Martinez <ibarona@gmail.com>. |
|
|
13. Version |
---------- |
|
0.1 - 09/01/2001 (September 2001) |
0.2 - 05/13/2003 |
1.0 - 02/24/2006 |
|
|
/Uspp/uspp.htm
0,0 → 1,635
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title>ibarona - USPP(Universal Serial Port Python Library)</title> |
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
|
<style type="text/css"> |
#g_title p, #g_footer p, #g_description p { |
margin: 0; |
} |
/* |
|
-- -- -- -- -- -- -- |
Browser Fixes |
-- -- -- -- -- -- -- |
|
This file uses CSS filtering methods to fix various |
layout bugs. |
|
Each of the following three imported files is a |
separate, browser-specific CSS file that keeps all |
hacks out of the main style sheet. |
|
Over time, as supporting these browsers no longer |
remains a priority, cleaning up the hacks is as |
easy as deleting the @import statement below, or |
simply no longer linking this file from the HTML. |
|
*/ |
|
/* |
fix ie6 "peekaboo bug" using the "holly hack". |
Note, this style only gets applied to ie6 |
*/ |
* html .wrapper { |
height: 0.1%; |
} |
|
/* |
* IE5 mac - overrides the IE/Win hack |
*/ |
|
/*\*//*/ |
|
* html #threecolumn div { |
height: auto; |
} |
|
/**/ |
|
|
/* |
* IE5/Win-specific CSS -ensures #container wraps all content on window resize |
*/ |
|
@media tty { |
i{content:"\";/*" "*/}} * html #container { height: 1%; } /*";} |
}/* */ |
/* Styling for editable elements. Eventually, this will be part of the style. */ |
.editable { |
border: 1px dashed blue; |
} |
|
#footer { |
clear: both; |
} |
|
/* Extra divs hidden by default. The custom CSS can override this though */ |
#extraDiv1, #extraDiv2, #extraDiv3, #extraDiv4, #extraDiv5, #extraDiv6 { |
display: none; |
} |
|
/* |
-- -- -- -- -- -- -- |
1 Column Layout |
-- -- -- -- -- -- -- |
*/ |
|
/* Center #container, constrain to 718px width |
----------------------------------------------- */ |
body { |
text-align: center; |
} |
#container { |
width: 718px; |
text-align: left; |
margin: 0 auto; |
} |
|
#main-content { |
overflow: hidden; |
} |
|
/** BEGIN CUSTOM SKIN **/ |
/* |
|
-- -- -- -- -- -- -- |
Base CSS |
-- -- -- -- -- -- -- |
|
This file simply removes default styling on most HTML elements in |
order to reduce the need to later override them. |
|
*/ |
|
h1,h2,h3,h4,h5,h6,pre,code,p {font-size: 1em;} |
dl,li,dt,dd,h1,h2,h3,h4,h5,h6,pre,form,body,html,p,blockquote,fieldset,input {margin: 0; padding: 0;} |
a img,:link img,:visited img {border: none;} |
address {font-style: normal;}/* |
|
-- -- -- -- -- -- -- |
Type Scheme: Deco |
-- -- -- -- -- -- -- |
|
*/ |
|
body { |
font: 76% Verdana, sans-serif; |
} |
|
h1, h2, h3, h4, h5, h6, p.description { |
font-family: "Trebuchet MS", Trebuchet, sans-serif; |
} |
h1 { |
font-size: 3em; |
font-weight: bold; |
letter-spacing: 2px; |
} |
h2 { |
font-size: 2em; |
font-weight: normal; |
} |
h3 { |
font-size: 1.5em; |
} |
h4 { |
font-size: 1.2em; |
letter-spacing: 0.2em; |
} |
h5 { |
font-size: 1.2em; |
} |
h6 { |
font-size: 1em; |
font-weight: bold; |
} |
|
p, td { |
line-height: 1.8em; |
} |
code, kbd { |
font-size: 1.25em; |
}/* |
|
-- -- -- -- -- -- -- |
STYLE: Micro |
-- -- -- -- -- -- -- |
|
*/ |
|
|
|
|
/* ie6win */ |
|
/* IE/Win fixes for various layouts |
----------------------------------------------- */ |
* html #onecolumn #header { |
margin-right: -3px; |
} |
* html #onecolumn #header, |
* html #twocolumn-left #header, * html #twocolumn-right #header, |
* html #twocolumn-liquid-left #header, * html #twocolumn-liquid-right #header { |
padding-bottom: 1px; |
} |
* html #twocolumn-left #main-content, * html #twocolumn-right #main-content { |
width: 459px; |
} |
* html #threecolumn #main-content { |
width: 409px; |
} |
|
/* ie5mac */ |
|
/*\*//*/ |
/* Undoing IE/Win fixes |
----------------------------------------------- */ |
* html #onecolumn #header { |
margin-right: 0; |
} |
* html #twocolumn-left #header, * html #twocolumn-right #header, |
* html #twocolumn-liquid-left #header, * html #twocolumn-liquid-right #header { |
padding-bottom: 0; |
} |
* html #twocolumn-left #main-content, * html #twocolumn-right #main-content { |
width: 479px; |
} |
* html #threecolumn #main-content { |
width: 429px; |
} |
/**/ |
|
@media tty { |
i{content:"\";/*" "*/}} td { font-size: 0.8em; } /*";} |
}/* */ |
|
|
|
/* Basic HTML style |
----------------------------------------------- */ |
body { |
font: 76% "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif; |
color: #000; |
background: #fff; |
margin: 0; |
padding: 0; |
} |
blockquote { |
margin: 1em 2em; |
font-style: italic; |
} |
caption { |
font-weight: bold; |
color: #444; |
background: #ccc; |
border-bottom: 0; |
padding: 0.3em 1em; |
} |
dd { |
margin: 1em 2em; |
} |
dl { |
margin: 2em 0; |
} |
dt { |
font-weight: bold; |
} |
hr { |
margin: 2em 0; |
color: #C7C7C7; |
background: #C7C7C7; |
border-color: #C7C7C7; |
border-style: none; |
height: 1px; |
} |
li { |
margin: 1em 0; |
} |
table { |
border: solid 1px #ccc; |
} |
td { |
vertical-align: top; |
padding: 0.5em; |
} |
th { |
text-align: left; |
color: #fff; |
background: #777; |
padding: 0.5em; |
} |
ol, ul { |
margin: 2em 0; |
padding-left: 1em; |
} |
|
|
|
/* Nested HTML elements, and basic classes |
----------------------------------------------- */ |
ol li { |
list-style-type: decimal; |
margin-left: 2em; |
} |
ul li { |
margin-left: 2em; |
list-style-type: square; |
} |
td p { |
margin-top: 0; |
} |
|
|
|
/* Set the stage with main layout tweaks |
----------------------------------------------- */ |
#container { |
border: solid 7px #999; |
border-left: 0; |
border-right: 0; |
padding-top: 1px; |
} |
#header { |
color: #04172D; |
border-top: solid 3px #777; |
padding: 0; |
margin: 0 0 1.5em 0; |
} |
#main-content .wrapper { |
margin: 0; |
} |
.description { |
font: normal 1em "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif; |
color: #444; |
background: #C7C7C7; |
padding: 3px 25px 2.2em 25px; |
margin: 0; |
line-height: 1; |
} |
#footer { |
clear: both; |
color: #999; |
padding: 0 1em 1em 1em; |
border-bottom: solid 3px #777; |
margin-bottom: 1px; |
} |
|
|
/* Content area offset |
----------------------------------------------- */ |
#main-content .wrapper { |
padding: 0 25px; |
} |
|
#main-content td p { |
margin: 0 0 1em 0; |
} |
|
|
|
/* Custom font definitions |
----------------------------------------------- */ |
p { |
margin: 1em 0; |
line-height: 1.5; |
} |
h1,h2,h3,h4,h5,h6 { |
font-family: "Trebuchet MS", arial, sans-serif; |
} |
h1 { |
color: #B2B2B2; |
font-size: 2.4em; |
letter-spacing: 0.2em; |
font-weight: normal; |
padding: 1em 25px 0 25px; |
} |
h2 { |
margin: 0 0 0.5em 0; |
color: #777; |
font-size: 1.4em; |
font-weight: normal; |
border-bottom: double 3px #C7C7C7; |
padding: 0 0 0.4em 0; |
} |
h3 { |
font-size: 1.2em; |
background: #eee; |
border: dotted 1px #C7C7C7; |
padding: 0.2em; |
} |
h4 { |
font-size: 1.2em; |
padding: 0 0 0.2em 0; |
margin: 0.6em 0 0 0.4em; |
color: #777; |
} |
h5 { |
border-bottom: dotted 1px #C7C7C7; |
} |
h6 { |
color: #777; |
border-left: solid 1.2em #777; |
padding-left: 0.6em; |
} |
|
a:link { |
color: #9db2df; |
} |
a:hover { |
text-decoration: none; |
border-bottom: 1px dotted #bb242d; |
background-color: #e0e0e0; |
} |
|
|
/* Sidebar |
----------------------------------------------- */ |
#sidebar h3, #sidebar-alternate h3 { |
margin: 0; |
color: #777; |
background: none; |
font-size: 1.4em; |
font-weight: normal; |
border: none; |
padding: 0; |
} |
|
#sidebar blockquote, #sidebar blockquote p, |
#sidebar-alternate blockquote, #sidebar-alternate blockquote p { |
margin-left: 0; |
margin-right: 0; |
} |
#sidebar blockquote { |
margin: 1em 0; |
padding: 0; |
} |
#adsense { |
text-align: center; |
} |
|
|
|
.editable { |
border: dashed 1px #c33; |
} |
|
|
|
|
/* Tweaks for Two-column Right layout |
----------------------------------------------- */ |
#twocolumn-right #sidebar .wrapper { |
margin: 0 10px; |
} |
|
|
|
/* Tweaks for Two-column Left layout |
----------------------------------------------- */ |
#twocolumn-left #sidebar .wrapper { |
margin: 0 10px; |
} |
|
|
/* Tweaks for Three-column layout |
----------------------------------------------- */ |
#threecolumn #sidebar .wrapper { |
margin: 0 10px; |
} |
#threecolumn #sidebar-alternate .wrapper { |
margin: 0 10px; |
} |
/* |
|
-- -- -- -- -- -- -- |
COLOR SCHEME: Blueprint |
-- -- -- -- -- -- -- |
|
*/ |
|
|
/* Basic HTML style |
----------------------------------------------- */ |
a:link { |
color: #445AA9; |
} |
a:visited { |
color: #283D88; |
} |
body { |
color: #283769; |
background: #ECEEF6; |
} |
caption { |
color: inherit; |
background: #ECEEF6; |
} |
hr { |
color: #C7C7C7; |
background: #C7C7C7; |
border-color: #C7C7C7; |
} |
table { |
background: #fff; |
border-color: #B3BCDC; |
} |
th { |
color: #fff; |
background: #445AA9; |
} |
|
|
|
/* Set the stage with main layout tweaks |
----------------------------------------------- */ |
#container { |
background-color: #F6F7FB; |
border-color: #6678B8; |
} |
#header { |
color: #445AA9; |
border-top-color: #6678B8; |
} |
.description { |
color: #445AA9; |
background: #C9D0E6; |
} |
#footer { |
color: #5064AE; |
border-bottom-color: #6678B8; |
} |
|
|
|
/* Custom font definitions |
----------------------------------------------- */ |
h1 { |
color: #445AA9; |
} |
h2 { |
color: #5064AE; |
border-bottom-color: #B3BCDC; |
} |
h3 { |
background: #ECEEF6; |
border-color: #C9D0E6; |
} |
h4 { |
border-bottom-color: #B3BCDC; |
color: #1A4292; |
} |
h5 { |
border-bottom-color: #C7C7C7; |
} |
h6 { |
color: #5064AE; |
border-left-color: #B3BCDC; |
} |
|
|
|
|
|
/* Sidebar |
----------------------------------------------- */ |
#sidebar h3, #sidebar-alternate h3 { |
color: #5064AE; |
background: none; |
} |
/** END CUSTOM SKIN **/ |
</style><!-- Hack to avoid flash of unstyled content in IE --> |
|
|
<script> </script></head><body id="onecolumn"> |
<div id="container"> |
<div class="wrapper"> |
<div id="header"> |
<div class="wrapper"> |
<h1 id="page-title"><div id="g_title">USPP(Universal Serial Port Python Library)<br></div></h1> |
<div style="clear: both;"></div> |
<p class="description"></p><div id="g_description"><p>Isaac Barona (ibarona@gmail.com) </p></div> |
<div style="clear: both;"></div> |
</div> |
</div> |
|
<div id="main-content"> |
<div class="wrapper"> |
<div class="content-item"><div id="g_body"><h2>Introduction</h2><p><i>USPP Library </i>is a multi-platform Python module to access serial ports. |
At the moment, it only works in Windows, Linux and MacOS but as it is written entirely in Python (doesn't wrap any C/C++ |
library) I hope you can extend it to support any other platforms. </p><h2>Motivation</h2><p> |
I like very much to make electronic widgets with microcontrollers, specially |
those that can be connected to the computer to send and receive data. |
</p><p>Some months ago, I discovered Python and inmediatelly liked it a lot. |
I started playing with it and saw that I could use it to make prototypes of |
comunication protocols between computer and microcontrollers really |
fast and easily than using C. At the same time, I was interested in |
working over different platforms. |
</p><p>I started looking for Python modules to access serial port and I found |
the following projects: |
</p><ul><li><i>win32comport_demo</i> from the win32 extension module</li><li><i>win32comm</i> module of wheineman@uconect.net</li><li><i>Sio Module </i>of Roger Rurnham (rburnham@cri-inc.com)</li><li><i>pyxal (Python X10 Abstraction Layer) </i>of Les Smithson (lsmithson@open-networks.co.uk)</li></ul><p>but they were not multi-platform, were just a wrap of propietary libraries or |
were just simple examples of serial port access. |
</p><p>For these reasons and also for learning more Python, I decided to start |
this project. Of course, I have used all this projects as reference to |
my module and so, I want to thanks the authors for their excellent work and |
for allowing us to study the code. |
I hope you enjoy using the uspp module as much as I am enjoying doing it.</p><h2>Features</h2><p> |
This module has the following features: |
</p><ul><li>hight level access to serial port under several platforms.</li><li>autodetects the platform in which it is working and exports the correct |
classes for that platform.</li><li>object oriented approach.</li><li>file object semantic operations over the ports.</li><li>allows using the serial port with different speeds and |
characteristics.</li><li>RS-232 and RS-485 modes (now only RS-232). In RS-485 mode the communication |
is half-duplex and uses the RTS line to control the direction of the |
transference.</li><li>blocking, non-blocking or configurable timeout reads.</li></ul><h2> Prerequisites</h2><p>You need the following to use the library: |
</p><ul><li>Python 2.1 or better</li><li>In windows you need the win32 extension modules. You can get it from <a href="http://sourceforge.net/projects/pywin32/">here</a>.<br></li></ul><h2>Usage and documentation</h2><p>You only have to import in your program the <i>uspp</i> module and automatically |
it loads the correct classes for the platform in which you are running |
the program. |
|
</p><p>First of all you have to create a <i>SerialPort</i> object with the settings you |
want. If a <i>SerialPortException</i> is not generated then you just can |
use the read and write methods of the object to read and write to |
the serial port. |
|
</p><p>Example: |
|
</p><pre><tt><br>>>> from uspp import *<br>>>> tty=SerialPort("COM2", 1000, 9600) <br>>>> # Opens COM2 at 9600 bps and with a read timeout of 1 second.<br>>>> tty.write("a") # Writes a character to the COM2 port<br>>>> # Now suppose we receive the string "abc"<br>>>> tty.inWaiting()<br>3<br>>>> tty.read()<br>'a'<br>>>> tty.inWaiting()<br>2<br>>>> tty.read(2)<br>'bc'<br></tt></pre> |
|
<p>Documentation of the different classes and methods can be found on |
uspp module docstring.</p><h2>Where does it works? </h2><p> |
The library has been tested in Windows 95, Windows XP and Windows 2000 machines with Python 2.0+ |
and in a Linux (2.0.34 and 2.4.20 kernels) machine with Python 2.1+.</p><h2>Porting to other frameworks</h2><p> |
If you want to port the library to other platforms you only have to follow |
these steps: |
</p><ul><li>Create a new python file called <i>SerialPort_XXXX.py </i>in which you |
implement the same public classes and methods found in the |
<i>SerialPort_win</i> |
and <i>SerialPort_linux</i> modules.</li><li>Append the new platform to the <i>uspp.py</i> file.</li></ul><h2>License </h2><p> |
This code is released under the "GPL" that can be found in |
<a href="http://www.gnu.org/copyleft/gpl.html%20">http://www.gnu.org/copyleft/gpl.html </a>or in the GPL.txt file that |
is with the library. |
</p><p>If you use this software, I'd like to know about it.</p><h2> Author</h2><p> |
This library has been created by Isaac Barona Martínez |
<a href="mailto:ibarona%20at%20gmail.com">(ibarona at gmail.com)</a> </p><h2>Versions <br></h2><h3>Version 1.0 - 02/24/2006 (February 2006) </h3><p>Lot |
to time after 0.1 version I have enouth time to publish the final |
version of the library. This version correct some bugs of 0.1 version, |
works in MacOS and have been extended.</p><p>The library contains more functions in Linux and MacOS platforms than in Windows platform. </p><p>I have to thanks a lot of people his contribution to the library, especially:</p><ul><li>Damien Geranton <dgeranton at voila.fr> </li><li>Douglas Jones <dfj23 at drexel.edu></li><li> J.Grauheding <juergen.grauheding at a-city.de> </li></ul><p> Files:</p><ul><ul><li>Zip file: uspp-0_1.zip</li><li>tar.gz file: uspp-0_1.tar.gz</li></ul></ul><h4> </h4><h3>Version 0.1 - 09/01/2001 (September 2001)</h3><p></p></div></div> |
<div style="clear: both;"></div> |
</div> |
</div> |
|
<div id="footer"><div class="wrapper"> |
<hr> |
<p></p><div id="g_footer"> </div> |
<div style="clear: both;"></div> |
</div></div> |
|
</div> |
</div> |
|
|
<div id="extraDiv1"><span></span></div><div id="extraDiv2"><span></span></div> |
<div id="extraDiv3"><span></span></div><div id="extraDiv4"><span></span></div> |
<div id="extraDiv5"><span></span></div><div id="extraDiv6"><span></span></div> |
|
</body></html> |
/readme.txt
0,0 → 1,11
Linux: |
On linux only python installation is needed |
and usually python is included. |
|
|
Windows: |
To use the python script on windows |
Python for Windows extensions have to be installed |
|
http://sourceforge.net/projects/pywin32 |
|
/AUTHORS
0,0 → 1,11
|
/Copyright
0,0 → 1,21
USPP Library (Universal Serial Port Python Library) |
|
Copyright (C) 2006 Artec Design <jyrit@artecdesign.ee> |
|
This is free software; you can redistribute it and/or |
modify it under the terms of the GNU Lesser General Public |
License as published by the Free Software Foundation; either |
version 2.1 of the License, or (at your option) any later version. |
|
This software is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
Lesser General Public License for more details. |
|
You should have received a copy of the GNU Lesser General Public |
License along with this library; if not, write to the Free Software |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
The complete text of the GNU Lesser General Public License can be found in |
the file 'lesser.txt'. |
/lesser.txt
0,0 → 1,504
GNU LESSER GENERAL PUBLIC LICENSE |
Version 2.1, February 1999 |
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc. |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Everyone is permitted to copy and distribute verbatim copies |
of this license document, but changing it is not allowed. |
|
[This is the first released version of the Lesser GPL. It also counts |
as the successor of the GNU Library Public License, version 2, hence |
the version number 2.1.] |
|
Preamble |
|
The licenses for most software are designed to take away your |
freedom to share and change it. By contrast, the GNU General Public |
Licenses are intended to guarantee your freedom to share and change |
free software--to make sure the software is free for all its users. |
|
This license, the Lesser General Public License, applies to some |
specially designated software packages--typically libraries--of the |
Free Software Foundation and other authors who decide to use it. You |
can use it too, but we suggest you first think carefully about whether |
this license or the ordinary General Public License is the better |
strategy to use in any particular case, based on the explanations below. |
|
When we speak of free software, we are referring to freedom of use, |
not price. Our General Public Licenses are designed to make sure that |
you have the freedom to distribute copies of free software (and charge |
for this service if you wish); that you receive source code or can get |
it if you want it; that you can change the software and use pieces of |
it in new free programs; and that you are informed that you can do |
these things. |
|
To protect your rights, we need to make restrictions that forbid |
distributors to deny you these rights or to ask you to surrender these |
rights. These restrictions translate to certain responsibilities for |
you if you distribute copies of the library or if you modify it. |
|
For example, if you distribute copies of the library, whether gratis |
or for a fee, you must give the recipients all the rights that we gave |
you. You must make sure that they, too, receive or can get the source |
code. If you link other code with the library, you must provide |
complete object files to the recipients, so that they can relink them |
with the library after making changes to the library and recompiling |
it. And you must show them these terms so they know their rights. |
|
We protect your rights with a two-step method: (1) we copyright the |
library, and (2) we offer you this license, which gives you legal |
permission to copy, distribute and/or modify the library. |
|
To protect each distributor, we want to make it very clear that |
there is no warranty for the free library. Also, if the library is |
modified by someone else and passed on, the recipients should know |
that what they have is not the original version, so that the original |
author's reputation will not be affected by problems that might be |
introduced by others. |
|
Finally, software patents pose a constant threat to the existence of |
any free program. We wish to make sure that a company cannot |
effectively restrict the users of a free program by obtaining a |
restrictive license from a patent holder. Therefore, we insist that |
any patent license obtained for a version of the library must be |
consistent with the full freedom of use specified in this license. |
|
Most GNU software, including some libraries, is covered by the |
ordinary GNU General Public License. This license, the GNU Lesser |
General Public License, applies to certain designated libraries, and |
is quite different from the ordinary General Public License. We use |
this license for certain libraries in order to permit linking those |
libraries into non-free programs. |
|
When a program is linked with a library, whether statically or using |
a shared library, the combination of the two is legally speaking a |
combined work, a derivative of the original library. The ordinary |
General Public License therefore permits such linking only if the |
entire combination fits its criteria of freedom. The Lesser General |
Public License permits more lax criteria for linking other code with |
the library. |
|
We call this license the "Lesser" General Public License because it |
does Less to protect the user's freedom than the ordinary General |
Public License. It also provides other free software developers Less |
of an advantage over competing non-free programs. These disadvantages |
are the reason we use the ordinary General Public License for many |
libraries. However, the Lesser license provides advantages in certain |
special circumstances. |
|
For example, on rare occasions, there may be a special need to |
encourage the widest possible use of a certain library, so that it becomes |
a de-facto standard. To achieve this, non-free programs must be |
allowed to use the library. A more frequent case is that a free |
library does the same job as widely used non-free libraries. In this |
case, there is little to gain by limiting the free library to free |
software only, so we use the Lesser General Public License. |
|
In other cases, permission to use a particular library in non-free |
programs enables a greater number of people to use a large body of |
free software. For example, permission to use the GNU C Library in |
non-free programs enables many more people to use the whole GNU |
operating system, as well as its variant, the GNU/Linux operating |
system. |
|
Although the Lesser General Public License is Less protective of the |
users' freedom, it does ensure that the user of a program that is |
linked with the Library has the freedom and the wherewithal to run |
that program using a modified version of the Library. |
|
The precise terms and conditions for copying, distribution and |
modification follow. Pay close attention to the difference between a |
"work based on the library" and a "work that uses the library". The |
former contains code derived from the library, whereas the latter must |
be combined with the library in order to run. |
|
GNU LESSER GENERAL PUBLIC LICENSE |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
|
0. This License Agreement applies to any software library or other |
program which contains a notice placed by the copyright holder or |
other authorized party saying it may be distributed under the terms of |
this Lesser General Public License (also called "this License"). |
Each licensee is addressed as "you". |
|
A "library" means a collection of software functions and/or data |
prepared so as to be conveniently linked with application programs |
(which use some of those functions and data) to form executables. |
|
The "Library", below, refers to any such software library or work |
which has been distributed under these terms. A "work based on the |
Library" means either the Library or any derivative work under |
copyright law: that is to say, a work containing the Library or a |
portion of it, either verbatim or with modifications and/or translated |
straightforwardly into another language. (Hereinafter, translation is |
included without limitation in the term "modification".) |
|
"Source code" for a work means the preferred form of the work for |
making modifications to it. For a library, complete source code means |
all the source code for all modules it contains, plus any associated |
interface definition files, plus the scripts used to control compilation |
and installation of the library. |
|
Activities other than copying, distribution and modification are not |
covered by this License; they are outside its scope. The act of |
running a program using the Library is not restricted, and output from |
such a program is covered only if its contents constitute a work based |
on the Library (independent of the use of the Library in a tool for |
writing it). Whether that is true depends on what the Library does |
and what the program that uses the Library does. |
|
1. You may copy and distribute verbatim copies of the Library's |
complete source code as you receive it, in any medium, provided that |
you conspicuously and appropriately publish on each copy an |
appropriate copyright notice and disclaimer of warranty; keep intact |
all the notices that refer to this License and to the absence of any |
warranty; and distribute a copy of this License along with the |
Library. |
|
You may charge a fee for the physical act of transferring a copy, |
and you may at your option offer warranty protection in exchange for a |
fee. |
|
2. You may modify your copy or copies of the Library or any portion |
of it, thus forming a work based on the Library, and copy and |
distribute such modifications or work under the terms of Section 1 |
above, provided that you also meet all of these conditions: |
|
a) The modified work must itself be a software library. |
|
b) You must cause the files modified to carry prominent notices |
stating that you changed the files and the date of any change. |
|
c) You must cause the whole of the work to be licensed at no |
charge to all third parties under the terms of this License. |
|
d) If a facility in the modified Library refers to a function or a |
table of data to be supplied by an application program that uses |
the facility, other than as an argument passed when the facility |
is invoked, then you must make a good faith effort to ensure that, |
in the event an application does not supply such function or |
table, the facility still operates, and performs whatever part of |
its purpose remains meaningful. |
|
(For example, a function in a library to compute square roots has |
a purpose that is entirely well-defined independent of the |
application. Therefore, Subsection 2d requires that any |
application-supplied function or table used by this function must |
be optional: if the application does not supply it, the square |
root function must still compute square roots.) |
|
These requirements apply to the modified work as a whole. If |
identifiable sections of that work are not derived from the Library, |
and can be reasonably considered independent and separate works in |
themselves, then this License, and its terms, do not apply to those |
sections when you distribute them as separate works. But when you |
distribute the same sections as part of a whole which is a work based |
on the Library, the distribution of the whole must be on the terms of |
this License, whose permissions for other licensees extend to the |
entire whole, and thus to each and every part regardless of who wrote |
it. |
|
Thus, it is not the intent of this section to claim rights or contest |
your rights to work written entirely by you; rather, the intent is to |
exercise the right to control the distribution of derivative or |
collective works based on the Library. |
|
In addition, mere aggregation of another work not based on the Library |
with the Library (or with a work based on the Library) on a volume of |
a storage or distribution medium does not bring the other work under |
the scope of this License. |
|
3. You may opt to apply the terms of the ordinary GNU General Public |
License instead of this License to a given copy of the Library. To do |
this, you must alter all the notices that refer to this License, so |
that they refer to the ordinary GNU General Public License, version 2, |
instead of to this License. (If a newer version than version 2 of the |
ordinary GNU General Public License has appeared, then you can specify |
that version instead if you wish.) Do not make any other change in |
these notices. |
|
Once this change is made in a given copy, it is irreversible for |
that copy, so the ordinary GNU General Public License applies to all |
subsequent copies and derivative works made from that copy. |
|
This option is useful when you wish to copy part of the code of |
the Library into a program that is not a library. |
|
4. You may copy and distribute the Library (or a portion or |
derivative of it, under Section 2) in object code or executable form |
under the terms of Sections 1 and 2 above provided that you accompany |
it with the complete corresponding machine-readable source code, which |
must be distributed under the terms of Sections 1 and 2 above on a |
medium customarily used for software interchange. |
|
If distribution of object code is made by offering access to copy |
from a designated place, then offering equivalent access to copy the |
source code from the same place satisfies the requirement to |
distribute the source code, even though third parties are not |
compelled to copy the source along with the object code. |
|
5. A program that contains no derivative of any portion of the |
Library, but is designed to work with the Library by being compiled or |
linked with it, is called a "work that uses the Library". Such a |
work, in isolation, is not a derivative work of the Library, and |
therefore falls outside the scope of this License. |
|
However, linking a "work that uses the Library" with the Library |
creates an executable that is a derivative of the Library (because it |
contains portions of the Library), rather than a "work that uses the |
library". The executable is therefore covered by this License. |
Section 6 states terms for distribution of such executables. |
|
When a "work that uses the Library" uses material from a header file |
that is part of the Library, the object code for the work may be a |
derivative work of the Library even though the source code is not. |
Whether this is true is especially significant if the work can be |
linked without the Library, or if the work is itself a library. The |
threshold for this to be true is not precisely defined by law. |
|
If such an object file uses only numerical parameters, data |
structure layouts and accessors, and small macros and small inline |
functions (ten lines or less in length), then the use of the object |
file is unrestricted, regardless of whether it is legally a derivative |
work. (Executables containing this object code plus portions of the |
Library will still fall under Section 6.) |
|
Otherwise, if the work is a derivative of the Library, you may |
distribute the object code for the work under the terms of Section 6. |
Any executables containing that work also fall under Section 6, |
whether or not they are linked directly with the Library itself. |
|
6. As an exception to the Sections above, you may also combine or |
link a "work that uses the Library" with the Library to produce a |
work containing portions of the Library, and distribute that work |
under terms of your choice, provided that the terms permit |
modification of the work for the customer's own use and reverse |
engineering for debugging such modifications. |
|
You must give prominent notice with each copy of the work that the |
Library is used in it and that the Library and its use are covered by |
this License. You must supply a copy of this License. If the work |
during execution displays copyright notices, you must include the |
copyright notice for the Library among them, as well as a reference |
directing the user to the copy of this License. Also, you must do one |
of these things: |
|
a) Accompany the work with the complete corresponding |
machine-readable source code for the Library including whatever |
changes were used in the work (which must be distributed under |
Sections 1 and 2 above); and, if the work is an executable linked |
with the Library, with the complete machine-readable "work that |
uses the Library", as object code and/or source code, so that the |
user can modify the Library and then relink to produce a modified |
executable containing the modified Library. (It is understood |
that the user who changes the contents of definitions files in the |
Library will not necessarily be able to recompile the application |
to use the modified definitions.) |
|
b) Use a suitable shared library mechanism for linking with the |
Library. A suitable mechanism is one that (1) uses at run time a |
copy of the library already present on the user's computer system, |
rather than copying library functions into the executable, and (2) |
will operate properly with a modified version of the library, if |
the user installs one, as long as the modified version is |
interface-compatible with the version that the work was made with. |
|
c) Accompany the work with a written offer, valid for at |
least three years, to give the same user the materials |
specified in Subsection 6a, above, for a charge no more |
than the cost of performing this distribution. |
|
d) If distribution of the work is made by offering access to copy |
from a designated place, offer equivalent access to copy the above |
specified materials from the same place. |
|
e) Verify that the user has already received a copy of these |
materials or that you have already sent this user a copy. |
|
For an executable, the required form of the "work that uses the |
Library" must include any data and utility programs needed for |
reproducing the executable from it. However, as a special exception, |
the materials to be distributed need not include anything that is |
normally distributed (in either source or binary form) with the major |
components (compiler, kernel, and so on) of the operating system on |
which the executable runs, unless that component itself accompanies |
the executable. |
|
It may happen that this requirement contradicts the license |
restrictions of other proprietary libraries that do not normally |
accompany the operating system. Such a contradiction means you cannot |
use both them and the Library together in an executable that you |
distribute. |
|
7. You may place library facilities that are a work based on the |
Library side-by-side in a single library together with other library |
facilities not covered by this License, and distribute such a combined |
library, provided that the separate distribution of the work based on |
the Library and of the other library facilities is otherwise |
permitted, and provided that you do these two things: |
|
a) Accompany the combined library with a copy of the same work |
based on the Library, uncombined with any other library |
facilities. This must be distributed under the terms of the |
Sections above. |
|
b) Give prominent notice with the combined library of the fact |
that part of it is a work based on the Library, and explaining |
where to find the accompanying uncombined form of the same work. |
|
8. You may not copy, modify, sublicense, link with, or distribute |
the Library except as expressly provided under this License. Any |
attempt otherwise to copy, modify, sublicense, link with, or |
distribute the Library is void, and will automatically terminate your |
rights under this License. However, parties who have received copies, |
or rights, from you under this License will not have their licenses |
terminated so long as such parties remain in full compliance. |
|
9. You are not required to accept this License, since you have not |
signed it. However, nothing else grants you permission to modify or |
distribute the Library or its derivative works. These actions are |
prohibited by law if you do not accept this License. Therefore, by |
modifying or distributing the Library (or any work based on the |
Library), you indicate your acceptance of this License to do so, and |
all its terms and conditions for copying, distributing or modifying |
the Library or works based on it. |
|
10. Each time you redistribute the Library (or any work based on the |
Library), the recipient automatically receives a license from the |
original licensor to copy, distribute, link with or modify the Library |
subject to these terms and conditions. You may not impose any further |
restrictions on the recipients' exercise of the rights granted herein. |
You are not responsible for enforcing compliance by third parties with |
this License. |
|
11. If, as a consequence of a court judgment or allegation of patent |
infringement or for any other reason (not limited to patent issues), |
conditions are imposed on you (whether by court order, agreement or |
otherwise) that contradict the conditions of this License, they do not |
excuse you from the conditions of this License. If you cannot |
distribute so as to satisfy simultaneously your obligations under this |
License and any other pertinent obligations, then as a consequence you |
may not distribute the Library at all. For example, if a patent |
license would not permit royalty-free redistribution of the Library by |
all those who receive copies directly or indirectly through you, then |
the only way you could satisfy both it and this License would be to |
refrain entirely from distribution of the Library. |
|
If any portion of this section is held invalid or unenforceable under any |
particular circumstance, the balance of the section is intended to apply, |
and the section as a whole is intended to apply in other circumstances. |
|
It is not the purpose of this section to induce you to infringe any |
patents or other property right claims or to contest validity of any |
such claims; this section has the sole purpose of protecting the |
integrity of the free software distribution system which is |
implemented by public license practices. Many people have made |
generous contributions to the wide range of software distributed |
through that system in reliance on consistent application of that |
system; it is up to the author/donor to decide if he or she is willing |
to distribute software through any other system and a licensee cannot |
impose that choice. |
|
This section is intended to make thoroughly clear what is believed to |
be a consequence of the rest of this License. |
|
12. If the distribution and/or use of the Library is restricted in |
certain countries either by patents or by copyrighted interfaces, the |
original copyright holder who places the Library under this License may add |
an explicit geographical distribution limitation excluding those countries, |
so that distribution is permitted only in or among countries not thus |
excluded. In such case, this License incorporates the limitation as if |
written in the body of this License. |
|
13. The Free Software Foundation may publish revised and/or new |
versions of the Lesser General Public License from time to time. |
Such new versions will be similar in spirit to the present version, |
but may differ in detail to address new problems or concerns. |
|
Each version is given a distinguishing version number. If the Library |
specifies a version number of this License which applies to it and |
"any later version", you have the option of following the terms and |
conditions either of that version or of any later version published by |
the Free Software Foundation. If the Library does not specify a |
license version number, you may choose any version ever published by |
the Free Software Foundation. |
|
14. If you wish to incorporate parts of the Library into other free |
programs whose distribution conditions are incompatible with these, |
write to the author to ask for permission. For software which is |
copyrighted by the Free Software Foundation, write to the Free |
Software Foundation; we sometimes make exceptions for this. Our |
decision will be guided by the two goals of preserving the free status |
of all derivatives of our free software and of promoting the sharing |
and reuse of software generally. |
|
NO WARRANTY |
|
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO |
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. |
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR |
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY |
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME |
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
|
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN |
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY |
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU |
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
DAMAGES. |
|
END OF TERMS AND CONDITIONS |
|
How to Apply These Terms to Your New Libraries |
|
If you develop a new library, and you want it to be of the greatest |
possible use to the public, we recommend making it free software that |
everyone can redistribute and change. You can do so by permitting |
redistribution under these terms (or, alternatively, under the terms of the |
ordinary General Public License). |
|
To apply these terms, attach the following notices to the library. It is |
safest to attach them to the start of each source file to most effectively |
convey the exclusion of warranty; and each file should have at least the |
"copyright" line and a pointer to where the full notice is found. |
|
<one line to give the library's name and a brief idea of what it does.> |
Copyright (C) <year> <name of author> |
|
This library is free software; you can redistribute it and/or |
modify it under the terms of the GNU Lesser General Public |
License as published by the Free Software Foundation; either |
version 2.1 of the License, or (at your option) any later version. |
|
This library is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
Lesser General Public License for more details. |
|
You should have received a copy of the GNU Lesser General Public |
License along with this library; if not, write to the Free Software |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
Also add information on how to contact you by electronic and paper mail. |
|
You should also get your employer (if you work as a programmer) or your |
school, if any, to sign a "copyright disclaimer" for the library, if |
necessary. Here is a sample; alter the names: |
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the |
library `Frob' (a library for tweaking knobs) written by James Random Hacker. |
|
<signature of Ty Coon>, 1 April 1990 |
Ty Coon, President of Vice |
|
That's all there is to it! |
|
|