1 /******************************************************************************
14 * \brief BotSense serial library python swig interface definitions file.
16 * \author Robin Knight (robin.knight@roadnarrows.com)
19 * (C) 2010. RoadNarrows LLC.
20 * (http://www.roadnarrows.com)
25 * Permission is hereby granted, without written agreement and without
26 * license or royalty fees, to use, copy, modify, and distribute this
27 * software and its documentation for any purpose, provided that
28 * (1) The above copyright notice and the following two paragraphs
29 * appear in all copies of the source code and (2) redistributions
30 * including binaries reproduces these notices in the supporting
31 * documentation. Substantial modifications to this software may be
32 * copyrighted by their authors and need not follow the licensing terms
33 * described here, provided that the new terms are clearly indicated in
34 * all files where they apply.
36 * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
37 * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
38 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
39 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
40 * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
41 * THE POSSIBILITY OF SUCH DAMAGE.
43 * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
44 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
45 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
46 * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
47 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
49 ******************************************************************************/
53 #include "botsense/BotSense.h"
54 #include "botsense/bsSerial.h"
60 * \brief Swig generated serial wrapper c file.
65 * Required RNR C Types
67 typedef unsigned char byte_t;
68 typedef unsigned short ushort_t;
69 typedef unsigned int uint_t;
70 typedef unsigned long ulong_t;
74 * Required BotSense C Types
76 typedef struct _bsClientStruct *BsClient_P;
77 typedef int BsVConnHnd_T;
79 /* the swigged interface */
80 %include "botsense/bsSerial.h"
83 * Higher-level python interface to the BotSense serial C library.
89 BotSense Serial Python Inline Extensions and Wrappers.
93 ## \package BotSense.bsSerial
95 ## \brief BotSense Swigged Serial Python Interface Module.
97 ## \author Robin Knight (robin.knight@roadnarrows.com)
100 ## (C) 2010. RoadNarrows LLC.\n
101 ## (http://www.roadnarrows.com)\n
102 ## All Rights Reserved
105 import BotSenseCore as bsCore
106 import BotSenseError as bsError
107 import BotSenseTypes as bsTypes
109 def SerialGetMsgName(client, hndVConn, msgId):
110 """ Get the serial message name.
112 For each (virtual connection, message id) 2-tuple, there can be a known
113 name string (provided the id is valid and an application provides the
117 client - BotSenseTypes.BsClient instance.
118 hndVConn - Virtual connection handle (ignored).
119 msgId - Serial message id.
122 Returns message name string if it can be determined.
123 Otherwise returns 'unknown'.
125 bsTypes.BsClient.ChkClient(client)
126 return bsSerialGetMsgName(client.pClient, hndVConn, msgId)
128 def SerialReqOpen(client, devName, baudRate=9600, byteSize=8, parity='N',
129 stopBits=1, rtscts=False, xonxoff=False, trace=False):
130 """ Proxy server request to establish a virtual connection to an RS-232
133 Raises a BotSenseError exception on failure.
136 client - BotSenseTypes.BsClient instance.
137 devName - Proxied serial device name (e.g. /dev/ttyS0).
138 baudRate - Baud rate.
139 byteSize - Bytes size in bits 5...8.
140 parity - Parity. One of: 'N', 'E', 'O'
141 stopBits - Number of stop bits 1, 2
142 rtscts - Do [not] use hardware flow control.
143 xonxoff - Do [not] use software flow control.
144 trace - Initial message tracing enable(true)/disable(false) state.
147 New virtual connection handle.
149 bsTypes.BsClient.ChkClient(client)
150 hndVConn = bsSerialReqOpen(client.pClient, devName, baudRate, byteSize,
151 ord(parity), stopBits, rtscts, xonxoff, trace)
152 bsError.ChkReturnIsNonNeg(hndVConn,
153 "Client %s: Serial Open request failed." % (client.AttrGetName()))
156 def SerialReqClose(client, hndVConn):
157 """ Proxy server request to close client's proxied serial device virtual
160 Raises a BotSenseError exception on failure.
163 client - BotSenseTypes.BsClient instance.
164 hndVConn - Virtual connection handle.
166 bsTypes.BsClient.ChkClient(client)
167 rc = bsSerialReqClose(client.pClient, hndVConn)
168 bsError.ChkReturnIsOk(rc,
169 "Client %s: Serial Close request failed." % (client.AttrGetName()))
171 def SerialReqRead(client, hndVConn, readLen):
172 """ Serial request to read from a proxied RS-232 serial device.
174 Raises a BotSenseError exception on failure.
177 client - BotSenseTypes.BsClient instance.
178 hndVConn - Virtual connection handle.
179 readLen - Number of bytes to read.
182 Buffer list of read bytes.
184 bsTypes.BsClient.ChkClient(client)
185 rbytebuf = bsTypes.ByteBuf(readLen)
186 n = bsSerialReqRead(client.pClient, hndVConn, readLen, rbytebuf.getSwigObj())
187 bsError.ChkReturnIsNonNeg(n,
188 "Client %s: Serial Read request failed." % (client.AttrGetName()))
189 rbytebuf.copyFromSwigObj(n)
192 def SerialReqWrite(client, hndVConn, wbuf):
193 """ Serial request to write to a proxied RS-232 serial device.
195 Raises a BotSenseError exception on failure.
198 client - BotSenseTypes.BsClient instance.
199 hndVConn - Virtual connection handle.
203 Number of bytes written.
205 bsTypes.BsClient.ChkClient(client)
206 wbytebuf = bsTypes.ByteBuf.Clone(wbuf)
207 wbytebuf.copyToSwigObj(len(wbytebuf))
208 n = bsSerialReqWrite(client.pClient, hndVConn, wbytebuf.getSwigObj(),
210 bsError.ChkReturnIsNonNeg(n,
211 "Client %s: Serial Write request failed." % (client.AttrGetName()))
214 def SerialReqTrans(client, hndVConn, wbuf, readLen):
215 """ Serial request to execute a write-read transaction to a proxied
216 RS-232 serial device.
218 Raises a BotSenseError exception on failure.
221 client - BotSenseTypes.BsClient instance.
222 hndVConn - Virtual connection handle.
224 readLen - Number of bytes to read.
227 Buffer list of read bytes.
229 bsTypes.BsClient.ChkClient(client)
230 wbytebuf = bsTypes.ByteBuf.Clone(wbuf)
231 wbytebuf.copyToSwigObj(len(wbytebuf))
232 rbytebuf = bsTypes.ByteBuf(readLen)
233 n = bsSerialReqTrans(client.pClient, hndVConn,
234 wbytebuf.getSwigObj(), len(wbytebuf),
235 readLen, rbytebuf.getSwigObj())
236 bsError.ChkReturnIsNonNeg(n,
237 "Client %s: Serial Transaction request failed." % (client.AttrGetName()))
238 rbytebuf.copyFromSwigObj(n)