-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDTOL_prototypes.py
More file actions
398 lines (335 loc) · 17.4 KB
/
DTOL_prototypes.py
File metadata and controls
398 lines (335 loc) · 17.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# -*- coding: utf-8 -*-
"""
Created on Fri May 16 11:05:53 2014
@author: Jens Brauer
"""
import ctypes
from ctypes.util import find_library
dll = ctypes.CDLL(find_library('oldaapi64'))
#print(dll)
dll2 = ctypes.CDLL(find_library('OLMEM64'))
#dll2 = ctypes.CDLL(find_library('OLMEMSUP'))
def errcheck_all(ret, func, args):
if ret:
print("Error occured in"+ str(func))
return
return args
def errcheck_none(ret, func, args):
if ret:
print("Error occured in"+ str(func))
print(ret)
return
# ----------- Initialize ---------------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_char_p, ctypes.POINTER(ctypes.c_ulong))
paramflags = (1, "name"), (2,'hDev')
olDaInitialize = prototype(("olDaInitialize", dll), paramflags)
olDaInitialize.errcheck = errcheck_all
# -----------END Initialize ---------------------------------
# ----------- olDaGetDASS ---------------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, ctypes.c_long, ctypes.c_uint, ctypes.POINTER(ctypes.c_ulong))
paramflags = (1, "hDev"), (1,"SubsystemType"), (1,"uiElementNr"), (2,'adhandle')
olDaGetDASS = prototype(("olDaGetDASS",dll), paramflags)
olDaGetDASS.errcheck = errcheck_all
# ----------- olDaGetDASS ---------------------------------
# ----------- olDaSetDataFlow -----------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, ctypes.c_uint)
paramflags = (1,"adhandle"),(1,"mode") # mode=OL_DF_SINGLEVALUE etc
olDaSetDataFlow = prototype(("olDaSetDataFlow",dll),paramflags)
olDaSetDataFlow.errcheck = errcheck_none
# ----------- olDaSetDataFlow -----------------------------
# ----------- olDaGetDataFlow -----------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, ctypes.POINTER(ctypes.c_uint))
paramflags = (1,'adhandle'),(2,'flowval')
olDaGetDataFlow = prototype(("olDaGetDataFlow",dll), paramflags)
olDaGetDataFlow.errcheck = errcheck_all
# ----------- olDaGetDataFlow -----------------------------
# ----------- olDaConfig -----------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong)
paramflags = (1,'adhandle'),
olDaConfig = prototype(("olDaConfig",dll),paramflags)
olDaConfig.errcheck = errcheck_none
# ----------- olDaConfig -----------------------------
#------------olDaGetRange -------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double))
paramflags = (1,"ADDEV"),(2,"rmax"),(2,"rmin")
olDaGetRange = prototype(("olDaGetRange",dll), paramflags)
olDaGetRange.errcheck = errcheck_all
#------------olDaGetRange -------------------------
#------------olDaGetEncoding --------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, ctypes.POINTER(ctypes.c_uint))
paramflags = (1,"ADDEV"),(2,"res")
olDaGetEncoding = prototype(("olDaGetEncoding",dll), paramflags)
olDaGetEncoding.errcheck = errcheck_all
#------------olDaGetEncoding --------------------------
#------------ olDaGetResolution -----------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, ctypes.POINTER(ctypes.c_uint))
paramflags = (1,"ADDEV"),(2,"res")
olDaGetResolution = prototype(("olDaGetResolution",dll), paramflags)
olDaGetResolution.errcheck = errcheck_all
#------------ olDaGetResolution -----------------------
#------------ olDaGetSingleValue ----------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, ctypes.POINTER(ctypes.c_long), ctypes.c_uint, ctypes.c_double)
paramflags = (1,"ADDEV"),(2,'Value'),(1,'Channel'),(1,'Gain')
olDaGetSingleValue = prototype(("olDaGetSingleValue",dll), paramflags)
olDaGetSingleValue.errcheck = errcheck_all
#------------ olDaGetSingleValue ----------------------
#------------ olDaPutSingleValue ----------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, ctypes.c_long, ctypes.c_uint, ctypes.c_double)
paramflags = (1,"ADDEV"),(1,'Value'),(1,'Channel'),(1,'Gain')
olDaPutSingleValue = prototype(("olDaPutSingleValue",dll), paramflags)
olDaPutSingleValue.errcheck = errcheck_all
#------------ olDaGetSingleValue ----------------------
#------------olDaGetSingleFloat -------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, ctypes.POINTER(ctypes.c_float), ctypes.c_uint, ctypes.c_double)
paaramflagst = (1,"ADDEV"),(2,'Value'),(1,'Channel'),(1,'Gain')
olDaGetSingleFloat = prototype(("olDaGetSingleFloat",dll), paramflags)
olDaGetSingleFloat.errcheck = errcheck_all
# -> error 26: Request not supported by this subsystem...
#------------olDaGetSingleFloat -------------------------
#------------olDaCodeToVolts --------------------------
#ECODE olDaCodeToVolts(DBL dfMinRangeVolts, DBL dfMaxRangeVolts, DBL dfGain, UINT uiBitsResolution, UINT uiEncoding, LNG lCode, PDBL pdfVoltage)
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_uint, ctypes.c_uint, ctypes.c_long, ctypes.POINTER(ctypes.c_double))
paramflags = (1,"minrange"),(1,"maxrange"),(1,"Gain"),(1,"Resolution"),(1,"Encoding"),(1,"Code"),(2,"Voltage")
olDaCodeToVolts = prototype(("olDaCodeToVolts",dll),paramflags)
olDaCodeToVolts.errcheck = errcheck_all
#------------olDaCodeToVolts --------------------------
#------------olDaVoltsToCode --------------------------
#ECODE olDaVoltsToCode(DBL dfMinRangeVolts, DBL dfMaxRangeVolts, DBL dfGain, UINT uiBitsResolution, UINT uiEncoding, DBL dfVoltage, PLNG plCode)
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_uint, ctypes.c_uint, ctypes.c_double, ctypes.POINTER(ctypes.c_long))
paramflags = (1,"minrange"),(1,"maxrange"),(1,"Gain"),(1,"Resolution"),(1,"Encoding"),(1,"Voltage"),(2,"Code")
olDaVoltsToCode = prototype(("olDaVoltsToCode",dll),paramflags)
olDaVoltsToCode.errcheck = errcheck_all
#------------olDaCodeToVolts --------------------------
HBUF = ctypes.c_void_p #HANDLE
PHBUF = ctypes.POINTER(ctypes.c_void_p)
PUINT = ctypes.POINTER(ctypes.c_int)
DWORD = ctypes.c_ulong
LPHBUF = ctypes.POINTER(HBUF)
#----------- olDaPutBuffer ----------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int,ctypes.c_ulong,HBUF)
paramflags =(1, "hDass"),(1, "hBuf")
olDaPutBuffer = prototype(("olDaPutBuffer", dll), paramflags)
olDaPutBuffer.errcheck = errcheck_none
#----------- olDaPutBuffer ----------------------------
#----------- olDaGetBuffer ----------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int,ctypes.c_ulong, PHBUF)
paramflags =(1, "hDass"),(2, "phBuf")
olDaGetBuffer = prototype(("olDaGetBuffer", dll), paramflags)
olDaGetBuffer.errcheck = errcheck_all
#----------- olDaGetBuffer ----------------------------
#----------- olDmCallocBuffer --------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_uint, ctypes.c_uint, DWORD, ctypes.c_uint, LPHBUF)
paramflags =(1, "uiWinFlags"),(1,"uiExFlags",0),(1, "numSamples"),(1,"uiSampleSize"),(2,"bufferhandle")
olDmCallocBuffer = prototype(("olDmCallocBuffer", dll2), paramflags)
olDmCallocBuffer.errcheck = errcheck_all
#----------- olDmCallocBuffer --------------------------
#----------- olDmgetValidSamples --------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, HBUF, ctypes.POINTER(DWORD))
paramflags =(1, "bufferhandle"),(2,"lpmax")
olDmGetValidSamples = prototype(("olDmGetValidSamples", dll2), paramflags)
olDmGetValidSamples.errcheck = errcheck_all
#----------- olDmgetValidSamples --------------------------
#----------- olDmGetBufferPtr ----------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, HBUF, ctypes.POINTER(ctypes.c_void_p))
paramflags =(1, "bufferhandle"),(2,"lpBuffer")
olDmGetBufferPtr = prototype(("olDmGetBufferPtr", dll2), paramflags)
olDmGetBufferPtr.errcheck = errcheck_all
#----------- olDmGetBufferPtr ----------------------------
#----------- olDmGetBufferECode ----------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, HBUF, ctypes.POINTER(ctypes.c_int))
paramflags =(1, "bufferhandle"),(2,"lpecode")
olDmGetBufferECode = prototype(("olDmGetBufferECode", dll2), paramflags)
olDmGetBufferECode.errcheck = errcheck_all
#----------- olDmGetBufferECode ----------------------------
#----------- olDmFreeBuffer --------------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, HBUF)
paramflags =(1, "bufferhandle"),
olDmFreeBuffer = prototype(("olDmFreeBuffer", dll2), paramflags)
olDmFreeBuffer.errcheck = errcheck_none
#----------- olDmGetBufferECode ----------------------------
#----------- olDmCopyFromBuffer --------------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, HBUF,ctypes.POINTER(ctypes.c_void_p),ctypes.c_ulong)
paramflags =(1, "bufferhandle"),(2,"lpAppBuffer"),(1,"maxSamples")
olDmCopyFromBuffer = prototype(("olDmCopyFromBuffer", dll2), paramflags)
olDmCopyFromBuffer.errcheck = errcheck_all
#----------- olDmGetBufferECode ----------------------------
#----------- olDaFlushBuffers -----------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong)
paramflags =(1, "hDass"),
olDaFlushBuffers = prototype(("olDaFlushBuffers", dll), paramflags)
olDaFlushBuffers.errcheck = errcheck_none
#----------- olDaFlushBuffers -----------------------------
#ECODE WINAPI olDmCopyFromBuffer(HBUF hBuf, LPVOID lpAppBuffer, ULNG ulMaxSamples);
#ECODE WINAPI olDmCallocBuffer (UINT, UINT, DWORD, UINT, LPHBUF);
#ECODE WINAPI olDmMallocBuffer (UINT, UINT, DWORD, LPHBUF);
#ECODE WINAPI olDmLockBuffer (HBUF);
#ECODE WINAPI olDmUnlockBuffer (HBUF);
#ECODE WINAPI olDmReCallocBuffer (UINT, UINT, DWORD, UINT, LPHBUF);
#ECODE WINAPI olDmReMallocBuffer (UINT, UINT, DWORD, LPHBUF);
#ECODE WINAPI olDmGetDataBits (HBUF, UINT FAR*);
#ECODE WINAPI olDmSetDataWidth (HBUF, UINT);
#ECODE WINAPI olDmGetDataWidth (HBUF, UINT FAR*);
#ECODE WINAPI olDmGetMaxSamples (HBUF, DWORD FAR*);
#ECODE WINAPI olDmSetValidSamples (HBUF, DWORD);
#ECODE WINAPI olDmGetValidSamples (HBUF, DWORD FAR*);
#ECODE WINAPI olDmGetBufferPtr (HBUF, LPVOID FAR*);
#ECODE WINAPI olDmGetBufferECode (HBUF, LPECODE);
#----------- olDaSetChannelListSize. ------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int,ctypes.c_ulong,ctypes.c_uint)
paramflags =(1, "hDass"),(1, "uiSize")
olDaSetChannelListSize = prototype(("olDaSetChannelListSize", dll), paramflags)
olDaSetChannelListSize.errcheck = errcheck_none
#----------- olDaSetChannelListSize. ------------------
#----------- olDaGetChannelListSize. ------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong,PUINT)
paramflags =(1, "hDass"),(2, "puiSize")
olDaGetChannelListSize = prototype(("olDaGetChannelListSize", dll), paramflags)
olDaGetChannelListSize.errcheck = errcheck_all
#----------- olDaGetChannelListSize. ------------------
#----------- olDaSetChannelListEntry ------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong,ctypes.c_uint,ctypes.c_uint)
paramflags =(1, "hDass"),(1, "uiEntry"),(1, "uiChan")
olDaSetChannelListEntry = prototype(("olDaSetChannelListEntry", dll), paramflags)
olDaSetChannelListEntry.errcheck = errcheck_none
#----------- olDaSetChannelListEntry ------------------
#----------- olDaGetChannelListEntry ------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong,ctypes.c_uint,PUINT)
paramflags =(1, "hDass"),(1, "uiEntry"),(2, "puiChan")
olDaGetChannelListEntry = prototype(("olDaGetChannelListEntry", dll), paramflags)
olDaGetChannelListEntry.errcheck = errcheck_all
#----------- olDaGetChannelListEntry ------------------
#----------- olDaSetGainListEntry ---------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong,ctypes.c_uint,ctypes.c_double)
paramflags =(1, "hDass"),(1, "uiEntry"),(1, "dGain")
olDaSetGainListEntry = prototype(("olDaSetGainListEntry", dll), paramflags)
olDaSetGainListEntry.errcheck = errcheck_none
#----------- olDaSetGainListEntry ---------------------
#----------- olDaGetGainListEntry ---------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong,ctypes.c_uint,ctypes.POINTER(ctypes.c_double))
paramflags =(1, "hDass"),(1, "uiEntry"),(2, "pdGain")
olDaGetGainListEntry = prototype(("olDaGetGainListEntry", dll), paramflags)
olDaGetGainListEntry.errcheck = errcheck_all
#----------- olDaGetGainListEntry ---------------------
#----------- olDaSetClockFrequency --------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong,ctypes.c_double)
paramflags =(1, "hDass"),(1, "dfFreq")
olDaSetClockFrequency = prototype(("olDaSetClockFrequency", dll), paramflags)
olDaSetClockFrequency.errcheck = errcheck_none
#----------- olDaSetClockFrequency --------------------
#----------- olDaGetClockFrequency --------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong,ctypes.POINTER(ctypes.c_double))
paramflags =(1, "hDass"),(2, "pdfFreq")
olDaGetClockFrequency = prototype(("olDaGetClockFrequency", dll), paramflags)
olDaGetClockFrequency.errcheck = errcheck_none
#----------- olDaGetClockFrequency --------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong,ctypes.c_uint)
paramflags =(1, "hDass"),(1, "uiWrapMode")
olDaSetWrapMode = prototype(("olDaSetWrapMode", dll), paramflags)
olDaSetWrapMode.errcheck = errcheck_none
#----------- olDaStart -------------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong)
paramflags =(1, "hDass"),
olDaStart = prototype(("olDaStart", dll), paramflags)
olDaStart.errcheck = errcheck_none
#----------- olDaStart -------------------------------
#----------- olDaStop. -------------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong)
paramflags =(1, "hDass"),
olDaStop = prototype(("olDaStop", dll), paramflags)
olDaStop.errcheck = errcheck_none
#----------- olDaStop. -------------------------------
#----------- olDaReleaseDASS -------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong)
paramflags =(1, "hDass"),
olDaReleaseDASS = prototype(("olDaReleaseDASS", dll), paramflags)
olDaReleaseDASS.errcheck = errcheck_none
#----------- olDaReleaseDASS -------------------------
#----------- olDaTerminate -------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong)
paramflags =(1, "hDev"),
olDaTerminate = prototype(("olDaTerminate", dll), paramflags)
olDaTerminate.errcheck = errcheck_none
#----------- olDaTerminate -------------------------
#----------- olDaGetSSCaps -------------------------
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong,ctypes.c_int,ctypes.POINTER(ctypes.c_uint))
paramflags =(1, "hDass"),(1, "OlSSc"),(2, "puiCap")
olDaGetSSCaps = prototype(("olDaGetSSCaps", dll), paramflags)
olDaGetSSCaps.errcheck = errcheck_all
#----------- olDaGetSSCaps -------------------------
#Fehlt:
#olDmCallocBuffer
#olDmGetValidSamples
#olDmGetBufferPtr
# Notify Callback for olDaSetNotificationProcedure
prototypeNotify = ctypes.WINFUNCTYPE(None, ctypes.c_uint, ctypes.c_ulong, ctypes.c_long)
def NotifyProc(uiMsg, wParam, lParam):
print(uiMsg)
print(wParam)
print(lParam)
notifycallback = prototypeNotify(NotifyProc)
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_ulong, prototypeNotify, ctypes.c_long)
paramflags =(1, "hDass"),(1,'pointer2fcn'),(1,'lparam')
olDaSetNotificationProcedure = prototype(('olDaSetNotificationProcedure',dll), paramflags)
olDaSetNotificationProcedure.errcheck = errcheck_none
# List Boards Callbacl
prototypeListBoards = ctypes.WINFUNCTYPE(None, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_long)
def ListBoardsProc(boardname, drivername, lParam):
print('Name = %s' % boardname)
print('Drivername = %s' % drivername)
print(lParam)
listboardscallback = prototypeListBoards(ListBoardsProc)
prototype = ctypes.WINFUNCTYPE(ctypes.c_int, prototypeListBoards, ctypes.c_long)
paramflags =(1,'pointer2fcn'),(1,'lparam')
olDaEnumBoards = prototype(('olDaEnumBoards',dll), paramflags)
olDaEnumBoards.errcheck = errcheck_none
#import matplotlib
#matplotlib.use('TkAgg')
#import matplotlib.pyplot as plt
#import numpy as np
#from time import sleep
#plt.ion() # set plot to animated
#plt.show()
##ydata = [0] * 1000
##ax1=plt.axes()
## make plot
##line, = plt.plot(ydata)
##plt.pause(0.0001)
##sleep(5)
# Notify Callback for olDaSetNotificationProcedure - new as a test for cintinious readout
prototypeNotifytest = ctypes.WINFUNCTYPE(None, ctypes.c_uint, ctypes.c_ulong, ctypes.c_long)
def NotifyProctest(uiMsg, wParam, lParam):
print(uiMsg)
if uiMsg == 1127:
print('Buffer done ...get Data...')
data = getData(lParam)
#print(data )
print(len(data[0]))
plt.cla()
plt.plot(data)
#line.set_xdata(np.arange(len(data[0])))
#line.set_ydata(data[0]) # update the data
plt.draw() # update the plot
plt.pause(0.0001)
sleep(0.05)
#print(wParam)
#print(lParam)
notifycallbacktest = prototypeNotifytest(NotifyProctest)
def getData(sshandle):
hbuffer = olDaGetBuffer(sshandle) #io create in DTOL_test_cont.py
print(hbuffer)
if( hbuffer ):
data = []
#/* get max samples in input buffer */
samples = olDmGetValidSamples( hbuffer )
print('Numer of samples %d' % samples)
#/* get pointer to the buffer */
buftmp = olDmGetBufferPtr( hbuffer) #type int with adress
print("Pointer buftemp:")
print(buftmp)
P = ctypes.POINTER(ctypes.c_ushort)
p=ctypes.cast(buftmp,P)
# Get all samples from buffer
data.append(p[0:samples-1])
#/* put buffer back to ready list */
olDaPutBuffer(sshandle, hbuffer)
return data