botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
bsSerial.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('_bsSerial', [dirname(__file__)])
19  except ImportError:
20  import _bsSerial
21  return _bsSerial
22  if fp is not None:
23  try:
24  _mod = imp.load_module('_bsSerial', fp, pathname, description)
25  finally:
26  fp.close()
27  return _mod
28  _bsSerial = swig_import_helper()
29  del swig_import_helper
30 else:
31  import _bsSerial
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 _bsSerial.BS_SER_DEV_NAME_DFT_swigconstant(_bsSerial)
95 BS_SER_DEV_NAME_DFT = _bsSerial.BS_SER_DEV_NAME_DFT
96 
97 _bsSerial.BS_SER_SERVER_MOD_swigconstant(_bsSerial)
98 BS_SER_SERVER_MOD = _bsSerial.BS_SER_SERVER_MOD
99 
100 _bsSerial.BS_SER_CLIENT_LIB_swigconstant(_bsSerial)
101 BS_SER_CLIENT_LIB = _bsSerial.BS_SER_CLIENT_LIB
102 
103 def bsSerialGetMsgName(pClient, hndVConn, uMsgId):
104  return _bsSerial.bsSerialGetMsgName(pClient, hndVConn, uMsgId)
105 bsSerialGetMsgName = _bsSerial.bsSerialGetMsgName
106 
107 def bsSerialReqOpen(pClient, sDevName, nBaudRate, nByteSize, cParity, nStopBits, bRtsCts, bXonXoff, bInitTrace):
108  return _bsSerial.bsSerialReqOpen(pClient, sDevName, nBaudRate, nByteSize, cParity, nStopBits, bRtsCts, bXonXoff, bInitTrace)
109 bsSerialReqOpen = _bsSerial.bsSerialReqOpen
110 
111 def bsSerialReqClose(pClient, hndVConn):
112  return _bsSerial.bsSerialReqClose(pClient, hndVConn)
113 bsSerialReqClose = _bsSerial.bsSerialReqClose
114 
115 def bsSerialReqRead(pClient, hndVConn, uReadLen, rbuf):
116  return _bsSerial.bsSerialReqRead(pClient, hndVConn, uReadLen, rbuf)
117 bsSerialReqRead = _bsSerial.bsSerialReqRead
118 
119 def bsSerialReqWrite(pClient, hndVConn, wbuf, uWriteLen):
120  return _bsSerial.bsSerialReqWrite(pClient, hndVConn, wbuf, uWriteLen)
121 bsSerialReqWrite = _bsSerial.bsSerialReqWrite
122 
123 def bsSerialReqTrans(pClient, hndVConn, wbuf, uWriteLen, uReadLen, rbuf):
124  return _bsSerial.bsSerialReqTrans(pClient, hndVConn, wbuf, uWriteLen, uReadLen, rbuf)
125 bsSerialReqTrans = _bsSerial.bsSerialReqTrans
126 
127 
128 """
129 BotSense Serial Python Inline Extensions and Wrappers.
130 """
131 
132 ## \file
133 ## \package BotSense.bsSerial
134 ##
135 ## \brief BotSense Swigged Serial Python Interface Module.
136 ##
137 ## \author Robin Knight (robin.knight@roadnarrows.com)
138 ##
139 ## \par Copyright:
140 ## (C) 2010. RoadNarrows LLC.\n
141 ## (http://www.roadnarrows.com)\n
142 ## All Rights Reserved
143 ##
144 
145 import BotSenseCore as bsCore
146 import BotSenseError as bsError
147 import BotSenseTypes as bsTypes
148 
149 def SerialGetMsgName(client, hndVConn, msgId):
150  """ Get the serial message name.
151 
152  For each (virtual connection, message id) 2-tuple, there can be a known
153  name string (provided the id is valid and an application provides the
154  information).
155 
156  Parameters:
157  client - BotSenseTypes.BsClient instance.
158  hndVConn - Virtual connection handle (ignored).
159  msgId - Serial message id.
160 
161  Return:
162  Returns message name string if it can be determined.
163  Otherwise returns 'unknown'.
164  """
165  bsTypes.BsClient.ChkClient(client)
166  return bsSerialGetMsgName(client.pClient, hndVConn, msgId)
167 
168 def SerialReqOpen(client, devName, baudRate=9600, byteSize=8, parity='N',
169  stopBits=1, rtscts=False, xonxoff=False, trace=False):
170  """ Proxy server request to establish a virtual connection to an RS-232
171  serial device.
172 
173  Raises a BotSenseError exception on failure.
174 
175  Parameters:
176  client - BotSenseTypes.BsClient instance.
177  devName - Proxied serial device name (e.g. /dev/ttyS0).
178  baudRate - Baud rate.
179  byteSize - Bytes size in bits 5...8.
180  parity - Parity. One of: 'N', 'E', 'O'
181  stopBits - Number of stop bits 1, 2
182  rtscts - Do [not] use hardware flow control.
183  xonxoff - Do [not] use software flow control.
184  trace - Initial message tracing enable(true)/disable(false) state.
185 
186  Return
187  New virtual connection handle.
188  """
189  bsTypes.BsClient.ChkClient(client)
190  hndVConn = bsSerialReqOpen(client.pClient, devName, baudRate, byteSize,
191  ord(parity), stopBits, rtscts, xonxoff, trace)
192  bsError.ChkReturnIsNonNeg(hndVConn,
193  "Client %s: Serial Open request failed." % (client.AttrGetName()))
194  return hndVConn
195 
196 def SerialReqClose(client, hndVConn):
197  """ Proxy server request to close client's proxied serial device virtual
198  connection.
199 
200  Raises a BotSenseError exception on failure.
201 
202  Parameters:
203  client - BotSenseTypes.BsClient instance.
204  hndVConn - Virtual connection handle.
205  """
206  bsTypes.BsClient.ChkClient(client)
207  rc = bsSerialReqClose(client.pClient, hndVConn)
208  bsError.ChkReturnIsOk(rc,
209  "Client %s: Serial Close request failed." % (client.AttrGetName()))
210 
211 def SerialReqRead(client, hndVConn, readLen):
212  """ Serial request to read from a proxied RS-232 serial device.
213 
214  Raises a BotSenseError exception on failure.
215 
216  Parameters:
217  client - BotSenseTypes.BsClient instance.
218  hndVConn - Virtual connection handle.
219  readLen - Number of bytes to read.
220 
221  Return:
222  Buffer list of read bytes.
223  """
224  bsTypes.BsClient.ChkClient(client)
225  rbytebuf = bsTypes.ByteBuf(readLen)
226  n = bsSerialReqRead(client.pClient, hndVConn, readLen, rbytebuf.getSwigObj())
227  bsError.ChkReturnIsNonNeg(n,
228  "Client %s: Serial Read request failed." % (client.AttrGetName()))
229  rbytebuf.copyFromSwigObj(n)
230  return rbytebuf.buf
231 
232 def SerialReqWrite(client, hndVConn, wbuf):
233  """ Serial request to write to a proxied RS-232 serial device.
234 
235  Raises a BotSenseError exception on failure.
236 
237  Parameters:
238  client - BotSenseTypes.BsClient instance.
239  hndVConn - Virtual connection handle.
240  wbuf - Write buffer.
241 
242  Return:
243  Number of bytes written.
244  """
245  bsTypes.BsClient.ChkClient(client)
246  wbytebuf = bsTypes.ByteBuf.Clone(wbuf)
247  wbytebuf.copyToSwigObj(len(wbytebuf))
248  n = bsSerialReqWrite(client.pClient, hndVConn, wbytebuf.getSwigObj(),
249  len(wbytebuf))
250  bsError.ChkReturnIsNonNeg(n,
251  "Client %s: Serial Write request failed." % (client.AttrGetName()))
252  return n
253 
254 def SerialReqTrans(client, hndVConn, wbuf, readLen):
255  """ Serial request to execute a write-read transaction to a proxied
256  RS-232 serial device.
257 
258  Raises a BotSenseError exception on failure.
259 
260  Parameters:
261  client - BotSenseTypes.BsClient instance.
262  hndVConn - Virtual connection handle.
263  wbuf - Write buffer.
264  readLen - Number of bytes to read.
265 
266  Return:
267  Buffer list of read bytes.
268  """
269  bsTypes.BsClient.ChkClient(client)
270  wbytebuf = bsTypes.ByteBuf.Clone(wbuf)
271  wbytebuf.copyToSwigObj(len(wbytebuf))
272  rbytebuf = bsTypes.ByteBuf(readLen)
273  n = bsSerialReqTrans(client.pClient, hndVConn,
274  wbytebuf.getSwigObj(), len(wbytebuf),
275  readLen, rbytebuf.getSwigObj())
276  bsError.ChkReturnIsNonNeg(n,
277  "Client %s: Serial Transaction request failed." % (client.AttrGetName()))
278  rbytebuf.copyFromSwigObj(n)
279  return rbytebuf.buf
280 
281 
282 # This file is compatible with both classic and new-style classes.
283 
284 
def SerialReqOpen(client, devName, baudRate=9600, byteSize=8, parity='N', stopBits=1, rtscts=False, xonxoff=False, trace=False)
Definition: bsSerial.py:169
def SerialGetMsgName(client, hndVConn, msgId)
Definition: bsSerial.py:149
def SerialReqRead(client, hndVConn, readLen)
Definition: bsSerial.py:211
def SerialReqWrite(client, hndVConn, wbuf)
Definition: bsSerial.py:232
def SerialReqClose(client, hndVConn)
Definition: bsSerial.py:196
def SerialReqTrans(client, hndVConn, wbuf, readLen)
Definition: bsSerial.py:254