gsmopen: adding libctb-0.16

This commit is contained in:
Giovanni Maruzzelli committed 2012-04-02 11:07:47 +02:00
1 parent fc4c61570b
commit 282a1885e7
59 files changed
+15449

No files matched your search

@@ -0,0 +1,455 @@
import wxctb, sys, re
DCD = wxctb.LinestateDcd
CTS = wxctb.LinestateCts
DSR = wxctb.LinestateDsr
DTR = wxctb.LinestateDtr
RING = wxctb.LinestateRing
RTS = wxctb.LinestateRts
NULL = wxctb.LinestateNull
def abstract():
import inspect
caller = inspect.getouterframes(inspect.currentframe())[1][3]
raise NotImplementedError(caller + ' must be implemented in subclass')
class IOBase:
def __init__(self):
self.device = None
# set timeout to 1000ms (the default)
self.timeout = 1000
def __del__(self):
pass
def Close(self):
if self.device:
self.device.Close()
def GetTimeout(self):
"""
Returns the internal timeout value in milliseconds
"""
return self.timeout
def Ioctl(self,cmd,arg):
if self.device:
self.device.Ioctl(cmd,arg)
def Open(self):
abstract()
def PutBack(self,char):
return self.device.PutBack(char)
def Read(self,length):
"""
Try to read the given count of data (length) and returns the
successfully readed number of data. The function never blocks.
For example:
readed = dev.Read(100)
"""
buf = "\x00"*(length+1)
rd = self.device.Read(buf,length)
return buf[0:rd]
def ReadBinary(self,eos="\n"):
"""
Special SCPI command. Read the next data coded as a SCPI
binary format.
A binary data transfer will be startet by '#'. The next byte
tells the count of bytes for the binary length header,
following by the length bytes. After these the data begins.
For example:
#500004xxxx
The header length covers 5 Byte, the length of the binary
data is 4 (x means the binary data bytes)
"""
try:
eoslen = len(eos)
b=self.Readv(2)
if len(b) == 2:
hl = int(b[1])
b = self.Readv(hl)
if len(b) == hl:
dl = int(b)
# don't left over the eos string or character in the
# device input buffer
data = self.Readv(dl+eoslen)
# check, if the binary data block is complete
if data[dl] == '#':
# not complete, another block is following
for c in data[dl:dl+eoslen]:
self.PutBack(c)
data = data[:dl] + self.ReadBinary()
return data
except:
pass
return ''
def ReadUntilEOS(self,eos="\n",quota=0):
"""
ReadUntilEOS(eosString=\"\\n\",timeout=1000)
Reads data until the given eos string was received (default is
the linefeed character (0x0a) or the internal timeout
(default 1000ms) was reached.
ReadUntilEOS returns the result as the following tuple:
['received string',state,readedBytes]
If a timeout occurred, state is 0, otherwise 1
"""
return self.device.ReadUntilEOS("",0,eos,self.timeout,quota)
def Readv(self,length):
"""
Try to read the given count of data. Readv blocks until all data
was readed successfully or the internal timeout, set with the
class member function SetTimeout(timeout), was reached.
Returns the readed data.
"""
buf = "\x00"*length
rd = self.device.Readv(buf,length,self.timeout)
return buf[0:rd]
def ResetBus(self):
"""
If the underlaying interface needs some special reset operations
(for instance the GPIB distinguish between a normal device reset
and a special bus reset), you can put some code here)
"""
pass
def SetTimeout(self,timeout):
"""
Set the internal timeout value in milliseconds for all blocked
operations like ReadUntilEOS, Readv and Writev.
"""
self.timeout = timeout
def Write(self,string):
"""
Writes the given string to the device and returns immediately.
Write returns the number of data bytes successfully written or a
negativ number if an error occured. For some circumstances, not
the complete string was written.
So you have to verify the return value to check this out.
"""
return self.device.Write(string,len(string))
def Writev(self,string):
"""
Writes the given string to the device. The function blocks until
the complete string was written or the internal timeout, set with
SetTimeout(timeout), was reached.
Writev returns the number of data successfully written or a
negativ value, if an errors occurred.
"""
return self.device.Writev(string,len(string),self.timeout)
class SerialPort(IOBase):
def __init__(self):
IOBase.__init__(self)
def __del__(self):
self.Close()
def ChangeLineState(self,lineState):
"""
Change (toggle) the state of each the lines given in the
linestate parameter. Possible values are DTR and/or RTS.
For example to toggle the RTS line only:
dev.ChangeLineState(RTS)
"""
self.device.ChangeLineState(lineState)
def ClrLineState(self,lineState):
"""
Clear the lines given in the linestate parameter. Possible
values are DTR and/or RTS. For example to clear only
the RTS line:
dev.ClrLineState(RTS)
"""
self.device.ClrLineState(lineState)
def GetAvailableBytes(self):
"""
Returns the available bytes in the input queue of the serial
driver.
"""
n = wxctb.new_intp()
wxctb.intp_assign(n, 0)
self.device.Ioctl(wxctb.CTB_SER_GETINQUE,n)
return wxctb.intp_value(n)
def GetCommErrors(self):
"""
Get the internal communication errors like breaks, framing,
parity or overrun errors.
Returns the count of each error as a tuple like this:
(b,f,o,p) = dev.GetCommErrors()
b: breaks, f: framing errors, o: overruns, p: parity errors
"""
einfo = wxctb.SerialPort_EINFO()
self.device.Ioctl(wxctb.CTB_SER_GETEINFO,einfo)
return einfo.brk,einfo.frame,einfo.overrun,einfo.parity
def GetLineState(self):
"""
Returns the current linestates of the CTS, DCD, DSR and RING
signal line as an integer value with the appropriate bits or
-1 on error.
For example:
lines = dev.GetLineState()
if lines & CTS:
print \"CTS is on\"
"""
return self.device.GetLineState()
def Open(self,devname,baudrate,protocol='8N1',handshake='no_handshake'):
"""
Open the device devname with the given baudrate, the protocol
like '8N1' (default) and the use of the handshake [no_handshake
(default), rtscts or xonxoff]
For example:
At Linux:
dev = SerialPort()
dev.Open(\"/dev/ttyS0\",115200)
or with a datalen of 7 bits, even parity, 2 stopbits and rts/cts
handshake:
dev.Open(\"/dev/ttyS0\",115200,'7E2',True)
At Windows:
dev = SerialPort()
dev.Open(\"COM1\",115200)
dev.Open(\"COM1\",115200,'7E2',True)
Returns the handle on success or a negativ value on failure.
"""
# the following parity values are valid:
# N:None, O:Odd, E:Even, M:Mark, S:Space
parity = {'N':0,'O':1,'E':2,'M':3,'S':4}
# the regular expression ensures a valid value for the datalen
# (5...8 bit) and the count of stopbits (1,2)
reg=re.compile(r"(?P<w>[8765])"r"(?P<p>[NOEMS])"r"(?P<s>[12])")
self.device = wxctb.SerialPort()
dcs = wxctb.SerialPort_DCS()
dcs.baud = baudrate
res = reg.search(protocol)
# handle the given protocol
if res:
dcs.wordlen = int(res.group('w'))
dcs.stopbits = int(res.group('s'))
dcs.parity = parity[res.group('p')]
# valid handshake are no one, rts/cts or xon/xoff
if handshake == 'rtscts':
dcs.rtscts = True
elif handshake == 'xonxoff':
dcs.xonxoff = True
return self.device.Open(devname,dcs)
def Reset(self):
"""
Send a break for 0.25s.
"""
self.device.SendBreak(0)
def SetBaudrate(self,baudrate):
"""
Set the baudrate for the device.
"""
self.device.SetBaudrate(baudrate)
def SetLineState(self,lineState):
"""
Set the lines given in the linestate parameter. Possible
values are DTR and/or RTS. For example to set both:
dev.SetLineState( DTR | RTS)
"""
self.device.SetLineState(lineState)
def SetParityBit(self,parity):
"""
Set the parity bit explicitly to 0 or 1. Use this function, if
you would like to simulate a 9 bit wordlen at what the ninth bit
was represented by the parity bit value. For example:
dev.SetParityBit( 0 )
dev.Write('some data sent with parity 0')
dev.SetParityBit( 1 )
dev.Write('another sequence with parity 1')
"""
return self.device.SetParityBit( parity )
class GpibDevice(IOBase):
"""
GPIB class
"""
def __init__(self):
IOBase.__init__(self)
def __del__(self):
self.Close()
def FindListeners(self,board = 0):
"""
Returns the address of the connected devices as a list.
If no device is listening, the list is empty. If an error
occurs an IOError exception raised. For example:
g = GPIB()
listeners = g.FindListeners()
"""
listeners = wxctb.GPIB_x_FindListeners(board)
if listeners < 0:
raise IOError("GPIB board error")
result = []
for i in range(1,31):
if listeners & (1 << i):
result.append(i)
return result
def GetEosChar(self):
"""
Get the internal EOS termination character (see SetEosChar).
For example:
g = GPIB()
g.Open(\"gpib1\",1)
eos = g.GetEosChar()
"""
eos = wxctb.new_intp()
wxctb.intp_assign(eos, 0)
self.device.Ioctl(wxctb.CTB_GPIB_GET_EOS_CHAR,eos)
return wxctb.intp_value(eos)
def GetEosMode(self):
"""
Get the internal EOS mode (see SetEosMode).
For example:
g = GPIB()
g.Open(\"gpib1\",1)
eos = g.GetEosMode()
"""
mode = wxctb.new_intp()
wxctb.intp_assign(mode, 0)
self.device.Ioctl(wxctb.CTB_GPIB_GET_EOS_MODE,mode)
return wxctb.intp_value(mode)
def GetError(self):
errorString = " "*256
self.device.GetError(errorString,256)
return errorString
def GetSTB(self):
"""
Returns the value of the internal GPIB status byte register.
"""
stb = wxctb.new_intp()
wxctb.intp_assign(stb, 0)
self.device.Ioctl(wxctb.CTB_GPIB_GETRSP,stb)
return wxctb.intp_value(stb)
# This is only for internal usage!!!
def Ibrd(self,length):
buf = "\x00"*length
state = self.device.Ibrd(buf,length)
return state,buf
# This is only for internal usage!!!
def Ibwrt(self,string):
return self.device.Ibwrt(string,len(string))
def Open(self,devname,adr,eosChar=10,eosMode=0x08|0x04):
"""
Open(gpibdevice,address,eosChar,eosMode)
Opens a connected device at the GPIB bus. gpibdevice means the
controller, (mostly \"gpib1\"), address the address of the desired
device in the range 1...31. The eosChar defines the EOS character
(default is linefeed), eosMode may be a combination of bits ORed
together. The following bits can be used:
0x04: Terminate read when EOS is detected.
0x08: Set EOI (End or identify line) with EOS on write function
0x10: Compare all 8 bits of EOS byte rather than low 7 bits
(all read and write functions). Default is 0x12
For example:
dev = GPIB()
dev.Open(\"gpib1\",17)
Opens the device with the address 17, linefeed as EOS (default)
and eos mode with 0x04 and 0x08.
Open returns >= 0 or a negativ value, if something going wrong.
"""
self.device = wxctb.GpibDevice()
dcs = wxctb.Gpib_DCS()
dcs.m_address1 = adr
dcs.m_eosChar = eosChar
dcs.m_eosMode = eosMode
result = self.device.Open(devname,dcs)
return result
def Reset(self):
"""
Resets the connected device. In the GPIB definition, the device
should be reset to it's initial state, so you can restart a
formely lost communication.
"""
self.device.Ioctl(wxctb.CTB_RESET,None)
def ResetBus(self):
"""
The command asserts the GPIB interface clear (IFC) line for
ast least 100us if the GPIB board is the system controller.
This initializes the GPIB and makes the interface CIC and
active controller with ATN asserted.
Note! The IFC signal resets only the GPIB interface functions
of the bus devices and not the internal device functions.
For a device reset you should use the Reset() command above.
"""
self.device.Ioctl(wxctb.CTB_GPIB_RESET_BUS,None)
def SetEosChar(self,eos):
"""
Configure the end-of-string (EOS) termination character.
Note! Defining an EOS byte does not cause the driver to
automatically send that byte at the end of write I/O
operations. The application is responsible for placing the
EOS byte at the end of the data strings that it defines.
(National Instruments NI-488.2M Function Reference Manual)
For example:
g = GPIB()
g.Open(\"gpib1\",1)
eos = g.GetEosChar(0x10)
"""
intp = wxctb.new_intp()
wxctb.intp_assign(intp, eos)
return self.device.Ioctl(wxctb.CTB_GPIB_SET_EOS_CHAR,intp)
def SetEosMode(self,mode):
"""
Set the EOS mode (handling).m_eosMode may be a combination
of bits ORed together. The following bits can be used:
0x04: Terminate read when EOS is detected.
0x08: Set EOI (End or identify line) with EOS on write function
0x10: Compare all 8 bits of EOS byte rather than low 7 bits
(all read and write functions). For example:
g = GPIB()
g.Open(\"gpib1\",1)
eos = g.GetEosMode(0x04 | 0x08)
"""
intp = wxctb.new_intp()
wxctb.intp_assign(intp, mode)
return self.device.Ioctl(wxctb.CTB_GPIB_SET_EOS_MODE,intp)
def GetKey():
"""
Returns the current pressed key or '\0', if no key is pressed.
You can simply create a query loop with:
while GetKey() == '\0':
... make some stuff ...
"""
return wxctb.GetKey()
def GetVersion():
"""
Returns the version of the ctb python module. The numbering
has the following format: x.y.z
x.y means the version of the underlaying ctb lib, z the version
of the python port.
"""
return "0.16"
@@ -0,0 +1,264 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.40
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_wxctb', [dirname(__file__)])
except ImportError:
import _wxctb
return _wxctb
if fp is not None:
try:
_mod = imp.load_module('_wxctb', fp, pathname, description)
finally:
fp.close()
return _mod
_wxctb = swig_import_helper()
del swig_import_helper
else:
import _wxctb
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static) or hasattr(self,name):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)
def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0
def _swig_setattr_nondynamic_method(set):
def set_attr(self,name,value):
if (name == "thisown"): return self.this.own(value)
if hasattr(self,name) or (name == "this"):
set(self,name,value)
else:
raise AttributeError("You cannot add attributes to %s" % self)
return set_attr
def new_intp():
return _wxctb.new_intp()
new_intp = _wxctb.new_intp
def copy_intp(*args, **kwargs):
return _wxctb.copy_intp(*args, **kwargs)
copy_intp = _wxctb.copy_intp
def delete_intp(*args, **kwargs):
return _wxctb.delete_intp(*args, **kwargs)
delete_intp = _wxctb.delete_intp
def intp_assign(*args, **kwargs):
return _wxctb.intp_assign(*args, **kwargs)
intp_assign = _wxctb.intp_assign
def intp_value(*args, **kwargs):
return _wxctb.intp_value(*args, **kwargs)
intp_value = _wxctb.intp_value
class timer_control(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
__repr__ = _swig_repr
usecs = _swig_property(_wxctb.timer_control_usecs_get, _wxctb.timer_control_usecs_set)
exitflag = _swig_property(_wxctb.timer_control_exitflag_get, _wxctb.timer_control_exitflag_set)
exitfnc = _swig_property(_wxctb.timer_control_exitfnc_get, _wxctb.timer_control_exitfnc_set)
timer_control_swigregister = _wxctb.timer_control_swigregister
timer_control_swigregister(timer_control)
class Timer(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
def __init__(self, *args, **kwargs):
this = _wxctb.new_Timer(*args, **kwargs)
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _wxctb.delete_Timer
__del__ = lambda self : None;
def start(self): return _wxctb.Timer_start(self)
def stop(self): return _wxctb.Timer_stop(self)
Timer_swigregister = _wxctb.Timer_swigregister
Timer_swigregister(Timer)
def sleepms(*args, **kwargs):
return _wxctb.sleepms(*args, **kwargs)
sleepms = _wxctb.sleepms
CTB_RESET = _wxctb.CTB_RESET
class IOBase(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined - class is abstract")
__repr__ = _swig_repr
__swig_destroy__ = _wxctb.delete_IOBase
__del__ = lambda self : None;
def ClassName(self): return _wxctb.IOBase_ClassName(self)
def Close(self): return _wxctb.IOBase_Close(self)
def Ioctl(self, *args, **kwargs): return _wxctb.IOBase_Ioctl(self, *args, **kwargs)
def IsOpen(self): return _wxctb.IOBase_IsOpen(self)
def Open(self, *args, **kwargs): return _wxctb.IOBase_Open(self, *args, **kwargs)
def PutBack(self, *args, **kwargs): return _wxctb.IOBase_PutBack(self, *args, **kwargs)
def Read(self, *args, **kwargs): return _wxctb.IOBase_Read(self, *args, **kwargs)
def ReadUntilEOS(self, *args, **kwargs): return _wxctb.IOBase_ReadUntilEOS(self, *args, **kwargs)
def Readv(self, *args, **kwargs): return _wxctb.IOBase_Readv(self, *args, **kwargs)
def Write(self, *args, **kwargs): return _wxctb.IOBase_Write(self, *args, **kwargs)
def Writev(self, *args, **kwargs): return _wxctb.IOBase_Writev(self, *args, **kwargs)
IOBase_swigregister = _wxctb.IOBase_swigregister
IOBase_swigregister(IOBase)
ParityNone = _wxctb.ParityNone
ParityOdd = _wxctb.ParityOdd
ParityEven = _wxctb.ParityEven
ParityMark = _wxctb.ParityMark
ParitySpace = _wxctb.ParitySpace
LinestateDcd = _wxctb.LinestateDcd
LinestateCts = _wxctb.LinestateCts
LinestateDsr = _wxctb.LinestateDsr
LinestateDtr = _wxctb.LinestateDtr
LinestateRing = _wxctb.LinestateRing
LinestateRts = _wxctb.LinestateRts
LinestateNull = _wxctb.LinestateNull
class SerialPort_DCS(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
baud = _swig_property(_wxctb.SerialPort_DCS_baud_get, _wxctb.SerialPort_DCS_baud_set)
parity = _swig_property(_wxctb.SerialPort_DCS_parity_get, _wxctb.SerialPort_DCS_parity_set)
wordlen = _swig_property(_wxctb.SerialPort_DCS_wordlen_get, _wxctb.SerialPort_DCS_wordlen_set)
stopbits = _swig_property(_wxctb.SerialPort_DCS_stopbits_get, _wxctb.SerialPort_DCS_stopbits_set)
rtscts = _swig_property(_wxctb.SerialPort_DCS_rtscts_get, _wxctb.SerialPort_DCS_rtscts_set)
xonxoff = _swig_property(_wxctb.SerialPort_DCS_xonxoff_get, _wxctb.SerialPort_DCS_xonxoff_set)
buf = _swig_property(_wxctb.SerialPort_DCS_buf_get, _wxctb.SerialPort_DCS_buf_set)
def __init__(self):
this = _wxctb.new_SerialPort_DCS()
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _wxctb.delete_SerialPort_DCS
__del__ = lambda self : None;
def GetSettings(self): return _wxctb.SerialPort_DCS_GetSettings(self)
SerialPort_DCS_swigregister = _wxctb.SerialPort_DCS_swigregister
SerialPort_DCS_swigregister(SerialPort_DCS)
class SerialPort_EINFO(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
brk = _swig_property(_wxctb.SerialPort_EINFO_brk_get, _wxctb.SerialPort_EINFO_brk_set)
frame = _swig_property(_wxctb.SerialPort_EINFO_frame_get, _wxctb.SerialPort_EINFO_frame_set)
overrun = _swig_property(_wxctb.SerialPort_EINFO_overrun_get, _wxctb.SerialPort_EINFO_overrun_set)
parity = _swig_property(_wxctb.SerialPort_EINFO_parity_get, _wxctb.SerialPort_EINFO_parity_set)
def __init__(self):
this = _wxctb.new_SerialPort_EINFO()
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _wxctb.delete_SerialPort_EINFO
__del__ = lambda self : None;
SerialPort_EINFO_swigregister = _wxctb.SerialPort_EINFO_swigregister
SerialPort_EINFO_swigregister(SerialPort_EINFO)
CTB_SER_GETEINFO = _wxctb.CTB_SER_GETEINFO
CTB_SER_GETBRK = _wxctb.CTB_SER_GETBRK
CTB_SER_GETFRM = _wxctb.CTB_SER_GETFRM
CTB_SER_GETOVR = _wxctb.CTB_SER_GETOVR
CTB_SER_GETPAR = _wxctb.CTB_SER_GETPAR
CTB_SER_GETINQUE = _wxctb.CTB_SER_GETINQUE
CTB_SER_SETPAR = _wxctb.CTB_SER_SETPAR
class SerialPort_x(IOBase):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined - class is abstract")
__repr__ = _swig_repr
__swig_destroy__ = _wxctb.delete_SerialPort_x
__del__ = lambda self : None;
def ClassName(self): return _wxctb.SerialPort_x_ClassName(self)
def ChangeLineState(self, *args, **kwargs): return _wxctb.SerialPort_x_ChangeLineState(self, *args, **kwargs)
def ClrLineState(self, *args, **kwargs): return _wxctb.SerialPort_x_ClrLineState(self, *args, **kwargs)
def GetLineState(self): return _wxctb.SerialPort_x_GetLineState(self)
def GetSettingsAsString(self): return _wxctb.SerialPort_x_GetSettingsAsString(self)
def Ioctl(self, *args, **kwargs): return _wxctb.SerialPort_x_Ioctl(self, *args, **kwargs)
def SendBreak(self, *args, **kwargs): return _wxctb.SerialPort_x_SendBreak(self, *args, **kwargs)
def SetBaudrate(self, *args, **kwargs): return _wxctb.SerialPort_x_SetBaudrate(self, *args, **kwargs)
def SetLineState(self, *args, **kwargs): return _wxctb.SerialPort_x_SetLineState(self, *args, **kwargs)
def SetParityBit(self, *args, **kwargs): return _wxctb.SerialPort_x_SetParityBit(self, *args, **kwargs)
IsStandardRate = staticmethod(_wxctb.SerialPort_x_IsStandardRate)
SerialPort_x_swigregister = _wxctb.SerialPort_x_swigregister
SerialPort_x_swigregister(SerialPort_x)
def SerialPort_x_IsStandardRate(*args, **kwargs):
return _wxctb.SerialPort_x_IsStandardRate(*args, **kwargs)
SerialPort_x_IsStandardRate = _wxctb.SerialPort_x_IsStandardRate
COM1 = "/dev/ttyS0"
COM2 = "/dev/ttyS1"
COM3 = "/dev/ttyS2"
COM4 = "/dev/ttyS3"
COM5 = "/dev/ttyS4"
COM6 = "/dev/ttyS5"
COM7 = "/dev/ttyS6"
COM8 = "/dev/ttyS7"
COM9 = "/dev/ttyS8"
class SerialPort(SerialPort_x):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
def __init__(self):
this = _wxctb.new_SerialPort()
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _wxctb.delete_SerialPort
__del__ = lambda self : None;
def ChangeLineState(self, *args, **kwargs): return _wxctb.SerialPort_ChangeLineState(self, *args, **kwargs)
def ClrLineState(self, *args, **kwargs): return _wxctb.SerialPort_ClrLineState(self, *args, **kwargs)
def GetLineState(self): return _wxctb.SerialPort_GetLineState(self)
def Ioctl(self, *args, **kwargs): return _wxctb.SerialPort_Ioctl(self, *args, **kwargs)
def IsOpen(self): return _wxctb.SerialPort_IsOpen(self)
def Read(self, *args, **kwargs): return _wxctb.SerialPort_Read(self, *args, **kwargs)
def SendBreak(self, *args, **kwargs): return _wxctb.SerialPort_SendBreak(self, *args, **kwargs)
def SetBaudrate(self, *args, **kwargs): return _wxctb.SerialPort_SetBaudrate(self, *args, **kwargs)
def SetLineState(self, *args, **kwargs): return _wxctb.SerialPort_SetLineState(self, *args, **kwargs)
def SetParityBit(self, *args, **kwargs): return _wxctb.SerialPort_SetParityBit(self, *args, **kwargs)
def Write(self, *args, **kwargs): return _wxctb.SerialPort_Write(self, *args, **kwargs)
SerialPort_swigregister = _wxctb.SerialPort_swigregister
SerialPort_swigregister(SerialPort)
def GetKey():
return _wxctb.GetKey()
GetKey = _wxctb.GetKey
@@ -0,0 +1,70 @@
#!/usr/bin/python
import getopt, time, sys
sys.path.insert( 0, r'/home/jb/project/libctb-0.16/python/module/linux')
import ctb
def main():
baudrate = 19200
devname = ""
protocol = '8N1'
try:
opt,arg = getopt.getopt(sys.argv[1:],
'b:d:p:',
['baudrate=',
'device=',
'protocol='
])
except getopt.GetoptError:
print "usage: parity.py [options]\n"\
"\t-b baudrate\n"\
"\t--baudrate=baudrate"\
"\t-d device\n"\
"\t--device=serial device name like /dev/ttyS0 or COM1\n"\
"\t-h\n"\
"\t--help print this\n"\
"\n"
sys.exit(0)
for o,a in opt:
if o in ("-b","--baudrate"):
baudrate = int(a)
if o in ("-d","--device"):
devname = a
if o in ("-p","--protocol"):
protocol = a
print "Using ctb version " + ctb.GetVersion()
dev = ctb.SerialPort()
if dev.Open( devname, baudrate, protocol ) < 0:
print "Cannot open " + devname + "\n"
# send the following string with a always set parity bit
dev.SetParityBit( 1 )
dev.Writev( "Hello World" )
# send the following string with a always cleared parity bit
dev.SetParityBit( 0 )
dev.Writev( "Hello World" )
main()
@@ -0,0 +1,88 @@
#!/usr/bin/python
import getopt, time, sys
sys.path.insert( 0, r'/home/jb/project/libctb-0.16/python/module/linux')
import ctb
def DataBlock():
data = ''
for c in range( 0, 256):
data += '%c' % c
return data
def main():
baudrate = 19200
devname = ""
try:
opt,arg = getopt.getopt(sys.argv[1:],
'b:d:',
['baudrate=',
'device='
])
except getopt.GetoptError:
print "usage: protocol.py [options]\n"\
"\t-b baudrate\n"\
"\t--baudrate=baudrate"\
"\t-d device\n"\
"\t--device=serial device name like /dev/ttyS0 or COM1\n"\
"\t-h\n"\
"\t--help print this\n"\
"\n"
sys.exit(0)
for o,a in opt:
if o in ("-b","--baudrate"):
baudrate = int(a)
if o in ("-d","--device"):
devname = a
print "Using ctb version " + ctb.GetVersion()
dev = ctb.SerialPort()
protocols = [
'8N1','8O1','8E1','8S1','8M1'
]
dev.SetTimeout( 1000 )
for protocol in protocols:
if dev.Open( devname, baudrate, protocol ) < 0:
print "Cannot open " + devname + "\n"
sys.exit( 1 )
else:
print( "%i %s" % ( baudrate, protocol ) )
for i in range(0, 4 ):
dev.Writev( "\x33" )
time.sleep( 0.0006 )
dev.Writev( "\x31" )
time.sleep( 0.0006 )
time.sleep( 0.5 )
dev.Close()
main()
@@ -0,0 +1,53 @@
#!/usr/bin/python
import getopt, time, sys
sys.path.insert( 0, r'/home/jb/project/libctb-0.16/python/module/linux')
import ctb
def main():
devname = ""
try:
opt,arg = getopt.getopt(sys.argv[1:],
'd:',
['device='
])
except getopt.GetoptError:
print "usage: parity.py [options]\n"\
"\t-d device\n"\
"\t--device=serial device name like /dev/ttyS0 or COM1\n"\
"\t-h\n"\
"\t--help print this\n"\
"\n"
sys.exit(0)
for o,a in opt:
if o in ("-d","--device"):
devname = a
print "Using ctb version " + ctb.GetVersion()
dev = ctb.SerialPort()
if dev.Open( devname, 38400 ) < 0:
print "Cannot open " + devname + "\n"
dev.SetLineState( ctb.DTR )
dev.ClrLineState( ctb.RTS )
for i in range( 0, 100 ) :
time.sleep( 0.01 )
dev.ChangeLineState( ctb.DTR | ctb.RTS )
main()
@@ -0,0 +1,353 @@
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ctb</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>ctb</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/mnt/s/wxaddons/wxctb-0.9/SWIG/ctb.py">/mnt/s/wxaddons/wxctb-0.9/SWIG/ctb.py</a></font></td></tr></table>
<p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="re.html">re</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top><a href="wxctb.html">wxctb</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="ctb.html#wxIOBase">wxIOBase</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ctb.html#wxGPIB">wxGPIB</a>
</font></dt><dt><font face="helvetica, arial"><a href="ctb.html#wxSerialPort">wxSerialPort</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="wxGPIB">class <strong>wxGPIB</strong></a>(<a href="ctb.html#wxIOBase">wxIOBase</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt><a href="#wxGPIB">wxGPIB</a>&nbsp;class<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="wxGPIB-GetError"><strong>GetError</strong></a>(self)</dt></dl>
<dl><dt><a name="wxGPIB-GetSTB"><strong>GetSTB</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value&nbsp;of&nbsp;the&nbsp;internal&nbsp;GPIB&nbsp;status&nbsp;byte&nbsp;register.</tt></dd></dl>
<dl><dt><a name="wxGPIB-Ibrd"><strong>Ibrd</strong></a>(self, length)</dt><dd><tt>#&nbsp;This&nbsp;is&nbsp;only&nbsp;for&nbsp;internal&nbsp;usage!!!</tt></dd></dl>
<dl><dt><a name="wxGPIB-Ibwrt"><strong>Ibwrt</strong></a>(self, string)</dt><dd><tt>#&nbsp;This&nbsp;is&nbsp;only&nbsp;for&nbsp;internal&nbsp;usage!!!</tt></dd></dl>
<dl><dt><a name="wxGPIB-Open"><strong>Open</strong></a>(self, devname, adr)</dt><dd><tt><a href="#wxGPIB-Open">Open</a>(gpibdevice,address)<br>
Opens&nbsp;a&nbsp;connected&nbsp;device&nbsp;at&nbsp;the&nbsp;GPIB&nbsp;bus.&nbsp;gpibdevice&nbsp;means&nbsp;the<br>
controller,&nbsp;(mostly&nbsp;"gpib1"),&nbsp;address&nbsp;the&nbsp;address&nbsp;of&nbsp;the&nbsp;desired<br>
device&nbsp;in&nbsp;the&nbsp;range&nbsp;1...31.&nbsp;For&nbsp;example:<br>
dev&nbsp;=&nbsp;<a href="#wxGPIB">wxGPIB</a>()<br>
dev.<a href="#wxGPIB-Open">Open</a>("gpib1",17)<br>
Opens&nbsp;the&nbsp;device&nbsp;with&nbsp;the&nbsp;address&nbsp;17.<br>
Open&nbsp;returns&nbsp;&gt;=&nbsp;0&nbsp;or&nbsp;a&nbsp;negativ&nbsp;value,&nbsp;if&nbsp;something&nbsp;going&nbsp;wrong.</tt></dd></dl>
<dl><dt><a name="wxGPIB-Reset"><strong>Reset</strong></a>(self)</dt><dd><tt>Resets&nbsp;the&nbsp;connected&nbsp;device.&nbsp;In&nbsp;the&nbsp;GPIB&nbsp;definition,&nbsp;the&nbsp;device<br>
should&nbsp;be&nbsp;reset&nbsp;to&nbsp;it's&nbsp;initial&nbsp;state,&nbsp;so&nbsp;you&nbsp;can&nbsp;restart&nbsp;a<br>
formely&nbsp;lost&nbsp;communication.</tt></dd></dl>
<dl><dt><a name="wxGPIB-ResetBus"><strong>ResetBus</strong></a>(self)</dt><dd><tt>The&nbsp;command&nbsp;asserts&nbsp;the&nbsp;GPIB&nbsp;interface&nbsp;clear&nbsp;(IFC)&nbsp;line&nbsp;for<br>
ast&nbsp;least&nbsp;100us&nbsp;if&nbsp;the&nbsp;GPIB&nbsp;board&nbsp;is&nbsp;the&nbsp;system&nbsp;controller.<br>
This&nbsp;initializes&nbsp;the&nbsp;GPIB&nbsp;and&nbsp;makes&nbsp;the&nbsp;interface&nbsp;CIC&nbsp;and<br>
active&nbsp;controller&nbsp;with&nbsp;ATN&nbsp;asserted.<br>
Note!&nbsp;The&nbsp;IFC&nbsp;signal&nbsp;resets&nbsp;only&nbsp;the&nbsp;GPIB&nbsp;interface&nbsp;functions<br>
of&nbsp;the&nbsp;bus&nbsp;devices&nbsp;and&nbsp;not&nbsp;the&nbsp;internal&nbsp;device&nbsp;functions.<br>
For&nbsp;a&nbsp;device&nbsp;reset&nbsp;you&nbsp;should&nbsp;use&nbsp;the&nbsp;<a href="#wxGPIB-Reset">Reset</a>()&nbsp;command&nbsp;above.</tt></dd></dl>
<dl><dt><a name="wxGPIB-__del__"><strong>__del__</strong></a>(self)</dt></dl>
<dl><dt><a name="wxGPIB-__init__"><strong>__init__</strong></a>(self)</dt></dl>
<hr>
Methods inherited from <a href="ctb.html#wxIOBase">wxIOBase</a>:<br>
<dl><dt><a name="wxGPIB-Close"><strong>Close</strong></a>(self)</dt></dl>
<dl><dt><a name="wxGPIB-GetTimeout"><strong>GetTimeout</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;internal&nbsp;timeout&nbsp;value&nbsp;in&nbsp;milliseconds</tt></dd></dl>
<dl><dt><a name="wxGPIB-Ioctl"><strong>Ioctl</strong></a>(self, cmd, arg)</dt></dl>
<dl><dt><a name="wxGPIB-PutBack"><strong>PutBack</strong></a>(self, char)</dt></dl>
<dl><dt><a name="wxGPIB-Read"><strong>Read</strong></a>(self, length)</dt><dd><tt>Try&nbsp;to&nbsp;read&nbsp;the&nbsp;given&nbsp;count&nbsp;of&nbsp;data&nbsp;(length)&nbsp;and&nbsp;returns&nbsp;the<br>
successfully&nbsp;readed&nbsp;number&nbsp;of&nbsp;data.&nbsp;The&nbsp;function&nbsp;never&nbsp;blocks.<br>
For&nbsp;example:<br>
readed&nbsp;=&nbsp;dev.<a href="#wxGPIB-Read">Read</a>(100)</tt></dd></dl>
<dl><dt><a name="wxGPIB-ReadBinary"><strong>ReadBinary</strong></a>(self, eos<font color="#909090">='<font color="#c040c0">\n</font>'</font>)</dt><dd><tt>Special&nbsp;SCPI&nbsp;command.&nbsp;Read&nbsp;the&nbsp;next&nbsp;data&nbsp;coded&nbsp;as&nbsp;a&nbsp;SCPI<br>
binary&nbsp;format.<br>
A&nbsp;binary&nbsp;data&nbsp;transfer&nbsp;will&nbsp;be&nbsp;startet&nbsp;by&nbsp;'#'.&nbsp;The&nbsp;next&nbsp;byte<br>
tells&nbsp;the&nbsp;count&nbsp;of&nbsp;bytes&nbsp;for&nbsp;the&nbsp;binary&nbsp;length&nbsp;header,<br>
following&nbsp;by&nbsp;the&nbsp;length&nbsp;bytes.&nbsp;After&nbsp;these&nbsp;the&nbsp;data&nbsp;begins.<br>
For&nbsp;example:<br>
#500004xxxx<br>
The&nbsp;header&nbsp;length&nbsp;covers&nbsp;5&nbsp;Byte,&nbsp;the&nbsp;length&nbsp;of&nbsp;the&nbsp;binary<br>
data&nbsp;is&nbsp;4&nbsp;(x&nbsp;means&nbsp;the&nbsp;binary&nbsp;data&nbsp;bytes)</tt></dd></dl>
<dl><dt><a name="wxGPIB-ReadUntilEOS"><strong>ReadUntilEOS</strong></a>(self, eos<font color="#909090">='<font color="#c040c0">\n</font>'</font>, quota<font color="#909090">=0</font>)</dt><dd><tt><a href="#wxGPIB-ReadUntilEOS">ReadUntilEOS</a>(eosString="\n",timeout=1000)<br>
Reads&nbsp;data&nbsp;until&nbsp;the&nbsp;given&nbsp;eos&nbsp;string&nbsp;was&nbsp;received&nbsp;(default&nbsp;is<br>
the&nbsp;linefeed&nbsp;character&nbsp;(0x0a)&nbsp;or&nbsp;the&nbsp;internal&nbsp;timeout<br>
(default&nbsp;1000ms)&nbsp;was&nbsp;reached.<br>
ReadUntilEOS&nbsp;returns&nbsp;the&nbsp;result&nbsp;as&nbsp;the&nbsp;following&nbsp;tuple:<br>
['received&nbsp;string',state,readedBytes]<br>
If&nbsp;a&nbsp;timeout&nbsp;occurred,&nbsp;state&nbsp;is&nbsp;0,&nbsp;otherwise&nbsp;1</tt></dd></dl>
<dl><dt><a name="wxGPIB-Readv"><strong>Readv</strong></a>(self, length)</dt><dd><tt>Try&nbsp;to&nbsp;read&nbsp;the&nbsp;given&nbsp;count&nbsp;of&nbsp;data.&nbsp;Readv&nbsp;blocks&nbsp;until&nbsp;all&nbsp;data<br>
was&nbsp;readed&nbsp;successfully&nbsp;or&nbsp;the&nbsp;internal&nbsp;timeout,&nbsp;set&nbsp;with&nbsp;the<br>
class&nbsp;member&nbsp;function&nbsp;<a href="#wxGPIB-SetTimeout">SetTimeout</a>(timeout),&nbsp;was&nbsp;reached.<br>
Returns&nbsp;the&nbsp;readed&nbsp;data.</tt></dd></dl>
<dl><dt><a name="wxGPIB-SetTimeout"><strong>SetTimeout</strong></a>(self, timeout)</dt><dd><tt>Set&nbsp;the&nbsp;internal&nbsp;timeout&nbsp;value&nbsp;in&nbsp;milliseconds&nbsp;for&nbsp;all&nbsp;blocked<br>
operations&nbsp;like&nbsp;ReadUntilEOS,&nbsp;Readv&nbsp;and&nbsp;Writev.</tt></dd></dl>
<dl><dt><a name="wxGPIB-Write"><strong>Write</strong></a>(self, string)</dt><dd><tt>Writes&nbsp;the&nbsp;given&nbsp;string&nbsp;to&nbsp;the&nbsp;device&nbsp;and&nbsp;returns&nbsp;immediately.<br>
Write&nbsp;returns&nbsp;the&nbsp;number&nbsp;of&nbsp;data&nbsp;bytes&nbsp;successfully&nbsp;written&nbsp;or&nbsp;a<br>
negativ&nbsp;number&nbsp;if&nbsp;an&nbsp;error&nbsp;occured.&nbsp;For&nbsp;some&nbsp;circumstances,&nbsp;not<br>
the&nbsp;complete&nbsp;string&nbsp;was&nbsp;written.<br>
So&nbsp;you&nbsp;have&nbsp;to&nbsp;verify&nbsp;the&nbsp;return&nbsp;value&nbsp;to&nbsp;check&nbsp;this&nbsp;out.</tt></dd></dl>
<dl><dt><a name="wxGPIB-Writev"><strong>Writev</strong></a>(self, string)</dt><dd><tt>Writes&nbsp;the&nbsp;given&nbsp;string&nbsp;to&nbsp;the&nbsp;device.&nbsp;The&nbsp;function&nbsp;blocks&nbsp;until<br>
the&nbsp;complete&nbsp;string&nbsp;was&nbsp;written&nbsp;or&nbsp;the&nbsp;internal&nbsp;timeout,&nbsp;set&nbsp;with<br>
<a href="#wxGPIB-SetTimeout">SetTimeout</a>(timeout),&nbsp;was&nbsp;reached.<br>
Writev&nbsp;returns&nbsp;the&nbsp;number&nbsp;of&nbsp;data&nbsp;successfully&nbsp;written&nbsp;or&nbsp;a<br>
negativ&nbsp;value,&nbsp;if&nbsp;an&nbsp;errors&nbsp;occurred.</tt></dd></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="wxIOBase">class <strong>wxIOBase</strong></a></font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="wxIOBase-Close"><strong>Close</strong></a>(self)</dt></dl>
<dl><dt><a name="wxIOBase-GetTimeout"><strong>GetTimeout</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;internal&nbsp;timeout&nbsp;value&nbsp;in&nbsp;milliseconds</tt></dd></dl>
<dl><dt><a name="wxIOBase-Ioctl"><strong>Ioctl</strong></a>(self, cmd, arg)</dt></dl>
<dl><dt><a name="wxIOBase-Open"><strong>Open</strong></a>(self)</dt></dl>
<dl><dt><a name="wxIOBase-PutBack"><strong>PutBack</strong></a>(self, char)</dt></dl>
<dl><dt><a name="wxIOBase-Read"><strong>Read</strong></a>(self, length)</dt><dd><tt>Try&nbsp;to&nbsp;read&nbsp;the&nbsp;given&nbsp;count&nbsp;of&nbsp;data&nbsp;(length)&nbsp;and&nbsp;returns&nbsp;the<br>
successfully&nbsp;readed&nbsp;number&nbsp;of&nbsp;data.&nbsp;The&nbsp;function&nbsp;never&nbsp;blocks.<br>
For&nbsp;example:<br>
readed&nbsp;=&nbsp;dev.<a href="#wxIOBase-Read">Read</a>(100)</tt></dd></dl>
<dl><dt><a name="wxIOBase-ReadBinary"><strong>ReadBinary</strong></a>(self, eos<font color="#909090">='<font color="#c040c0">\n</font>'</font>)</dt><dd><tt>Special&nbsp;SCPI&nbsp;command.&nbsp;Read&nbsp;the&nbsp;next&nbsp;data&nbsp;coded&nbsp;as&nbsp;a&nbsp;SCPI<br>
binary&nbsp;format.<br>
A&nbsp;binary&nbsp;data&nbsp;transfer&nbsp;will&nbsp;be&nbsp;startet&nbsp;by&nbsp;'#'.&nbsp;The&nbsp;next&nbsp;byte<br>
tells&nbsp;the&nbsp;count&nbsp;of&nbsp;bytes&nbsp;for&nbsp;the&nbsp;binary&nbsp;length&nbsp;header,<br>
following&nbsp;by&nbsp;the&nbsp;length&nbsp;bytes.&nbsp;After&nbsp;these&nbsp;the&nbsp;data&nbsp;begins.<br>
For&nbsp;example:<br>
#500004xxxx<br>
The&nbsp;header&nbsp;length&nbsp;covers&nbsp;5&nbsp;Byte,&nbsp;the&nbsp;length&nbsp;of&nbsp;the&nbsp;binary<br>
data&nbsp;is&nbsp;4&nbsp;(x&nbsp;means&nbsp;the&nbsp;binary&nbsp;data&nbsp;bytes)</tt></dd></dl>
<dl><dt><a name="wxIOBase-ReadUntilEOS"><strong>ReadUntilEOS</strong></a>(self, eos<font color="#909090">='<font color="#c040c0">\n</font>'</font>, quota<font color="#909090">=0</font>)</dt><dd><tt><a href="#wxIOBase-ReadUntilEOS">ReadUntilEOS</a>(eosString="\n",timeout=1000)<br>
Reads&nbsp;data&nbsp;until&nbsp;the&nbsp;given&nbsp;eos&nbsp;string&nbsp;was&nbsp;received&nbsp;(default&nbsp;is<br>
the&nbsp;linefeed&nbsp;character&nbsp;(0x0a)&nbsp;or&nbsp;the&nbsp;internal&nbsp;timeout<br>
(default&nbsp;1000ms)&nbsp;was&nbsp;reached.<br>
ReadUntilEOS&nbsp;returns&nbsp;the&nbsp;result&nbsp;as&nbsp;the&nbsp;following&nbsp;tuple:<br>
['received&nbsp;string',state,readedBytes]<br>
If&nbsp;a&nbsp;timeout&nbsp;occurred,&nbsp;state&nbsp;is&nbsp;0,&nbsp;otherwise&nbsp;1</tt></dd></dl>
<dl><dt><a name="wxIOBase-Readv"><strong>Readv</strong></a>(self, length)</dt><dd><tt>Try&nbsp;to&nbsp;read&nbsp;the&nbsp;given&nbsp;count&nbsp;of&nbsp;data.&nbsp;Readv&nbsp;blocks&nbsp;until&nbsp;all&nbsp;data<br>
was&nbsp;readed&nbsp;successfully&nbsp;or&nbsp;the&nbsp;internal&nbsp;timeout,&nbsp;set&nbsp;with&nbsp;the<br>
class&nbsp;member&nbsp;function&nbsp;<a href="#wxIOBase-SetTimeout">SetTimeout</a>(timeout),&nbsp;was&nbsp;reached.<br>
Returns&nbsp;the&nbsp;readed&nbsp;data.</tt></dd></dl>
<dl><dt><a name="wxIOBase-ResetBus"><strong>ResetBus</strong></a>(self)</dt><dd><tt>If&nbsp;the&nbsp;underlaying&nbsp;interface&nbsp;needs&nbsp;some&nbsp;special&nbsp;reset&nbsp;operations<br>
(for&nbsp;instance&nbsp;the&nbsp;GPIB&nbsp;distinguish&nbsp;between&nbsp;a&nbsp;normal&nbsp;device&nbsp;reset<br>
and&nbsp;a&nbsp;special&nbsp;bus&nbsp;reset),&nbsp;you&nbsp;can&nbsp;put&nbsp;some&nbsp;code&nbsp;here)</tt></dd></dl>
<dl><dt><a name="wxIOBase-SetTimeout"><strong>SetTimeout</strong></a>(self, timeout)</dt><dd><tt>Set&nbsp;the&nbsp;internal&nbsp;timeout&nbsp;value&nbsp;in&nbsp;milliseconds&nbsp;for&nbsp;all&nbsp;blocked<br>
operations&nbsp;like&nbsp;ReadUntilEOS,&nbsp;Readv&nbsp;and&nbsp;Writev.</tt></dd></dl>
<dl><dt><a name="wxIOBase-Write"><strong>Write</strong></a>(self, string)</dt><dd><tt>Writes&nbsp;the&nbsp;given&nbsp;string&nbsp;to&nbsp;the&nbsp;device&nbsp;and&nbsp;returns&nbsp;immediately.<br>
Write&nbsp;returns&nbsp;the&nbsp;number&nbsp;of&nbsp;data&nbsp;bytes&nbsp;successfully&nbsp;written&nbsp;or&nbsp;a<br>
negativ&nbsp;number&nbsp;if&nbsp;an&nbsp;error&nbsp;occured.&nbsp;For&nbsp;some&nbsp;circumstances,&nbsp;not<br>
the&nbsp;complete&nbsp;string&nbsp;was&nbsp;written.<br>
So&nbsp;you&nbsp;have&nbsp;to&nbsp;verify&nbsp;the&nbsp;return&nbsp;value&nbsp;to&nbsp;check&nbsp;this&nbsp;out.</tt></dd></dl>
<dl><dt><a name="wxIOBase-Writev"><strong>Writev</strong></a>(self, string)</dt><dd><tt>Writes&nbsp;the&nbsp;given&nbsp;string&nbsp;to&nbsp;the&nbsp;device.&nbsp;The&nbsp;function&nbsp;blocks&nbsp;until<br>
the&nbsp;complete&nbsp;string&nbsp;was&nbsp;written&nbsp;or&nbsp;the&nbsp;internal&nbsp;timeout,&nbsp;set&nbsp;with<br>
<a href="#wxIOBase-SetTimeout">SetTimeout</a>(timeout),&nbsp;was&nbsp;reached.<br>
Writev&nbsp;returns&nbsp;the&nbsp;number&nbsp;of&nbsp;data&nbsp;successfully&nbsp;written&nbsp;or&nbsp;a<br>
negativ&nbsp;value,&nbsp;if&nbsp;an&nbsp;errors&nbsp;occurred.</tt></dd></dl>
<dl><dt><a name="wxIOBase-__del__"><strong>__del__</strong></a>(self)</dt></dl>
<dl><dt><a name="wxIOBase-__init__"><strong>__init__</strong></a>(self)</dt></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="wxSerialPort">class <strong>wxSerialPort</strong></a>(<a href="ctb.html#wxIOBase">wxIOBase</a>)</font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="wxSerialPort-ChangeLineState"><strong>ChangeLineState</strong></a>(self, lineState)</dt><dd><tt>Change&nbsp;(toggle)&nbsp;the&nbsp;state&nbsp;of&nbsp;each&nbsp;the&nbsp;lines&nbsp;given&nbsp;in&nbsp;the<br>
linestate&nbsp;parameter.&nbsp;Possible&nbsp;values&nbsp;are&nbsp;wxSERIAL_LINESTATE_DTR<br>
(means&nbsp;the&nbsp;DTR&nbsp;signal)&nbsp;and/or&nbsp;wxSERIAL_LINESTATE_RTS&nbsp;(RTS&nbsp;signal).<br>
For&nbsp;example&nbsp;to&nbsp;toggle&nbsp;the&nbsp;RTS&nbsp;line&nbsp;only:<br>
dev.<a href="#wxSerialPort-ChangeLineState">ChangeLineState</a>(wxSERIAL_LINESTATE_RTS)</tt></dd></dl>
<dl><dt><a name="wxSerialPort-ClrLineState"><strong>ClrLineState</strong></a>(self, lineState)</dt><dd><tt>Clear&nbsp;the&nbsp;lines&nbsp;given&nbsp;in&nbsp;the&nbsp;linestate&nbsp;parameter.&nbsp;Possible<br>
values&nbsp;are&nbsp;wxSERIAL_LINESTATE_DTR&nbsp;(means&nbsp;the&nbsp;DTR&nbsp;signal)&nbsp;and/or<br>
wxSERIAL_LINESTATE_RTS&nbsp;(RTS&nbsp;signal).&nbsp;For&nbsp;example&nbsp;to&nbsp;clear&nbsp;only<br>
the&nbsp;RTS&nbsp;line:<br>
dev.<a href="#wxSerialPort-ClrLineState">ClrLineState</a>(wxSERIAL_LINESTATE_RTS)</tt></dd></dl>
<dl><dt><a name="wxSerialPort-GetAvailableBytes"><strong>GetAvailableBytes</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;available&nbsp;bytes&nbsp;in&nbsp;the&nbsp;input&nbsp;queue&nbsp;of&nbsp;the&nbsp;serial<br>
driver.</tt></dd></dl>
<dl><dt><a name="wxSerialPort-GetCommErrors"><strong>GetCommErrors</strong></a>(self)</dt><dd><tt>Get&nbsp;the&nbsp;internal&nbsp;communication&nbsp;errors&nbsp;like&nbsp;breaks,&nbsp;framing,<br>
parity&nbsp;or&nbsp;overrun&nbsp;errors.<br>
Returns&nbsp;the&nbsp;count&nbsp;of&nbsp;each&nbsp;error&nbsp;as&nbsp;a&nbsp;tuple&nbsp;like&nbsp;this:<br>
(b,f,o,p)&nbsp;=&nbsp;dev.<a href="#wxSerialPort-GetCommErrors">GetCommErrors</a>()<br>
b:&nbsp;breaks,&nbsp;f:&nbsp;framing&nbsp;errors,&nbsp;&nbsp;o:&nbsp;overruns,&nbsp;p:&nbsp;parity&nbsp;errors</tt></dd></dl>
<dl><dt><a name="wxSerialPort-GetLineState"><strong>GetLineState</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;current&nbsp;linestates&nbsp;of&nbsp;the&nbsp;CTS,&nbsp;DCD,&nbsp;DSR&nbsp;and&nbsp;RING<br>
signal&nbsp;line&nbsp;as&nbsp;an&nbsp;integer&nbsp;value&nbsp;with&nbsp;the&nbsp;appropriate&nbsp;bits&nbsp;or<br>
-1&nbsp;on&nbsp;error.<br>
For&nbsp;example:<br>
lines&nbsp;=&nbsp;dev.<a href="#wxSerialPort-GetLineState">GetLineState</a>()<br>
if&nbsp;lines&nbsp;&amp;&nbsp;wxSERIAL_LINESTATE_CTS:<br>
&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;"CTS&nbsp;is&nbsp;on"</tt></dd></dl>
<dl><dt><a name="wxSerialPort-Open"><strong>Open</strong></a>(self, devname, baudrate, protocol<font color="#909090">='8N1'</font>, handshake<font color="#909090">='no_handshake'</font>)</dt><dd><tt>Open&nbsp;the&nbsp;device&nbsp;devname&nbsp;with&nbsp;the&nbsp;given&nbsp;baudrate,&nbsp;the&nbsp;protocol<br>
like&nbsp;'8N1'&nbsp;(default)&nbsp;and&nbsp;the&nbsp;use&nbsp;of&nbsp;the&nbsp;handshake&nbsp;[no_handshake<br>
(default),&nbsp;rtscts&nbsp;or&nbsp;xonxoff]<br>
For&nbsp;example:<br>
At&nbsp;Linux:<br>
dev&nbsp;=&nbsp;<a href="#wxSerialPort">wxSerialPort</a>()<br>
dev.<a href="#wxSerialPort-Open">Open</a>("/dev/ttyS0",115200)<br>
or&nbsp;with&nbsp;a&nbsp;datalen&nbsp;of&nbsp;7&nbsp;bits,&nbsp;even&nbsp;parity,&nbsp;2&nbsp;stopbits&nbsp;and&nbsp;rts/cts<br>
handshake:<br>
dev.<a href="#wxSerialPort-Open">Open</a>("/dev/ttyS0",115200,'7E2',True)<br>
At&nbsp;Windows:<br>
dev&nbsp;=&nbsp;<a href="#wxSerialPort">wxSerialPort</a>()<br>
dev.<a href="#wxSerialPort-Open">Open</a>("COM1",115200)<br>
dev.<a href="#wxSerialPort-Open">Open</a>("COM1",115200,'7E2',True)<br>
Returns&nbsp;the&nbsp;handle&nbsp;on&nbsp;success&nbsp;or&nbsp;a&nbsp;negativ&nbsp;value&nbsp;on&nbsp;failure.</tt></dd></dl>
<dl><dt><a name="wxSerialPort-Reset"><strong>Reset</strong></a>(self)</dt><dd><tt>Send&nbsp;a&nbsp;break&nbsp;for&nbsp;0.25s.</tt></dd></dl>
<dl><dt><a name="wxSerialPort-SetBaudRate"><strong>SetBaudRate</strong></a>(self, baudrate)</dt><dd><tt>Set&nbsp;the&nbsp;baudrate&nbsp;for&nbsp;the&nbsp;device.</tt></dd></dl>
<dl><dt><a name="wxSerialPort-SetLineState"><strong>SetLineState</strong></a>(self, lineState)</dt><dd><tt>Set&nbsp;the&nbsp;lines&nbsp;given&nbsp;in&nbsp;the&nbsp;linestate&nbsp;parameter.&nbsp;Possible<br>
values&nbsp;are&nbsp;wxSERIAL_LINESTATE_DTR&nbsp;(means&nbsp;the&nbsp;DTR&nbsp;signal)&nbsp;and/or<br>
wxSERIAL_LINESTATE_RTS&nbsp;(RTS&nbsp;signal).&nbsp;For&nbsp;example&nbsp;to&nbsp;set&nbsp;both:<br>
dev.<a href="#wxSerialPort-SetLineState">SetLineState</a>(wxSERIAL_LINESTATE_DTR&nbsp;|&nbsp;wxSERIAL_LINESTATE_RTS)</tt></dd></dl>
<dl><dt><a name="wxSerialPort-__del__"><strong>__del__</strong></a>(self)</dt></dl>
<dl><dt><a name="wxSerialPort-__init__"><strong>__init__</strong></a>(self)</dt></dl>
<hr>
Methods inherited from <a href="ctb.html#wxIOBase">wxIOBase</a>:<br>
<dl><dt><a name="wxSerialPort-Close"><strong>Close</strong></a>(self)</dt></dl>
<dl><dt><a name="wxSerialPort-GetTimeout"><strong>GetTimeout</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;internal&nbsp;timeout&nbsp;value&nbsp;in&nbsp;milliseconds</tt></dd></dl>
<dl><dt><a name="wxSerialPort-Ioctl"><strong>Ioctl</strong></a>(self, cmd, arg)</dt></dl>
<dl><dt><a name="wxSerialPort-PutBack"><strong>PutBack</strong></a>(self, char)</dt></dl>
<dl><dt><a name="wxSerialPort-Read"><strong>Read</strong></a>(self, length)</dt><dd><tt>Try&nbsp;to&nbsp;read&nbsp;the&nbsp;given&nbsp;count&nbsp;of&nbsp;data&nbsp;(length)&nbsp;and&nbsp;returns&nbsp;the<br>
successfully&nbsp;readed&nbsp;number&nbsp;of&nbsp;data.&nbsp;The&nbsp;function&nbsp;never&nbsp;blocks.<br>
For&nbsp;example:<br>
readed&nbsp;=&nbsp;dev.<a href="#wxSerialPort-Read">Read</a>(100)</tt></dd></dl>
<dl><dt><a name="wxSerialPort-ReadBinary"><strong>ReadBinary</strong></a>(self, eos<font color="#909090">='<font color="#c040c0">\n</font>'</font>)</dt><dd><tt>Special&nbsp;SCPI&nbsp;command.&nbsp;Read&nbsp;the&nbsp;next&nbsp;data&nbsp;coded&nbsp;as&nbsp;a&nbsp;SCPI<br>
binary&nbsp;format.<br>
A&nbsp;binary&nbsp;data&nbsp;transfer&nbsp;will&nbsp;be&nbsp;startet&nbsp;by&nbsp;'#'.&nbsp;The&nbsp;next&nbsp;byte<br>
tells&nbsp;the&nbsp;count&nbsp;of&nbsp;bytes&nbsp;for&nbsp;the&nbsp;binary&nbsp;length&nbsp;header,<br>
following&nbsp;by&nbsp;the&nbsp;length&nbsp;bytes.&nbsp;After&nbsp;these&nbsp;the&nbsp;data&nbsp;begins.<br>
For&nbsp;example:<br>
#500004xxxx<br>
The&nbsp;header&nbsp;length&nbsp;covers&nbsp;5&nbsp;Byte,&nbsp;the&nbsp;length&nbsp;of&nbsp;the&nbsp;binary<br>
data&nbsp;is&nbsp;4&nbsp;(x&nbsp;means&nbsp;the&nbsp;binary&nbsp;data&nbsp;bytes)</tt></dd></dl>
<dl><dt><a name="wxSerialPort-ReadUntilEOS"><strong>ReadUntilEOS</strong></a>(self, eos<font color="#909090">='<font color="#c040c0">\n</font>'</font>, quota<font color="#909090">=0</font>)</dt><dd><tt><a href="#wxSerialPort-ReadUntilEOS">ReadUntilEOS</a>(eosString="\n",timeout=1000)<br>
Reads&nbsp;data&nbsp;until&nbsp;the&nbsp;given&nbsp;eos&nbsp;string&nbsp;was&nbsp;received&nbsp;(default&nbsp;is<br>
the&nbsp;linefeed&nbsp;character&nbsp;(0x0a)&nbsp;or&nbsp;the&nbsp;internal&nbsp;timeout<br>
(default&nbsp;1000ms)&nbsp;was&nbsp;reached.<br>
ReadUntilEOS&nbsp;returns&nbsp;the&nbsp;result&nbsp;as&nbsp;the&nbsp;following&nbsp;tuple:<br>
['received&nbsp;string',state,readedBytes]<br>
If&nbsp;a&nbsp;timeout&nbsp;occurred,&nbsp;state&nbsp;is&nbsp;0,&nbsp;otherwise&nbsp;1</tt></dd></dl>
<dl><dt><a name="wxSerialPort-Readv"><strong>Readv</strong></a>(self, length)</dt><dd><tt>Try&nbsp;to&nbsp;read&nbsp;the&nbsp;given&nbsp;count&nbsp;of&nbsp;data.&nbsp;Readv&nbsp;blocks&nbsp;until&nbsp;all&nbsp;data<br>
was&nbsp;readed&nbsp;successfully&nbsp;or&nbsp;the&nbsp;internal&nbsp;timeout,&nbsp;set&nbsp;with&nbsp;the<br>
class&nbsp;member&nbsp;function&nbsp;<a href="#wxSerialPort-SetTimeout">SetTimeout</a>(timeout),&nbsp;was&nbsp;reached.<br>
Returns&nbsp;the&nbsp;readed&nbsp;data.</tt></dd></dl>
<dl><dt><a name="wxSerialPort-ResetBus"><strong>ResetBus</strong></a>(self)</dt><dd><tt>If&nbsp;the&nbsp;underlaying&nbsp;interface&nbsp;needs&nbsp;some&nbsp;special&nbsp;reset&nbsp;operations<br>
(for&nbsp;instance&nbsp;the&nbsp;GPIB&nbsp;distinguish&nbsp;between&nbsp;a&nbsp;normal&nbsp;device&nbsp;reset<br>
and&nbsp;a&nbsp;special&nbsp;bus&nbsp;reset),&nbsp;you&nbsp;can&nbsp;put&nbsp;some&nbsp;code&nbsp;here)</tt></dd></dl>
<dl><dt><a name="wxSerialPort-SetTimeout"><strong>SetTimeout</strong></a>(self, timeout)</dt><dd><tt>Set&nbsp;the&nbsp;internal&nbsp;timeout&nbsp;value&nbsp;in&nbsp;milliseconds&nbsp;for&nbsp;all&nbsp;blocked<br>
operations&nbsp;like&nbsp;ReadUntilEOS,&nbsp;Readv&nbsp;and&nbsp;Writev.</tt></dd></dl>
<dl><dt><a name="wxSerialPort-Write"><strong>Write</strong></a>(self, string)</dt><dd><tt>Writes&nbsp;the&nbsp;given&nbsp;string&nbsp;to&nbsp;the&nbsp;device&nbsp;and&nbsp;returns&nbsp;immediately.<br>
Write&nbsp;returns&nbsp;the&nbsp;number&nbsp;of&nbsp;data&nbsp;bytes&nbsp;successfully&nbsp;written&nbsp;or&nbsp;a<br>
negativ&nbsp;number&nbsp;if&nbsp;an&nbsp;error&nbsp;occured.&nbsp;For&nbsp;some&nbsp;circumstances,&nbsp;not<br>
the&nbsp;complete&nbsp;string&nbsp;was&nbsp;written.<br>
So&nbsp;you&nbsp;have&nbsp;to&nbsp;verify&nbsp;the&nbsp;return&nbsp;value&nbsp;to&nbsp;check&nbsp;this&nbsp;out.</tt></dd></dl>
<dl><dt><a name="wxSerialPort-Writev"><strong>Writev</strong></a>(self, string)</dt><dd><tt>Writes&nbsp;the&nbsp;given&nbsp;string&nbsp;to&nbsp;the&nbsp;device.&nbsp;The&nbsp;function&nbsp;blocks&nbsp;until<br>
the&nbsp;complete&nbsp;string&nbsp;was&nbsp;written&nbsp;or&nbsp;the&nbsp;internal&nbsp;timeout,&nbsp;set&nbsp;with<br>
<a href="#wxSerialPort-SetTimeout">SetTimeout</a>(timeout),&nbsp;was&nbsp;reached.<br>
Writev&nbsp;returns&nbsp;the&nbsp;number&nbsp;of&nbsp;data&nbsp;successfully&nbsp;written&nbsp;or&nbsp;a<br>
negativ&nbsp;value,&nbsp;if&nbsp;an&nbsp;errors&nbsp;occurred.</tt></dd></dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-GetKey"><strong>GetKey</strong></a>()</dt><dd><tt>Returns&nbsp;the&nbsp;current&nbsp;pressed&nbsp;key&nbsp;or&nbsp;'',&nbsp;if&nbsp;no&nbsp;key&nbsp;is&nbsp;pressed.<br>
You&nbsp;can&nbsp;simply&nbsp;create&nbsp;a&nbsp;query&nbsp;loop&nbsp;with:<br>
while&nbsp;<a href="#-GetKey">GetKey</a>()&nbsp;==&nbsp;'':<br>
&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp;make&nbsp;some&nbsp;stuff&nbsp;...</tt></dd></dl>
<dl><dt><a name="-abstract"><strong>abstract</strong></a>()</dt></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>wxSERIAL_LINESTATE_CTS</strong> = 32<br>
<strong>wxSERIAL_LINESTATE_DCD</strong> = 64<br>
<strong>wxSERIAL_LINESTATE_DSR</strong> = 256<br>
<strong>wxSERIAL_LINESTATE_DTR</strong> = 2<br>
<strong>wxSERIAL_LINESTATE_NULL</strong> = 0<br>
<strong>wxSERIAL_LINESTATE_RING</strong> = 128<br>
<strong>wxSERIAL_LINESTATE_RTS</strong> = 4</td></tr></table>
</body></html>
@@ -0,0 +1,455 @@
import wxctb, sys, re
DCD = wxctb.LinestateDcd
CTS = wxctb.LinestateCts
DSR = wxctb.LinestateDsr
DTR = wxctb.LinestateDtr
RING = wxctb.LinestateRing
RTS = wxctb.LinestateRts
NULL = wxctb.LinestateNull
def abstract():
import inspect
caller = inspect.getouterframes(inspect.currentframe())[1][3]
raise NotImplementedError(caller + ' must be implemented in subclass')
class IOBase:
def __init__(self):
self.device = None
# set timeout to 1000ms (the default)
self.timeout = 1000
def __del__(self):
pass
def Close(self):
if self.device:
self.device.Close()
def GetTimeout(self):
"""
Returns the internal timeout value in milliseconds
"""
return self.timeout
def Ioctl(self,cmd,arg):
if self.device:
self.device.Ioctl(cmd,arg)
def Open(self):
abstract()
def PutBack(self,char):
return self.device.PutBack(char)
def Read(self,length):
"""
Try to read the given count of data (length) and returns the
successfully readed number of data. The function never blocks.
For example:
readed = dev.Read(100)
"""
buf = "\x00"*(length+1)
rd = self.device.Read(buf,length)
return buf[0:rd]
def ReadBinary(self,eos="\n"):
"""
Special SCPI command. Read the next data coded as a SCPI
binary format.
A binary data transfer will be startet by '#'. The next byte
tells the count of bytes for the binary length header,
following by the length bytes. After these the data begins.
For example:
#500004xxxx
The header length covers 5 Byte, the length of the binary
data is 4 (x means the binary data bytes)
"""
try:
eoslen = len(eos)
b=self.Readv(2)
if len(b) == 2:
hl = int(b[1])
b = self.Readv(hl)
if len(b) == hl:
dl = int(b)
# don't left over the eos string or character in the
# device input buffer
data = self.Readv(dl+eoslen)
# check, if the binary data block is complete
if data[dl] == '#':
# not complete, another block is following
for c in data[dl:dl+eoslen]:
self.PutBack(c)
data = data[:dl] + self.ReadBinary()
return data
except:
pass
return ''
def ReadUntilEOS(self,eos="\n",quota=0):
"""
ReadUntilEOS(eosString=\"\\n\",timeout=1000)
Reads data until the given eos string was received (default is
the linefeed character (0x0a) or the internal timeout
(default 1000ms) was reached.
ReadUntilEOS returns the result as the following tuple:
['received string',state,readedBytes]
If a timeout occurred, state is 0, otherwise 1
"""
return self.device.ReadUntilEOS("",0,eos,self.timeout,quota)
def Readv(self,length):
"""
Try to read the given count of data. Readv blocks until all data
was readed successfully or the internal timeout, set with the
class member function SetTimeout(timeout), was reached.
Returns the readed data.
"""
buf = "\x00"*length
rd = self.device.Readv(buf,length,self.timeout)
return buf[0:rd]
def ResetBus(self):
"""
If the underlaying interface needs some special reset operations
(for instance the GPIB distinguish between a normal device reset
and a special bus reset), you can put some code here)
"""
pass
def SetTimeout(self,timeout):
"""
Set the internal timeout value in milliseconds for all blocked
operations like ReadUntilEOS, Readv and Writev.
"""
self.timeout = timeout
def Write(self,string):
"""
Writes the given string to the device and returns immediately.
Write returns the number of data bytes successfully written or a
negativ number if an error occured. For some circumstances, not
the complete string was written.
So you have to verify the return value to check this out.
"""
return self.device.Write(string,len(string))
def Writev(self,string):
"""
Writes the given string to the device. The function blocks until
the complete string was written or the internal timeout, set with
SetTimeout(timeout), was reached.
Writev returns the number of data successfully written or a
negativ value, if an errors occurred.
"""
return self.device.Writev(string,len(string),self.timeout)
class SerialPort(IOBase):
def __init__(self):
IOBase.__init__(self)
def __del__(self):
self.Close()
def ChangeLineState(self,lineState):
"""
Change (toggle) the state of each the lines given in the
linestate parameter. Possible values are DTR and/or RTS.
For example to toggle the RTS line only:
dev.ChangeLineState(RTS)
"""
self.device.ChangeLineState(lineState)
def ClrLineState(self,lineState):
"""
Clear the lines given in the linestate parameter. Possible
values are DTR and/or RTS. For example to clear only
the RTS line:
dev.ClrLineState(RTS)
"""
self.device.ClrLineState(lineState)
def GetAvailableBytes(self):
"""
Returns the available bytes in the input queue of the serial
driver.
"""
n = wxctb.new_intp()
wxctb.intp_assign(n, 0)
self.device.Ioctl(wxctb.CTB_SER_GETINQUE,n)
return wxctb.intp_value(n)
def GetCommErrors(self):
"""
Get the internal communication errors like breaks, framing,
parity or overrun errors.
Returns the count of each error as a tuple like this:
(b,f,o,p) = dev.GetCommErrors()
b: breaks, f: framing errors, o: overruns, p: parity errors
"""
einfo = wxctb.SerialPort_EINFO()
self.device.Ioctl(wxctb.CTB_SER_GETEINFO,einfo)
return einfo.brk,einfo.frame,einfo.overrun,einfo.parity
def GetLineState(self):
"""
Returns the current linestates of the CTS, DCD, DSR and RING
signal line as an integer value with the appropriate bits or
-1 on error.
For example:
lines = dev.GetLineState()
if lines & CTS:
print \"CTS is on\"
"""
return self.device.GetLineState()
def Open(self,devname,baudrate,protocol='8N1',handshake='no_handshake'):
"""
Open the device devname with the given baudrate, the protocol
like '8N1' (default) and the use of the handshake [no_handshake
(default), rtscts or xonxoff]
For example:
At Linux:
dev = SerialPort()
dev.Open(\"/dev/ttyS0\",115200)
or with a datalen of 7 bits, even parity, 2 stopbits and rts/cts
handshake:
dev.Open(\"/dev/ttyS0\",115200,'7E2',True)
At Windows:
dev = SerialPort()
dev.Open(\"COM1\",115200)
dev.Open(\"COM1\",115200,'7E2',True)
Returns the handle on success or a negativ value on failure.
"""
# the following parity values are valid:
# N:None, O:Odd, E:Even, M:Mark, S:Space
parity = {'N':0,'O':1,'E':2,'M':3,'S':4}
# the regular expression ensures a valid value for the datalen
# (5...8 bit) and the count of stopbits (1,2)
reg=re.compile(r"(?P<w>[8765])"r"(?P<p>[NOEMS])"r"(?P<s>[12])")
self.device = wxctb.SerialPort()
dcs = wxctb.SerialPort_DCS()
dcs.baud = baudrate
res = reg.search(protocol)
# handle the given protocol
if res:
dcs.wordlen = int(res.group('w'))
dcs.stopbits = int(res.group('s'))
dcs.parity = parity[res.group('p')]
# valid handshake are no one, rts/cts or xon/xoff
if handshake == 'rtscts':
dcs.rtscts = True
elif handshake == 'xonxoff':
dcs.xonxoff = True
return self.device.Open(devname,dcs)
def Reset(self):
"""
Send a break for 0.25s.
"""
self.device.SendBreak(0)
def SetBaudrate(self,baudrate):
"""
Set the baudrate for the device.
"""
self.device.SetBaudrate(baudrate)
def SetLineState(self,lineState):
"""
Set the lines given in the linestate parameter. Possible
values are DTR and/or RTS. For example to set both:
dev.SetLineState( DTR | RTS)
"""
self.device.SetLineState(lineState)
def SetParityBit(self,parity):
"""
Set the parity bit explicitly to 0 or 1. Use this function, if
you would like to simulate a 9 bit wordlen at what the ninth bit
was represented by the parity bit value. For example:
dev.SetParityBit( 0 )
dev.Write('some data sent with parity 0')
dev.SetParityBit( 1 )
dev.Write('another sequence with parity 1')
"""
return self.device.SetParityBit( parity )
class GpibDevice(IOBase):
"""
GPIB class
"""
def __init__(self):
IOBase.__init__(self)
def __del__(self):
self.Close()
def FindListeners(self,board = 0):
"""
Returns the address of the connected devices as a list.
If no device is listening, the list is empty. If an error
occurs an IOError exception raised. For example:
g = GPIB()
listeners = g.FindListeners()
"""
listeners = wxctb.GPIB_x_FindListeners(board)
if listeners < 0:
raise IOError("GPIB board error")
result = []
for i in range(1,31):
if listeners & (1 << i):
result.append(i)
return result
def GetEosChar(self):
"""
Get the internal EOS termination character (see SetEosChar).
For example:
g = GPIB()
g.Open(\"gpib1\",1)
eos = g.GetEosChar()
"""
eos = wxctb.new_intp()
wxctb.intp_assign(eos, 0)
self.device.Ioctl(wxctb.CTB_GPIB_GET_EOS_CHAR,eos)
return wxctb.intp_value(eos)
def GetEosMode(self):
"""
Get the internal EOS mode (see SetEosMode).
For example:
g = GPIB()
g.Open(\"gpib1\",1)
eos = g.GetEosMode()
"""
mode = wxctb.new_intp()
wxctb.intp_assign(mode, 0)
self.device.Ioctl(wxctb.CTB_GPIB_GET_EOS_MODE,mode)
return wxctb.intp_value(mode)
def GetError(self):
errorString = " "*256
self.device.GetError(errorString,256)
return errorString
def GetSTB(self):
"""
Returns the value of the internal GPIB status byte register.
"""
stb = wxctb.new_intp()
wxctb.intp_assign(stb, 0)
self.device.Ioctl(wxctb.CTB_GPIB_GETRSP,stb)
return wxctb.intp_value(stb)
# This is only for internal usage!!!
def Ibrd(self,length):
buf = "\x00"*length
state = self.device.Ibrd(buf,length)
return state,buf
# This is only for internal usage!!!
def Ibwrt(self,string):
return self.device.Ibwrt(string,len(string))
def Open(self,devname,adr,eosChar=10,eosMode=0x08|0x04):
"""
Open(gpibdevice,address,eosChar,eosMode)
Opens a connected device at the GPIB bus. gpibdevice means the
controller, (mostly \"gpib1\"), address the address of the desired
device in the range 1...31. The eosChar defines the EOS character
(default is linefeed), eosMode may be a combination of bits ORed
together. The following bits can be used:
0x04: Terminate read when EOS is detected.
0x08: Set EOI (End or identify line) with EOS on write function
0x10: Compare all 8 bits of EOS byte rather than low 7 bits
(all read and write functions). Default is 0x12
For example:
dev = GPIB()
dev.Open(\"gpib1\",17)
Opens the device with the address 17, linefeed as EOS (default)
and eos mode with 0x04 and 0x08.
Open returns >= 0 or a negativ value, if something going wrong.
"""
self.device = wxctb.GpibDevice()
dcs = wxctb.Gpib_DCS()
dcs.m_address1 = adr
dcs.m_eosChar = eosChar
dcs.m_eosMode = eosMode
result = self.device.Open(devname,dcs)
return result
def Reset(self):
"""
Resets the connected device. In the GPIB definition, the device
should be reset to it's initial state, so you can restart a
formely lost communication.
"""
self.device.Ioctl(wxctb.CTB_RESET,None)
def ResetBus(self):
"""
The command asserts the GPIB interface clear (IFC) line for
ast least 100us if the GPIB board is the system controller.
This initializes the GPIB and makes the interface CIC and
active controller with ATN asserted.
Note! The IFC signal resets only the GPIB interface functions
of the bus devices and not the internal device functions.
For a device reset you should use the Reset() command above.
"""
self.device.Ioctl(wxctb.CTB_GPIB_RESET_BUS,None)
def SetEosChar(self,eos):
"""
Configure the end-of-string (EOS) termination character.
Note! Defining an EOS byte does not cause the driver to
automatically send that byte at the end of write I/O
operations. The application is responsible for placing the
EOS byte at the end of the data strings that it defines.
(National Instruments NI-488.2M Function Reference Manual)
For example:
g = GPIB()
g.Open(\"gpib1\",1)
eos = g.GetEosChar(0x10)
"""
intp = wxctb.new_intp()
wxctb.intp_assign(intp, eos)
return self.device.Ioctl(wxctb.CTB_GPIB_SET_EOS_CHAR,intp)
def SetEosMode(self,mode):
"""
Set the EOS mode (handling).m_eosMode may be a combination
of bits ORed together. The following bits can be used:
0x04: Terminate read when EOS is detected.
0x08: Set EOI (End or identify line) with EOS on write function
0x10: Compare all 8 bits of EOS byte rather than low 7 bits
(all read and write functions). For example:
g = GPIB()
g.Open(\"gpib1\",1)
eos = g.GetEosMode(0x04 | 0x08)
"""
intp = wxctb.new_intp()
wxctb.intp_assign(intp, mode)
return self.device.Ioctl(wxctb.CTB_GPIB_SET_EOS_MODE,intp)
def GetKey():
"""
Returns the current pressed key or '\0', if no key is pressed.
You can simply create a query loop with:
while GetKey() == '\0':
... make some stuff ...
"""
return wxctb.GetKey()
def GetVersion():
"""
Returns the version of the ctb python module. The numbering
has the following format: x.y.z
x.y means the version of the underlaying ctb lib, z the version
of the python port.
"""
return "0.16"
@@ -0,0 +1,96 @@
%{
#include "ctb-0.16/gpib.h"
%}
%include iobase.i
namespace ctb {
%typemap(in) void * dcs (Gpib_DCS tmp) {
/* dont check for list */
$1 = &tmp;
}
enum GpibTimeout
{
GpibTimeoutNONE = 0,
GpibTimeout10us,
GpibTimeout30us,
GpibTimeout100us,
GpibTimeout300us,
GpibTimeout1ms,
GpibTimeout3ms,
GpibTimeout10ms,
GpibTimeout30ms,
GpibTimeout100ms,
GpibTimeout300ms,
GpibTimeout1s,
GpibTimeout3s,
GpibTimeout10s,
GpibTimeout30s,
GpibTimeout100s,
GpibTimeout300s,
GpibTimeout1000s
};
struct Gpib_DCS
{
int m_address1;
int m_address2;
GpibTimeout m_timeout;
bool m_eot;
unsigned char m_eosChar;
unsigned char m_eosMode;
Gpib_DCS();
~Gpib_DCS();
char* GetSettings();
};
enum {
CTB_GPIB_SETADR = CTB_GPIB,
CTB_GPIB_GETRSP,
CTB_GPIB_GETSTA,
CTB_GPIB_GETERR,
CTB_GPIB_GETLINES,
CTB_GPIB_SETTIMEOUT,
CTB_GPIB_GTL,
CTB_GPIB_REN,
CTB_GPIB_RESET_BUS,
CTB_GPIB_SET_EOS_CHAR,
CTB_GPIB_GET_EOS_CHAR,
CTB_GPIB_SET_EOS_MODE,
CTB_GPIB_GET_EOS_MODE
};
class GpibDevice : public IOBase
{
protected:
int m_board;
int m_hd;
int m_state;
int m_error;
int m_count;
int m_asyncio;
Gpib_DCS m_dcs;
int CloseDevice();
int OpenDevice(const char* devname, void* dcs);
virtual const char* GetErrorString(int error,bool detailed);
public:
GpibDevice();
virtual ~GpibDevice();
const char* ClassName();
virtual const char* GetErrorDescription(int error);
virtual const char* GetErrorNotation(int error);
virtual char* GetSettingsAsString();
int Ibrd(char* buf,size_t len);
int Ibwrt(char* buf,size_t len);
virtual int Ioctl(int cmd,void* args);
int IsOpen();
int Read(char* buf,size_t len);
int Write(char* buf,size_t len);
static int FindListeners(int board = 0);
};
};
@@ -0,0 +1,59 @@
%{
#include "ctb-0.16/iobase.h"
%}
namespace ctb {
enum {
CTB_RESET = CTB_COMMON
};
%typemap(in) char *& readbuf (char * tmp) {
/* dont check for list */
$1 = &tmp;
}
%typemap(argout) char *& readbuf {
PyObject * plist = PyList_New(2);
PyList_SetItem(plist, 0, PyString_FromString(*$1));
PyList_SetItem(plist, 1, $result);
$result = plist;
delete *$1;
}
%typemap(in) size_t * readedBytes (size_t tmp) {
/* dont check for list */
$1 = &tmp;
}
%typemap(argout) size_t * readedBytes {
PyList_Append($result, PyInt_FromLong(*$1));
}
class IOBase
{
protected:
virtual int CloseDevice() = 0;
virtual int OpenDevice(const char* devname, void* dcs = 0L) = 0;
public:
IOBase();
virtual ~IOBase();
virtual const char* ClassName();
int Close();
virtual int Ioctl(int cmd,void* args);
virtual int IsOpen() = 0;
int Open(const char* devname,void* dcs=0L);
int PutBack(char ch);
virtual int Read(char* buf,size_t len) = 0;
virtual int ReadUntilEOS(char*& readbuf,
size_t* readedBytes,
char* eosString = "\n",
long timeout_in_ms = 1000L,
char quota = 0);
int Readv(char* buf,size_t len,unsigned int timeout_in_ms);
virtual int Write(char* buf,size_t len) = 0;
int Writev(char* buf,size_t len,unsigned int timeout_in_ms);
};
};
@@ -0,0 +1,9 @@
%{
#include "ctb-0.16/kbhit.h"
%}
namespace ctb {
char GetKey();
};
@@ -0,0 +1,63 @@
#!/bin/bash
CFLAG=''
GPIB_SOURCES=''
GPIB_LIB=''
GPIB_SUPPORT=''
# the python develop version. Please check the right version of your
# python developent enviroment
PYTHON_VERSION='2.6'
for arg in $*; do
if [ "$arg" = "USE_GPIB" ]; then
GPIB_SOURCES='../../../src/gpib.cpp'
GPIB_LIB='-lgpib'
GPIB_SUPPORT='Yes'
else
echo '============================================================'
echo 'You run makepy.sh without GPIB support.'
echo 'If you want to create the python wxctb library with'
echo 'GPIB support, rerun the command with:'
echo 'makepy.sh USE_GPIB=1'
echo '============================================================'
GPIB_SUPPORT='No'
fi
if [ "$arg" = "USE_DEBUG" ]; then
CFLAG='-g'
fi
done
echo "// This file is created automatically, don't change it!" > wxctb.i
echo "%module wxctb" >> wxctb.i
echo "typedef int size_t;" >> wxctb.i
echo "%include timer.i" >> wxctb.i
echo "%include serport.i" >> wxctb.i
echo "%include ../kbhit.i" >> wxctb.i
if [ "$arg" = "USE_GPIB" ]; then
echo "%include ../gpib.i" >> wxctb.i
fi
echo "swig generates python wrapper files..."
swig -c++ -Wall -nodefault -python -keyword -new_repr -modern wxctb.i
echo "create shared library wxctb with GPIB=$GPIB_SUPPORT for python"\
"$PYTHON_VERSION ..."
g++ -Wall $CFLAG -shared -I /usr/include/python$PYTHON_VERSION/ \
-I ../../../include \
wxctb_wrap.cxx \
../../../src/linux/timer.cpp \
../../../src/linux/serport.cpp \
../../../src/serportx.cpp \
../../../src/kbhit.cpp \
../../../src/iobase.cpp \
../../../src/fifo.cpp \
$GPIB_SOURCES \
$GPIB_LIB \
-o _wxctb.so
echo "copy ctb.py, wxctb.py and _wxctb.so to the module/linux folder..."
mkdir -p ../../module/linux
cp ../ctb.py ../../module/linux/
cp wxctb.py ../../module/linux/
cp _wxctb.so ../../module/linux/
@@ -0,0 +1,50 @@
%module serport
%{
#include "ctb-0.16/linux/serport.h"
%}
%include ../serportx.i
namespace ctb {
%pythoncode {
COM1 = "/dev/ttyS0"
COM2 = "/dev/ttyS1"
COM3 = "/dev/ttyS2"
COM4 = "/dev/ttyS3"
COM5 = "/dev/ttyS4"
COM6 = "/dev/ttyS5"
COM7 = "/dev/ttyS6"
COM8 = "/dev/ttyS7"
COM9 = "/dev/ttyS8"
};
class SerialPort : public SerialPort_x
{
protected:
int fd;
struct termios t, save_t;
struct serial_icounter_struct save_info, last_info;
speed_t AdaptBaudrate(int baud);
int CloseDevice();
int OpenDevice(const char* devname, void* dcs);
public:
SerialPort();
~SerialPort();
int ChangeLineState(SerialLineState flags);
int ClrLineState(SerialLineState flags);
int GetLineState();
int Ioctl(int cmd,void* args);
int IsOpen();
int Read(char* buf,size_t len);
int SendBreak(int duration);
int SetBaudrate(int baudrate);
int SetLineState(SerialLineState flags);
int SetParityBit( bool parity );
int Write(char* buf,size_t len);
};
};
@@ -0,0 +1,37 @@
%{
#include "ctb-0.16/linux/timer.h"
%}
%include cpointer.i
// lets create new fuctions for pointer handling in python (for int *exitflag)
%pointer_functions(int, intp);
namespace ctb {
// perhaps we doesn''t need timer_control to export
// but we need if we want to inherit from timer in python
struct timer_control
{
unsigned int usecs;
int *exitflag;
void* (*exitfnc)(void*);
};
class Timer
{
protected:
timer_control control;
int stopped;
pthread_t tid;
unsigned int timer_secs;
public:
Timer(unsigned int msec,int* exitflag,void*(*exitfnc)(void*)=NULL);
~Timer();
int start();
int stop();
};
void sleepms(unsigned int ms);
};
@@ -0,0 +1,6 @@
// This file is created automatically, don't change it!
%module wxctb
typedef int size_t;
%include timer.i
%include serport.i
%include ../kbhit.i
@@ -0,0 +1,264 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.40
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_wxctb', [dirname(__file__)])
except ImportError:
import _wxctb
return _wxctb
if fp is not None:
try:
_mod = imp.load_module('_wxctb', fp, pathname, description)
finally:
fp.close()
return _mod
_wxctb = swig_import_helper()
del swig_import_helper
else:
import _wxctb
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static) or hasattr(self,name):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)
def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0
def _swig_setattr_nondynamic_method(set):
def set_attr(self,name,value):
if (name == "thisown"): return self.this.own(value)
if hasattr(self,name) or (name == "this"):
set(self,name,value)
else:
raise AttributeError("You cannot add attributes to %s" % self)
return set_attr
def new_intp():
return _wxctb.new_intp()
new_intp = _wxctb.new_intp
def copy_intp(*args, **kwargs):
return _wxctb.copy_intp(*args, **kwargs)
copy_intp = _wxctb.copy_intp
def delete_intp(*args, **kwargs):
return _wxctb.delete_intp(*args, **kwargs)
delete_intp = _wxctb.delete_intp
def intp_assign(*args, **kwargs):
return _wxctb.intp_assign(*args, **kwargs)
intp_assign = _wxctb.intp_assign
def intp_value(*args, **kwargs):
return _wxctb.intp_value(*args, **kwargs)
intp_value = _wxctb.intp_value
class timer_control(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
__repr__ = _swig_repr
usecs = _swig_property(_wxctb.timer_control_usecs_get, _wxctb.timer_control_usecs_set)
exitflag = _swig_property(_wxctb.timer_control_exitflag_get, _wxctb.timer_control_exitflag_set)
exitfnc = _swig_property(_wxctb.timer_control_exitfnc_get, _wxctb.timer_control_exitfnc_set)
timer_control_swigregister = _wxctb.timer_control_swigregister
timer_control_swigregister(timer_control)
class Timer(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
def __init__(self, *args, **kwargs):
this = _wxctb.new_Timer(*args, **kwargs)
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _wxctb.delete_Timer
__del__ = lambda self : None;
def start(self): return _wxctb.Timer_start(self)
def stop(self): return _wxctb.Timer_stop(self)
Timer_swigregister = _wxctb.Timer_swigregister
Timer_swigregister(Timer)
def sleepms(*args, **kwargs):
return _wxctb.sleepms(*args, **kwargs)
sleepms = _wxctb.sleepms
CTB_RESET = _wxctb.CTB_RESET
class IOBase(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined - class is abstract")
__repr__ = _swig_repr
__swig_destroy__ = _wxctb.delete_IOBase
__del__ = lambda self : None;
def ClassName(self): return _wxctb.IOBase_ClassName(self)
def Close(self): return _wxctb.IOBase_Close(self)
def Ioctl(self, *args, **kwargs): return _wxctb.IOBase_Ioctl(self, *args, **kwargs)
def IsOpen(self): return _wxctb.IOBase_IsOpen(self)
def Open(self, *args, **kwargs): return _wxctb.IOBase_Open(self, *args, **kwargs)
def PutBack(self, *args, **kwargs): return _wxctb.IOBase_PutBack(self, *args, **kwargs)
def Read(self, *args, **kwargs): return _wxctb.IOBase_Read(self, *args, **kwargs)
def ReadUntilEOS(self, *args, **kwargs): return _wxctb.IOBase_ReadUntilEOS(self, *args, **kwargs)
def Readv(self, *args, **kwargs): return _wxctb.IOBase_Readv(self, *args, **kwargs)
def Write(self, *args, **kwargs): return _wxctb.IOBase_Write(self, *args, **kwargs)
def Writev(self, *args, **kwargs): return _wxctb.IOBase_Writev(self, *args, **kwargs)
IOBase_swigregister = _wxctb.IOBase_swigregister
IOBase_swigregister(IOBase)
ParityNone = _wxctb.ParityNone
ParityOdd = _wxctb.ParityOdd
ParityEven = _wxctb.ParityEven
ParityMark = _wxctb.ParityMark
ParitySpace = _wxctb.ParitySpace
LinestateDcd = _wxctb.LinestateDcd
LinestateCts = _wxctb.LinestateCts
LinestateDsr = _wxctb.LinestateDsr
LinestateDtr = _wxctb.LinestateDtr
LinestateRing = _wxctb.LinestateRing
LinestateRts = _wxctb.LinestateRts
LinestateNull = _wxctb.LinestateNull
class SerialPort_DCS(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
baud = _swig_property(_wxctb.SerialPort_DCS_baud_get, _wxctb.SerialPort_DCS_baud_set)
parity = _swig_property(_wxctb.SerialPort_DCS_parity_get, _wxctb.SerialPort_DCS_parity_set)
wordlen = _swig_property(_wxctb.SerialPort_DCS_wordlen_get, _wxctb.SerialPort_DCS_wordlen_set)
stopbits = _swig_property(_wxctb.SerialPort_DCS_stopbits_get, _wxctb.SerialPort_DCS_stopbits_set)
rtscts = _swig_property(_wxctb.SerialPort_DCS_rtscts_get, _wxctb.SerialPort_DCS_rtscts_set)
xonxoff = _swig_property(_wxctb.SerialPort_DCS_xonxoff_get, _wxctb.SerialPort_DCS_xonxoff_set)
buf = _swig_property(_wxctb.SerialPort_DCS_buf_get, _wxctb.SerialPort_DCS_buf_set)
def __init__(self):
this = _wxctb.new_SerialPort_DCS()
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _wxctb.delete_SerialPort_DCS
__del__ = lambda self : None;
def GetSettings(self): return _wxctb.SerialPort_DCS_GetSettings(self)
SerialPort_DCS_swigregister = _wxctb.SerialPort_DCS_swigregister
SerialPort_DCS_swigregister(SerialPort_DCS)
class SerialPort_EINFO(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
brk = _swig_property(_wxctb.SerialPort_EINFO_brk_get, _wxctb.SerialPort_EINFO_brk_set)
frame = _swig_property(_wxctb.SerialPort_EINFO_frame_get, _wxctb.SerialPort_EINFO_frame_set)
overrun = _swig_property(_wxctb.SerialPort_EINFO_overrun_get, _wxctb.SerialPort_EINFO_overrun_set)
parity = _swig_property(_wxctb.SerialPort_EINFO_parity_get, _wxctb.SerialPort_EINFO_parity_set)
def __init__(self):
this = _wxctb.new_SerialPort_EINFO()
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _wxctb.delete_SerialPort_EINFO
__del__ = lambda self : None;
SerialPort_EINFO_swigregister = _wxctb.SerialPort_EINFO_swigregister
SerialPort_EINFO_swigregister(SerialPort_EINFO)
CTB_SER_GETEINFO = _wxctb.CTB_SER_GETEINFO
CTB_SER_GETBRK = _wxctb.CTB_SER_GETBRK
CTB_SER_GETFRM = _wxctb.CTB_SER_GETFRM
CTB_SER_GETOVR = _wxctb.CTB_SER_GETOVR
CTB_SER_GETPAR = _wxctb.CTB_SER_GETPAR
CTB_SER_GETINQUE = _wxctb.CTB_SER_GETINQUE
CTB_SER_SETPAR = _wxctb.CTB_SER_SETPAR
class SerialPort_x(IOBase):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined - class is abstract")
__repr__ = _swig_repr
__swig_destroy__ = _wxctb.delete_SerialPort_x
__del__ = lambda self : None;
def ClassName(self): return _wxctb.SerialPort_x_ClassName(self)
def ChangeLineState(self, *args, **kwargs): return _wxctb.SerialPort_x_ChangeLineState(self, *args, **kwargs)
def ClrLineState(self, *args, **kwargs): return _wxctb.SerialPort_x_ClrLineState(self, *args, **kwargs)
def GetLineState(self): return _wxctb.SerialPort_x_GetLineState(self)
def GetSettingsAsString(self): return _wxctb.SerialPort_x_GetSettingsAsString(self)
def Ioctl(self, *args, **kwargs): return _wxctb.SerialPort_x_Ioctl(self, *args, **kwargs)
def SendBreak(self, *args, **kwargs): return _wxctb.SerialPort_x_SendBreak(self, *args, **kwargs)
def SetBaudrate(self, *args, **kwargs): return _wxctb.SerialPort_x_SetBaudrate(self, *args, **kwargs)
def SetLineState(self, *args, **kwargs): return _wxctb.SerialPort_x_SetLineState(self, *args, **kwargs)
def SetParityBit(self, *args, **kwargs): return _wxctb.SerialPort_x_SetParityBit(self, *args, **kwargs)
IsStandardRate = staticmethod(_wxctb.SerialPort_x_IsStandardRate)
SerialPort_x_swigregister = _wxctb.SerialPort_x_swigregister
SerialPort_x_swigregister(SerialPort_x)
def SerialPort_x_IsStandardRate(*args, **kwargs):
return _wxctb.SerialPort_x_IsStandardRate(*args, **kwargs)
SerialPort_x_IsStandardRate = _wxctb.SerialPort_x_IsStandardRate
COM1 = "/dev/ttyS0"
COM2 = "/dev/ttyS1"
COM3 = "/dev/ttyS2"
COM4 = "/dev/ttyS3"
COM5 = "/dev/ttyS4"
COM6 = "/dev/ttyS5"
COM7 = "/dev/ttyS6"
COM8 = "/dev/ttyS7"
COM9 = "/dev/ttyS8"
class SerialPort(SerialPort_x):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
def __init__(self):
this = _wxctb.new_SerialPort()
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _wxctb.delete_SerialPort
__del__ = lambda self : None;
def ChangeLineState(self, *args, **kwargs): return _wxctb.SerialPort_ChangeLineState(self, *args, **kwargs)
def ClrLineState(self, *args, **kwargs): return _wxctb.SerialPort_ClrLineState(self, *args, **kwargs)
def GetLineState(self): return _wxctb.SerialPort_GetLineState(self)
def Ioctl(self, *args, **kwargs): return _wxctb.SerialPort_Ioctl(self, *args, **kwargs)
def IsOpen(self): return _wxctb.SerialPort_IsOpen(self)
def Read(self, *args, **kwargs): return _wxctb.SerialPort_Read(self, *args, **kwargs)
def SendBreak(self, *args, **kwargs): return _wxctb.SerialPort_SendBreak(self, *args, **kwargs)
def SetBaudrate(self, *args, **kwargs): return _wxctb.SerialPort_SetBaudrate(self, *args, **kwargs)
def SetLineState(self, *args, **kwargs): return _wxctb.SerialPort_SetLineState(self, *args, **kwargs)
def SetParityBit(self, *args, **kwargs): return _wxctb.SerialPort_SetParityBit(self, *args, **kwargs)
def Write(self, *args, **kwargs): return _wxctb.SerialPort_Write(self, *args, **kwargs)
SerialPort_swigregister = _wxctb.SerialPort_swigregister
SerialPort_swigregister(SerialPort)
def GetKey():
return _wxctb.GetKey()
GetKey = _wxctb.GetKey
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,84 @@
%{
#include "ctb-0.16/serportx.h"
%}
%include iobase.i
namespace ctb {
enum Parity
{
ParityNone,
ParityOdd,
ParityEven,
ParityMark,
ParitySpace
};
enum SerialLineState
{
LinestateDcd = 0x040,
LinestateCts = 0x020,
LinestateDsr = 0x100,
LinestateDtr = 0x002,
LinestateRing = 0x080,
LinestateRts = 0x004,
LinestateNull = 0x000
};
struct SerialPort_DCS
{
int baud;
Parity parity;
unsigned char wordlen;
unsigned char stopbits;
bool rtscts;
bool xonxoff;
char buf[16];
SerialPort_DCS();
~SerialPort_DCS();
char* GetSettings();
};
struct SerialPort_EINFO
{
int brk;
int frame;
int overrun;
int parity;
SerialPort_EINFO();
~SerialPort_EINFO();
};
enum {
CTB_SER_GETEINFO = CTB_SERIAL,
CTB_SER_GETBRK,
CTB_SER_GETFRM,
CTB_SER_GETOVR,
CTB_SER_GETPAR,
CTB_SER_GETINQUE,
CTB_SER_SETPAR,
};
class SerialPort_x : public IOBase
{
protected:
SerialPort_DCS m_dcs;
char m_devname[SERIALPORT_NAME_LEN];
public:
SerialPort_x();
virtual ~SerialPort_x();
const char* ClassName();
virtual int ChangeLineState(SerialLineState flags) = 0;
virtual int ClrLineState(SerialLineState flags) = 0;
virtual int GetLineState() = 0;
virtual char* GetSettingsAsString();
virtual int Ioctl(int cmd,void* args);
virtual int SendBreak(int duration) = 0;
virtual int SetBaudrate(int baudrate) = 0;
virtual int SetLineState(SerialLineState flags) = 0;
virtual int SetParityBit( bool parity ) = 0;
static bool IsStandardRate( long rate );
};
};
@@ -0,0 +1,65 @@
@ECHO OFF
REM ##################################################################
REM # set the path/settings of your compiler enviroment and remove the
REM # comment command (REM)
REM # (you don't need this, if you set it always in your system
REM # enviroment)
REM ##################################################################
REM CALL "c:\Programme\Microsoft Visual C++ Toolkit 2003\vcvars32.bat"
REM ##################################################################
REM # set the path to your python24 (or python23) library, for example
REM # works for me with C:\Program Files\Python2.4\libs\python24.lib
REM ##################################################################
SET PYTHON_LIB="C:\Program Files\Python2.4\libs\python24.lib"
REM ##################################################################
REM # set the include path of your python24 (python23) deleveloper
REM # header files. For me, it's on C:\Program Files
REM ##################################################################
SET PYTHON_INCLUDE="C:\Program Files\Python2.4\include"
REM ##################################################################
REM # after installing swig, set the path, so the script can find it
REM ##################################################################
SET SWIG="C:\Program Files\swigwin-1.3.40\swig"
REM ##################################################################
REM # DON'T CHANGE ANYMORE AT THE FOLLOWING LINES!!!
REM ##################################################################
SET GPIB_LIB=
SET GPIB_SRC=
ECHO // This file is created automatically, don't change it! > wxctb.i
ECHO %%module wxctb >> wxctb.i
ECHO typedef int size_t; >> wxctb.i
ECHO %%include timer.i >> wxctb.i
ECHO %%include serport.i >> wxctb.i
ECHO %%include ../kbhit.i >> wxctb.i
IF NOT [%1]==[USE_GPIB] GOTO nogpib
SET GPIB_LIB=../../../lib/gpib32.lib
SET GPIB_SRC=../../../src/gpib.cpp
ECHO %%include ../gpib.i >> wxctb.i
:nogpib
DEL *.obj wxctb_wrap.cxx *.lib *.dll *.exp
ECHO "swig generates python wrapper files..."
%SWIG% -c++ -Wall -nodefault -python -keyword -new_repr -modern wxctb.i
ECHO "create shared library wxctb for python 2.4..."
cl /LD /D WIN32 /I %PYTHON_INCLUDE% /I ../../../include wxctb_wrap.cxx ../../../src/win32/serport.cpp ../../../src/serportx.cpp ../../../src/win32/timer.cpp ../../../src/kbhit.cpp ../../../src/iobase.cpp %GPIB_SRC% ../../../src/fifo.cpp /link %PYTHON_LIB% winmm.lib %GPIB_LIB%
MOVE wxctb_wrap.dll _wxctb.dll
ECHO "copy ctb.py, wxctb.py and _wxctb.so to the module/win32 folder..."
MKDIR ..\..\module\win32
COPY ..\ctb.py ..\..\module\win32
COPY wxctb.py ..\..\module\win32
COPY _wxctb.dll ..\..\module\win32
@@ -0,0 +1,57 @@
%{
#include "ctb-0.16/win32/serport.h"
%}
%include ../serportx.i
namespace ctb {
%pythoncode {
COM1 = "com1"
COM2 = "com2"
COM3 = "com3"
COM4 = "com4"
COM5 = "com5"
COM6 = "com6"
COM7 = "com7"
COM8 = "com8"
COM9 = "com9"
COM10 = "\\\\.\\com10"
COM11 = "\\\\.\\com11"
COM12 = "\\\\.\\com12"
COM13 = "\\\\.\\com13"
COM14 = "\\\\.\\com14"
COM15 = "\\\\.\\com15"
COM16 = "\\\\.\\com16"
COM17 = "\\\\.\\com17"
COM18 = "\\\\.\\com18"
COM19 = "\\\\.\\com19"
};
class SerialPort : public SerialPort_x
{
protected:
HANDLE fd;
OVERLAPPED ov;
SerialPort_EINFO einfo;
int CloseDevice();
int OpenDevice(const char* devname, void* dcs);
public:
SerialPort();
~SerialPort();
int ChangeLineState(SerialLineState flags);
int ClrLineState(SerialLineState flags);
int GetLineState();
int Ioctl(int cmd,void* args);
int IsOpen();
int Read(char* buf,size_t len);
int SendBreak(int duration);
int SetBaudrate(int baudrate);
int SetLineState(SerialLineState flags);
int SetParityBit( bool parity );
int Write(char* buf,size_t len);
};
};
@@ -0,0 +1,39 @@
%{
#include "ctb-0.16/win32/timer.h"
%}
%include cpointer.i
// lets create new fuctions for pointer handling in python (for int *exitflag)
%pointer_functions(int, intp);
namespace ctb {
// perhaps we doesn''t need timer_control to export
// but we need if we want to inherit from timer in python
struct timer_control
{
unsigned int msecs;
int *exitflag;
MMRESULT stop;
void* (*exitfnc)(void*);
};
class Timer
{
protected:
DWORD id;
MMRESULT h;
timer_control control;
unsigned int timer_secs;
public:
Timer(unsigned int msec,int* exitflag,void*(*exitfnc)(void*)=NULL);
~Timer();
int start();
int stop();
};
void sleepms(unsigned int ms);
};
@@ -0,0 +1,6 @@
// This file is created automatically, don't change it!
%module wxctb
typedef int size_t;
%include timer.i
%include serport.i
%include ../kbhit.i