@@ -119,130 +119,120 @@ def __check_bus_handle_validity(handle, function, arguments):
119
119
else :
120
120
return handle
121
121
122
+ if __canlib is not None :
123
+ canInitializeLibrary = __get_canlib_function ("canInitializeLibrary" )
122
124
123
- canInitializeLibrary = __get_canlib_function ("canInitializeLibrary" )
125
+ canGetErrorText = __get_canlib_function ("canGetErrorText" ,
126
+ argtypes = [canstat .c_canStatus , ctypes .c_char_p , ctypes .c_uint ],
127
+ restype = canstat .c_canStatus ,
128
+ errcheck = __check_status )
124
129
125
- canGetErrorText = __get_canlib_function ("canGetErrorText" ,
126
- argtypes = [canstat .c_canStatus , ctypes .c_char_p , ctypes .c_uint ],
127
- restype = canstat .c_canStatus ,
128
- errcheck = __check_status )
130
+ # TODO wrap this type of function to provide a more Pythonic API
131
+ canGetNumberOfChannels = __get_canlib_function ("canGetNumberOfChannels" ,
132
+ argtypes = [ctypes .c_void_p ],
133
+ restype = canstat .c_canStatus ,
134
+ errcheck = __check_status )
135
+
136
+ if sys .platform == "win32" :
137
+ __canReadTimer_func_name = "kvReadTimer"
138
+ else :
139
+ __canReadTimer_func_name = "canReadTimer"
140
+ canReadTimer = __get_canlib_function (__canReadTimer_func_name ,
141
+ argtypes = [c_canHandle , ctypes .c_void_p ],
142
+ restype = canstat .c_canStatus ,
143
+ errcheck = __check_status )
144
+
145
+ canBusOff = __get_canlib_function ("canBusOff" ,
146
+ argtypes = [c_canHandle ],
147
+ restype = canstat .c_canStatus ,
148
+ errcheck = __check_status )
129
149
130
- # TODO wrap this type of function to provide a more Pythonic API
131
- canGetNumberOfChannels = __get_canlib_function ("canGetNumberOfChannels" ,
132
- argtypes = [ctypes .c_void_p ],
133
- restype = canstat .c_canStatus ,
134
- errcheck = __check_status )
135
-
136
- if sys .platform == "win32" :
137
- __canReadTimer_func_name = "kvReadTimer"
138
- else :
139
- __canReadTimer_func_name = "canReadTimer"
140
- canReadTimer = __get_canlib_function (__canReadTimer_func_name ,
141
- argtypes = [c_canHandle , ctypes .c_void_p ],
150
+ canBusOn = __get_canlib_function ("canBusOn" ,
151
+ argtypes = [c_canHandle ],
142
152
restype = canstat .c_canStatus ,
143
153
errcheck = __check_status )
144
154
145
- canBusOff = __get_canlib_function ("canBusOff" ,
146
- argtypes = [c_canHandle ],
147
- restype = canstat .c_canStatus ,
148
- errcheck = __check_status )
149
-
150
- canBusOn = __get_canlib_function ("canBusOn" ,
151
- argtypes = [c_canHandle ],
152
- restype = canstat .c_canStatus ,
153
- errcheck = __check_status )
154
-
155
- canClose = __get_canlib_function ("canClose" ,
156
- argtypes = [c_canHandle ],
157
- restype = canstat .c_canStatus ,
158
- errcheck = __check_status )
159
-
160
- canOpenChannel = __get_canlib_function ("canOpenChannel" ,
161
- argtypes = [ctypes .c_int , ctypes .c_int ],
162
- restype = c_canHandle ,
163
- errcheck = __check_bus_handle_validity )
164
-
165
- canSetBusParams = __get_canlib_function ("canSetBusParams" ,
166
- argtypes = [c_canHandle , ctypes .c_long ,
167
- ctypes .c_uint , ctypes .c_uint ,
168
- ctypes .c_uint , ctypes .c_uint ,
169
- ctypes .c_uint ],
170
- restype = canstat .c_canStatus ,
171
- errcheck = __check_status )
172
-
173
-
174
- canSetBusOutputControl = __get_canlib_function ("canSetBusOutputControl" ,
175
- argtypes = [c_canHandle ,
176
- ctypes .c_uint ],
177
- restype = canstat .c_canStatus ,
178
- errcheck = __check_status )
179
-
180
- canSetAcceptanceFilter = __get_canlib_function ("canSetAcceptanceFilter" ,
181
- argtypes = [
182
- c_canHandle ,
183
- ctypes .c_uint ,
184
- ctypes .c_uint ,
185
- ctypes .c_int
186
- ],
187
- restype = canstat .c_canStatus ,
188
- errcheck = __check_status )
189
-
190
- canReadWait = __get_canlib_function ("canReadWait" ,
191
- argtypes = [c_canHandle , ctypes .c_void_p ,
192
- ctypes .c_void_p , ctypes .c_void_p ,
193
- ctypes .c_void_p , ctypes .c_void_p ,
194
- ctypes .c_long ],
195
- restype = canstat .c_canStatus ,
196
- errcheck = __check_status_read )
197
-
198
- canWrite = __get_canlib_function ("canWrite" ,
199
- argtypes = [
200
- c_canHandle ,
201
- ctypes .c_long ,
202
- ctypes .c_void_p ,
203
- ctypes .c_uint ,
204
- ctypes .c_uint ],
205
- restype = canstat .c_canStatus ,
206
- errcheck = __check_status )
207
-
208
- canWriteSync = __get_canlib_function ("canWriteSync" ,
209
- argtypes = [c_canHandle , ctypes .c_ulong ],
155
+ canClose = __get_canlib_function ("canClose" ,
156
+ argtypes = [c_canHandle ],
210
157
restype = canstat .c_canStatus ,
211
158
errcheck = __check_status )
212
159
213
- canIoCtl = __get_canlib_function ("canIoCtl" ,
214
- argtypes = [c_canHandle , ctypes .c_uint ,
215
- ctypes .c_void_p , ctypes .c_uint ],
216
- restype = canstat .c_canStatus ,
217
- errcheck = __check_status )
160
+ canOpenChannel = __get_canlib_function ("canOpenChannel" ,
161
+ argtypes = [ctypes .c_int , ctypes .c_int ],
162
+ restype = c_canHandle ,
163
+ errcheck = __check_bus_handle_validity )
164
+
165
+ canSetBusParams = __get_canlib_function ("canSetBusParams" ,
166
+ argtypes = [c_canHandle , ctypes .c_long ,
167
+ ctypes .c_uint , ctypes .c_uint ,
168
+ ctypes .c_uint , ctypes .c_uint ,
169
+ ctypes .c_uint ],
170
+ restype = canstat .c_canStatus ,
171
+ errcheck = __check_status )
218
172
219
- canGetVersion = __get_canlib_function ("canGetVersion" ,
220
- restype = ctypes .c_short ,
221
- errcheck = __check_status )
222
173
223
- kvFlashLeds = __get_canlib_function ("kvFlashLeds" ,
224
- argtypes = [c_canHandle , ctypes .c_int ,
225
- ctypes .c_int ],
226
- restype = ctypes .c_short ,
227
- errcheck = __check_status )
174
+ canSetBusOutputControl = __get_canlib_function ("canSetBusOutputControl" ,
175
+ argtypes = [c_canHandle ,
176
+ ctypes .c_uint ],
177
+ restype = canstat .c_canStatus ,
178
+ errcheck = __check_status )
179
+
180
+ canSetAcceptanceFilter = __get_canlib_function ("canSetAcceptanceFilter" ,
181
+ argtypes = [
182
+ c_canHandle ,
183
+ ctypes .c_uint ,
184
+ ctypes .c_uint ,
185
+ ctypes .c_int
186
+ ],
187
+ restype = canstat .c_canStatus ,
188
+ errcheck = __check_status )
189
+
190
+ canReadWait = __get_canlib_function ("canReadWait" ,
191
+ argtypes = [c_canHandle , ctypes .c_void_p ,
192
+ ctypes .c_void_p , ctypes .c_void_p ,
193
+ ctypes .c_void_p , ctypes .c_void_p ,
194
+ ctypes .c_long ],
195
+ restype = canstat .c_canStatus ,
196
+ errcheck = __check_status_read )
197
+
198
+ canWrite = __get_canlib_function ("canWrite" ,
199
+ argtypes = [
200
+ c_canHandle ,
201
+ ctypes .c_long ,
202
+ ctypes .c_void_p ,
203
+ ctypes .c_uint ,
204
+ ctypes .c_uint ],
205
+ restype = canstat .c_canStatus ,
206
+ errcheck = __check_status )
228
207
229
- if sys .platform == "win32" :
230
- canGetVersionEx = __get_canlib_function ("canGetVersionEx" ,
231
- argtypes = [ctypes .c_uint ],
232
- restype = ctypes .c_uint ,
233
- errcheck = __check_status )
208
+ canWriteSync = __get_canlib_function ("canWriteSync" ,
209
+ argtypes = [c_canHandle , ctypes .c_ulong ],
210
+ restype = canstat .c_canStatus ,
211
+ errcheck = __check_status )
234
212
213
+ canIoCtl = __get_canlib_function ("canIoCtl" ,
214
+ argtypes = [c_canHandle , ctypes .c_uint ,
215
+ ctypes .c_void_p , ctypes .c_uint ],
216
+ restype = canstat .c_canStatus ,
217
+ errcheck = __check_status )
235
218
236
- def init_kvaser_library ():
237
- try :
238
- log .debug ("Initializing Kvaser CAN library" )
239
- canInitializeLibrary ()
240
- log .debug ("CAN library initialized" )
241
- except :
242
- log .warning ("Kvaser canlib could not be initialized." )
219
+ canGetVersion = __get_canlib_function ("canGetVersion" ,
220
+ restype = ctypes .c_short ,
221
+ errcheck = __check_status )
243
222
223
+ kvFlashLeds = __get_canlib_function ("kvFlashLeds" ,
224
+ argtypes = [c_canHandle , ctypes .c_int ,
225
+ ctypes .c_int ],
226
+ restype = ctypes .c_short ,
227
+ errcheck = __check_status )
228
+
229
+ if sys .platform == "win32" :
230
+ canGetVersionEx = __get_canlib_function ("canGetVersionEx" ,
231
+ argtypes = [ctypes .c_uint ],
232
+ restype = ctypes .c_uint ,
233
+ errcheck = __check_status )
244
234
245
- canGetChannelData = __get_canlib_function ("canGetChannelData" ,
235
+ canGetChannelData = __get_canlib_function ("canGetChannelData" ,
246
236
argtypes = [ctypes .c_int ,
247
237
ctypes .c_int ,
248
238
ctypes .c_void_p ,
@@ -251,6 +241,16 @@ def init_kvaser_library():
251
241
errcheck = __check_status )
252
242
253
243
244
+ def init_kvaser_library ():
245
+ if __canlib is not None :
246
+ try :
247
+ log .debug ("Initializing Kvaser CAN library" )
248
+ canInitializeLibrary ()
249
+ log .debug ("CAN library initialized" )
250
+ except :
251
+ log .warning ("Kvaser canlib could not be initialized." )
252
+
253
+
254
254
DRIVER_MODE_SILENT = False
255
255
DRIVER_MODE_NORMAL = True
256
256
0 commit comments