botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
bsI2C.py
Go to the documentation of this file.
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 3.0.8
3 #
4 # Do not make changes to this file unless you know what you are doing--modify
5 # the SWIG interface file instead.
6 
7 
8 
9 
10 
11 from sys import version_info
12 if version_info >= (2, 6, 0):
13  def swig_import_helper():
14  from os.path import dirname
15  import imp
16  fp = None
17  try:
18  fp, pathname, description = imp.find_module('_bsI2C', [dirname(__file__)])
19  except ImportError:
20  import _bsI2C
21  return _bsI2C
22  if fp is not None:
23  try:
24  _mod = imp.load_module('_bsI2C', fp, pathname, description)
25  finally:
26  fp.close()
27  return _mod
28  _bsI2C = swig_import_helper()
29  del swig_import_helper
30 else:
31  import _bsI2C
32 del version_info
33 try:
34  _swig_property = property
35 except NameError:
36  pass # Python < 2.2 doesn't have 'property'.
37 
38 
39 def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
40  if (name == "thisown"):
41  return self.this.own(value)
42  if (name == "this"):
43  if type(value).__name__ == 'SwigPyObject':
44  self.__dict__[name] = value
45  return
46  method = class_type.__swig_setmethods__.get(name, None)
47  if method:
48  return method(self, value)
49  if (not static):
50  if _newclass:
51  object.__setattr__(self, name, value)
52  else:
53  self.__dict__[name] = value
54  else:
55  raise AttributeError("You cannot add attributes to %s" % self)
56 
57 
58 def _swig_setattr(self, class_type, name, value):
59  return _swig_setattr_nondynamic(self, class_type, name, value, 0)
60 
61 
62 def _swig_getattr_nondynamic(self, class_type, name, static=1):
63  if (name == "thisown"):
64  return self.this.own()
65  method = class_type.__swig_getmethods__.get(name, None)
66  if method:
67  return method(self)
68  if (not static):
69  return object.__getattr__(self, name)
70  else:
71  raise AttributeError(name)
72 
73 def _swig_getattr(self, class_type, name):
74  return _swig_getattr_nondynamic(self, class_type, name, 0)
75 
76 
77 def _swig_repr(self):
78  try:
79  strthis = "proxy of " + self.this.__repr__()
80  except Exception:
81  strthis = ""
82  return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
83 
84 try:
85  _object = object
86  _newclass = 1
87 except AttributeError:
88  class _object:
89  pass
90  _newclass = 0
91 
92 
93 
94 _bsI2C.BS_I2C_DEV_NAME_DFT_swigconstant(_bsI2C)
95 BS_I2C_DEV_NAME_DFT = _bsI2C.BS_I2C_DEV_NAME_DFT
96 
97 _bsI2C.BS_I2C_SERVER_MOD_swigconstant(_bsI2C)
98 BS_I2C_SERVER_MOD = _bsI2C.BS_I2C_SERVER_MOD
99 
100 _bsI2C.BS_I2C_CLIENT_LIB_swigconstant(_bsI2C)
101 BS_I2C_CLIENT_LIB = _bsI2C.BS_I2C_CLIENT_LIB
102 
103 def bsI2CGetMsgName(pClient, hndVConn, uMsgId):
104  return _bsI2C.bsI2CGetMsgName(pClient, hndVConn, uMsgId)
105 bsI2CGetMsgName = _bsI2C.bsI2CGetMsgName
106 
107 def bsI2CReqOpen(pClient, sDevName, bInitTrace):
108  return _bsI2C.bsI2CReqOpen(pClient, sDevName, bInitTrace)
109 bsI2CReqOpen = _bsI2C.bsI2CReqOpen
110 
111 def bsI2CReqClose(pClient, hndVConn):
112  return _bsI2C.bsI2CReqClose(pClient, hndVConn)
113 bsI2CReqClose = _bsI2C.bsI2CReqClose
114 
115 def bsI2CReqRead(pClient, hndVConn, i2cAddr, uReadLen, rbuf):
116  return _bsI2C.bsI2CReqRead(pClient, hndVConn, i2cAddr, uReadLen, rbuf)
117 bsI2CReqRead = _bsI2C.bsI2CReqRead
118 
119 def bsI2CReqWrite(pClient, hndVConn, i2cAddr, wbuf, uWriteLen):
120  return _bsI2C.bsI2CReqWrite(pClient, hndVConn, i2cAddr, wbuf, uWriteLen)
121 bsI2CReqWrite = _bsI2C.bsI2CReqWrite
122 
123 def bsI2CReqTrans(pClient, hndVConn, i2cAddr, wbuf, uWriteLen, uReadLen, rbuf):
124  return _bsI2C.bsI2CReqTrans(pClient, hndVConn, i2cAddr, wbuf, uWriteLen, uReadLen, rbuf)
125 bsI2CReqTrans = _bsI2C.bsI2CReqTrans
126 
127 def bsI2CReqScan(pClient, hndVConn, bufScan, sizeScanBuf):
128  return _bsI2C.bsI2CReqScan(pClient, hndVConn, bufScan, sizeScanBuf)
129 bsI2CReqScan = _bsI2C.bsI2CReqScan
130 
131 def new_i2cAddrArray(nelements):
132  return _bsI2C.new_i2cAddrArray(nelements)
133 new_i2cAddrArray = _bsI2C.new_i2cAddrArray
134 
135 def delete_i2cAddrArray(ary):
136  return _bsI2C.delete_i2cAddrArray(ary)
137 delete_i2cAddrArray = _bsI2C.delete_i2cAddrArray
138 
139 def i2cAddrArray_getitem(ary, index):
140  return _bsI2C.i2cAddrArray_getitem(ary, index)
141 i2cAddrArray_getitem = _bsI2C.i2cAddrArray_getitem
142 
143 def i2cAddrArray_setitem(ary, index, value):
144  return _bsI2C.i2cAddrArray_setitem(ary, index, value)
145 i2cAddrArray_setitem = _bsI2C.i2cAddrArray_setitem
146 
147 
148 #
149 # BotSense I2C Python Wrappers
150 #
151 
152 """
153 BotSense I2C Python Inline Extensions and Wrappers.
154 """
155 
156 ## \file
157 ## \package BotSense.bsI2C
158 ##
159 ## \brief BotSense Swigged I2C Python Interface Module.
160 ##
161 ## \author Robin Knight (robin.knight@roadnarrows.com)
162 ##
163 ## \par Copyright:
164 ## (C) 2010. RoadNarrows LLC.\n
165 ## (http://www.roadnarrows.com)\n
166 ## All Rights Reserved
167 ##
168 
169 import BotSenseCore as bsCore
170 import BotSenseError as bsError
171 import BotSenseTypes as bsTypes
172 
173 # maximum number of scanned I2C attached device addresses
174 I2CMaxNumOfScannedAddrs = 256
175 
176 def I2CGetMsgName(client, hndVConn, msgId):
177  """ Get the I2C message name.
178 
179  For each (virtual connection, message id) 2-tuple, there can be a known
180  name string (provided the id is valid and an application provides the
181  information).
182 
183  Parameters:
184  client - BotSenseTypes.BsClient instance.
185  hndVConn - Virtual connection handle (ignored).
186  msgId - I2C message id.
187 
188  Return:
189  Returns message name string if it can be determined.
190  Otherwise returns 'unknown'.
191  """
192  bsTypes.BsClient.ChkClient(client)
193  return bsI2CGetMsgName(client.pClient, hndVConn, msgId)
194 
195 def I2CReqOpen(client, devName, trace=False):
196  """ Proxy server request to establish a virtual connection to an
197  I2C bus device.
198 
199  Raises a BotSenseError exception on failure.
200 
201  Parameters:
202  client - BotSenseTypes.BsClient instance.
203  devName - Proxied I2C device name (e.g. /dev/i2c-0).
204  trace - Initial message tracing enable(true)/disable(false) state.
205 
206  Return
207  New virtual connection handle.
208  """
209  bsTypes.BsClient.ChkClient(client)
210  hndVConn = bsI2CReqOpen(client.pClient, devName, trace)
211  bsError.ChkReturnIsNonNeg(hndVConn,
212  "Client %s: I2C Open request failed." % (client.AttrGetName()))
213  return hndVConn
214 
215 def I2CReqClose(client, hndVConn):
216  """ Proxy server request to close client's proxied I2C bus device virtual
217  connection.
218 
219  Raises a BotSenseError exception on failure.
220 
221  Parameters:
222  client - BotSenseTypes.BsClient instance.
223  hndVConn - Virtual connection handle.
224  """
225  bsTypes.BsClient.ChkClient(client)
226  rc = bsI2CReqClose(client.pClient, hndVConn)
227  bsError.ChkReturnIsOk(rc,
228  "Client %s: I2C Close request failed." % (client.AttrGetName()))
229 
230 def I2CReqRead(client, hndVConn, i2cAddr, readLen):
231  """ I2C request to read from a device attached to a proxied I2C bus.
232 
233  Raises a BotSenseError exception on failure.
234 
235  Parameters:
236  client - BotSenseTypes.BsClient instance.
237  hndVConn - Virtual connection handle.
238  i2cAddr - Address of attached device on the I2C bus.
239  readLen - Number of bytes to read.
240 
241  Return:
242  Buffer list of read bytes.
243  """
244  bsTypes.BsClient.ChkClient(client)
245  rbytebuf = bsTypes.ByteBuf(readLen)
246  n = bsI2CReqRead(client.pClient, hndVConn, i2cAddr, readLen,
247  rbytebuf.getSwigObj())
248  bsError.ChkReturnIsNonNeg(n,
249  "Client %s: I2C Read request failed." % (client.AttrGetName()))
250  rbytebuf.copyFromSwigObj(n)
251  return rbytebuf.buf
252 
253 def I2CReqWrite(client, hndVConn, i2cAddr, wbuf):
254  """ I2C request to write to a device attached to a proxied I2C bus.
255 
256  Raises a BotSenseError exception on failure.
257 
258  Parameters:
259  client - BotSenseTypes.BsClient instance.
260  hndVConn - Virtual connection handle.
261  i2cAddr - Address of attached device on the I2C bus.
262  wbuf - Write buffer.
263 
264  Return:
265  Number of bytes written.
266  """
267  bsTypes.BsClient.ChkClient(client)
268  wbytebuf = bsTypes.ByteBuf.Clone(wbuf)
269  wbytebuf.copyToSwigObj(len(wbytebuf))
270  n = bsI2CReqWrite(client.pClient, hndVConn, i2cAddr, wbytebuf.getSwigObj(),
271  len(wbytebuf))
272  bsError.ChkReturnIsNonNeg(n,
273  "Client %s: I2C Write request failed." % (client.AttrGetName()))
274  return n
275 
276 def I2CReqTrans(client, hndVConn, i2cAddr, wbuf, readLen):
277  """ I2C request to execute a write-read transaction to a device
278  attached to a proxied I2C bus.
279 
280  Raises a BotSenseError exception on failure.
281 
282  Parameters:
283  client - BotSenseTypes.BsClient instance.
284  hndVConn - Virtual connection handle.
285  i2cAddr - Address of attached device on the I2C bus.
286  wbuf - Write buffer.
287  readLen - Number of bytes to read.
288 
289  Return:
290  Buffer list of read bytes.
291  """
292  bsTypes.BsClient.ChkClient(client)
293  wbytebuf = bsTypes.ByteBuf.Clone(wbuf)
294  wbytebuf.copyToSwigObj(len(wbytebuf))
295  rbytebuf = bsTypes.ByteBuf(readLen)
296  n = bsI2CReqTrans(client.pClient, hndVConn, i2cAddr,
297  wbytebuf.getSwigObj(), len(wbytebuf),
298  readLen, rbytebuf.getSwigObj())
299  bsError.ChkReturnIsNonNeg(n,
300  "Client %s: I2C Transaction request failed." % (client.AttrGetName()))
301  rbytebuf.copyFromSwigObj(n)
302  return rbytebuf.buf
303 
304 def I2CReqScan(client, hndVConn):
305  """ I2C request to scan a proxied I2C bus for attached devices.
306 
307  Raises a BotSenseError exception on failure.
308 
309  Parameters:
310  client - BotSenseTypes.BsClient instance.
311  hndVConn - Virtual connection handle.
312 
313  Return:
314  List of I2C address of discovered attached devices.
315  """
316  bsTypes.BsClient.ChkClient(client)
317  swigObj = new_i2cAddrArray(I2CMaxNumOfScannedAddrs)
318  n = bsI2CReqScan(client.pClient, hndVConn, swigObj, I2CMaxNumOfScannedAddrs)
319  bsError.ChkReturnIsNonNeg(n,
320  "Client %s: I2C Read request failed." % (client.AttrGetName()))
321  addrs = []
322  for i in xrange(n):
323  addrs += [ i2cAddrArray_getitem(swigObj, i) ]
324  return addrs
325 
326 
327 # This file is compatible with both classic and new-style classes.
328 
329 
def I2CReqOpen(client, devName, trace=False)
Definition: bsI2C.py:195
def I2CReqClose(client, hndVConn)
Definition: bsI2C.py:215
def I2CReqScan(client, hndVConn)
Definition: bsI2C.py:304
def I2CReqTrans(client, hndVConn, i2cAddr, wbuf, readLen)
Definition: bsI2C.py:276
def I2CGetMsgName(client, hndVConn, msgId)
Definition: bsI2C.py:176
def I2CReqWrite(client, hndVConn, i2cAddr, wbuf)
Definition: bsI2C.py:253
def I2CReqRead(client, hndVConn, i2cAddr, readLen)
Definition: bsI2C.py:230