|
@@
-1,431
+1,458
|
|
1
|
#!/usr/bin/env python
|
|
1
|
#!/usr/bin/env python
|
|
2
|
#-*- coding: utf-8 -*-
|
|
2
|
#-*- coding: utf-8 -*-
|
|
3
|
"""Simple python library to drive the analog discovery module from www.digilentinc.com
|
|
3
|
"""Simple python library to drive the analog discovery module from www.digilentinc.com
|
|
4
|
"""
|
|
4
|
"""
|
|
5
|
|
|
5
|
|
|
6
|
from ctypes import *
|
|
6
|
from ctypes import *
|
|
7
|
import time
|
|
7
|
import time
|
|
8
|
import sys
|
|
8
|
import sys
|
|
9
|
import os
|
|
9
|
import os
|
|
10
|
import matplotlib.pyplot as plt
|
|
10
|
import matplotlib.pyplot as plt
|
|
11
|
import numpy as np
|
|
11
|
import numpy as np
|
|
12
|
|
|
12
|
|
|
13
|
__author__ = "Alexis Jeandet"
|
|
13
|
__author__ = "Alexis Jeandet"
|
|
14
|
__copyright__ = "Copyright 2015, Laboratory of Plasma Physics"
|
|
14
|
__copyright__ = "Copyright 2015, Laboratory of Plasma Physics"
|
|
15
|
__credits__ = []
|
|
15
|
__credits__ = []
|
|
16
|
__license__ = "GPLv2"
|
|
16
|
__license__ = "GPLv2"
|
|
17
|
__version__ = "1.0.0"
|
|
17
|
__version__ = "1.0.0"
|
|
18
|
__maintainer__ = "Alexis Jeandet"
|
|
18
|
__maintainer__ = "Alexis Jeandet"
|
|
19
|
__email__ = "alexis.jeandet@member.fsf.org"
|
|
19
|
__email__ = "alexis.jeandet@member.fsf.org"
|
|
20
|
__status__ = "Production"
|
|
20
|
__status__ = "Production"
|
|
21
|
|
|
21
|
|
|
22
|
|
|
22
|
|
|
23
|
nodev = c_int(0)
|
|
23
|
nodev = c_int(0)
|
|
24
|
|
|
24
|
|
|
25
|
DwfStateReady = c_byte(0)
|
|
25
|
DwfStateReady = c_byte(0)
|
|
26
|
DwfStateConfig = c_byte(4)
|
|
26
|
DwfStateConfig = c_byte(4)
|
|
27
|
DwfStatePrefill = c_byte(5)
|
|
27
|
DwfStatePrefill = c_byte(5)
|
|
28
|
DwfStateArmed = c_byte(1)
|
|
28
|
DwfStateArmed = c_byte(1)
|
|
29
|
DwfStateWait = c_byte(7)
|
|
29
|
DwfStateWait = c_byte(7)
|
|
30
|
DwfStateTriggered = c_byte(3)
|
|
30
|
DwfStateTriggered = c_byte(3)
|
|
31
|
DwfStateRunning = c_byte(3)
|
|
31
|
DwfStateRunning = c_byte(3)
|
|
32
|
DwfStateDone = c_byte(2)
|
|
32
|
DwfStateDone = c_byte(2)
|
|
33
|
|
|
33
|
|
|
34
|
DwfStateDict={
|
|
34
|
DwfStateDict={
|
|
35
|
DwfStateReady.value:"Ready",
|
|
35
|
DwfStateReady.value:"Ready",
|
|
36
|
DwfStateConfig.value:"Config",
|
|
36
|
DwfStateConfig.value:"Config",
|
|
37
|
DwfStatePrefill.value:"Prefill",
|
|
37
|
DwfStatePrefill.value:"Prefill",
|
|
38
|
DwfStateArmed.value:"Armed",
|
|
38
|
DwfStateArmed.value:"Armed",
|
|
39
|
DwfStateWait.value:"Wait",
|
|
39
|
DwfStateWait.value:"Wait",
|
|
40
|
DwfStateTriggered.value:"Triggered",
|
|
40
|
DwfStateTriggered.value:"Triggered",
|
|
41
|
DwfStateRunning.value:"Running",
|
|
41
|
DwfStateRunning.value:"Running",
|
|
42
|
DwfStateDone.value:"Done"
|
|
42
|
DwfStateDone.value:"Done"
|
|
43
|
}
|
|
43
|
}
|
|
44
|
|
|
44
|
|
|
45
|
DECIAnalogInChannelCount = c_int(1)
|
|
45
|
DECIAnalogInChannelCount = c_int(1)
|
|
46
|
DECIAnalogOutChannelCount = c_int(2)
|
|
46
|
DECIAnalogOutChannelCount = c_int(2)
|
|
47
|
DECIAnalogIOChannelCount = c_int(3)
|
|
47
|
DECIAnalogIOChannelCount = c_int(3)
|
|
48
|
DECIDigitalInChannelCount = c_int(4)
|
|
48
|
DECIDigitalInChannelCount = c_int(4)
|
|
49
|
DECIDigitalOutChannelCount = c_int(5)
|
|
49
|
DECIDigitalOutChannelCount = c_int(5)
|
|
50
|
DECIDigitalIOChannelCount = c_int(6)
|
|
50
|
DECIDigitalIOChannelCount = c_int(6)
|
|
51
|
DECIAnalogInBufferSize = c_int(7)
|
|
51
|
DECIAnalogInBufferSize = c_int(7)
|
|
52
|
DECIAnalogOutBufferSize = c_int(8)
|
|
52
|
DECIAnalogOutBufferSize = c_int(8)
|
|
53
|
DECIDigitalInBufferSize = c_int(9)
|
|
53
|
DECIDigitalInBufferSize = c_int(9)
|
|
54
|
DECIDigitalOutBufferSize = c_int(10)
|
|
54
|
DECIDigitalOutBufferSize = c_int(10)
|
|
55
|
|
|
55
|
|
|
56
|
trigsrcNone = c_byte(0)
|
|
56
|
trigsrcNone = c_byte(0)
|
|
57
|
trigsrcPC = c_byte(1)
|
|
57
|
trigsrcPC = c_byte(1)
|
|
58
|
trigsrcDetectorAnalogIn = c_byte(2)
|
|
58
|
trigsrcDetectorAnalogIn = c_byte(2)
|
|
59
|
trigsrcDetectorDigitalIn = c_byte(3)
|
|
59
|
trigsrcDetectorDigitalIn = c_byte(3)
|
|
60
|
trigsrcAnalogIn = c_byte(4)
|
|
60
|
trigsrcAnalogIn = c_byte(4)
|
|
61
|
trigsrcDigitalIn = c_byte(5)
|
|
61
|
trigsrcDigitalIn = c_byte(5)
|
|
62
|
trigsrcDigitalOut = c_byte(6)
|
|
62
|
trigsrcDigitalOut = c_byte(6)
|
|
63
|
trigsrcAnalogOut1 = c_byte(7)
|
|
63
|
trigsrcAnalogOut1 = c_byte(7)
|
|
64
|
trigsrcAnalogOut2 = c_byte(8)
|
|
64
|
trigsrcAnalogOut2 = c_byte(8)
|
|
65
|
trigsrcAnalogOut3 = c_byte(9)
|
|
65
|
trigsrcAnalogOut3 = c_byte(9)
|
|
66
|
trigsrcAnalogOut4 = c_byte(10)
|
|
66
|
trigsrcAnalogOut4 = c_byte(10)
|
|
67
|
trigsrcExternal1 = c_byte(11)
|
|
67
|
trigsrcExternal1 = c_byte(11)
|
|
68
|
trigsrcExternal2 = c_byte(12)
|
|
68
|
trigsrcExternal2 = c_byte(12)
|
|
69
|
trigsrcExternal3 = c_byte(13)
|
|
69
|
trigsrcExternal3 = c_byte(13)
|
|
70
|
trigsrcExternal4 = c_byte(14)
|
|
70
|
trigsrcExternal4 = c_byte(14)
|
|
71
|
trigAuto = c_byte(254)
|
|
71
|
trigAuto = c_byte(254)
|
|
72
|
trigNormal = c_byte(255)
|
|
72
|
trigNormal = c_byte(255)
|
|
73
|
|
|
73
|
|
|
74
|
AnalogOutNodeCarrier = c_int(0)
|
|
74
|
AnalogOutNodeCarrier = c_int(0)
|
|
75
|
AnalogOutNodeFM = c_int(1)
|
|
75
|
AnalogOutNodeFM = c_int(1)
|
|
76
|
AnalogOutNodeAM = c_int(2)
|
|
76
|
AnalogOutNodeAM = c_int(2)
|
|
77
|
|
|
77
|
|
|
|
|
|
78
|
filterDecimate = c_int(0)
|
|
|
|
|
79
|
filterAverage = c_int(1)
|
|
|
|
|
80
|
filterMinMax = c_int(2)
|
|
|
|
|
81
|
|
|
78
|
|
|
82
|
|
|
79
|
shapes = {'DC' : 0,
|
|
83
|
shapes = {'DC' : 0,
|
|
80
|
'Sine' : 1,
|
|
84
|
'Sine' : 1,
|
|
81
|
'Square' : 2,
|
|
85
|
'Square' : 2,
|
|
82
|
'Triangle' : 3,
|
|
86
|
'Triangle' : 3,
|
|
83
|
'RampUp' : 4,
|
|
87
|
'RampUp' : 4,
|
|
84
|
'RampDown' : 5,
|
|
88
|
'RampDown' : 5,
|
|
85
|
'Noise' : 6,
|
|
89
|
'Noise' : 6,
|
|
86
|
'Custom' : 30,
|
|
90
|
'Custom' : 30,
|
|
87
|
'Play' :31, }
|
|
91
|
'Play' :31, }
|
|
88
|
|
|
92
|
|
|
89
|
closed=False
|
|
93
|
closed=False
|
|
90
|
opened=True
|
|
94
|
opened=True
|
|
91
|
|
|
95
|
|
|
92
|
|
|
96
|
|
|
93
|
class DiscoveryLimits(object):
|
|
97
|
class DiscoveryLimits(object):
|
|
94
|
class limitRange(object):
|
|
98
|
class limitRange(object):
|
|
95
|
def __init__(self,Min,Max,name="Unknow",unit=""):
|
|
99
|
def __init__(self,Min,Max,name="Unknow",unit=""):
|
|
96
|
self.Min = Min
|
|
100
|
self.Min = Min
|
|
97
|
self.Max = Max
|
|
101
|
self.Max = Max
|
|
98
|
self.name = name
|
|
102
|
self.name = name
|
|
99
|
self.unit = unit
|
|
103
|
self.unit = unit
|
|
100
|
|
|
104
|
|
|
101
|
def conform(self,value):
|
|
105
|
def conform(self,value):
|
|
102
|
if value<self.Min:
|
|
106
|
if value<self.Min:
|
|
103
|
raise UserWarning("Parameter "+self.name+" out of bound\nValue="+str(value)+"\nForce to "+str(self.Min))
|
|
107
|
raise UserWarning("Parameter "+self.name+" out of bound\nValue="+str(value)+"\nForce to "+str(self.Min))
|
|
104
|
return self.Min
|
|
108
|
return self.Min
|
|
105
|
if value>self.Max:
|
|
109
|
if value>self.Max:
|
|
106
|
raise UserWarning("Parameter "+self.name+" out of bound\nValue="+str(value)+"\nForce to "+str(self.Max))
|
|
110
|
raise UserWarning("Parameter "+self.name+" out of bound\nValue="+str(value)+"\nForce to "+str(self.Max))
|
|
107
|
return self.Max
|
|
111
|
return self.Max
|
|
108
|
return value
|
|
112
|
return value
|
|
109
|
|
|
113
|
|
|
110
|
def __str__(self):
|
|
114
|
def __str__(self):
|
|
111
|
return self.name + ":\n Min="+str(self.Min)+" "+self.unit+",Max="+str(self.Max)+" "+self.unit
|
|
115
|
return self.name + ":\n Min="+str(self.Min)+" "+self.unit+",Max="+str(self.Max)+" "+self.unit
|
|
112
|
|
|
116
|
|
|
113
|
errors = {0: RuntimeError("No card opened"),
|
|
117
|
errors = {0: RuntimeError("No card opened"),
|
|
114
|
1: UserWarning("Parameter out of bound"),
|
|
118
|
1: UserWarning("Parameter out of bound"),
|
|
115
|
}
|
|
119
|
}
|
|
116
|
def __init__(self,libdwf,hdwf):
|
|
120
|
def __init__(self,libdwf,hdwf):
|
|
117
|
self.limits=[]
|
|
121
|
self.limits=[]
|
|
118
|
self.ACQ_IN_RANGES=[0.0]
|
|
122
|
self.ACQ_IN_RANGES=[0.0]
|
|
119
|
if hdwf.value == nodev.value:
|
|
123
|
if hdwf.value == nodev.value:
|
|
120
|
return
|
|
124
|
return
|
|
121
|
self.__hdwf=hdwf
|
|
125
|
self.__hdwf=hdwf
|
|
122
|
self.__libdwf=libdwf
|
|
126
|
self.__libdwf=libdwf
|
|
123
|
Mind=c_double()
|
|
127
|
Mind=c_double()
|
|
124
|
Maxd=c_double()
|
|
128
|
Maxd=c_double()
|
|
125
|
Mini=c_int()
|
|
129
|
Mini=c_int()
|
|
126
|
Maxi=c_int()
|
|
130
|
Maxi=c_int()
|
|
127
|
StepsCount=c_int()
|
|
131
|
StepsCount=c_int()
|
|
128
|
Steps=(c_double*32)()
|
|
132
|
Steps=(c_double*32)()
|
|
129
|
self.__libdwf.FDwfAnalogInBufferSizeInfo(self.__hdwf, byref(Mini), byref(Maxi))
|
|
133
|
self.__libdwf.FDwfAnalogInBufferSizeInfo(self.__hdwf, byref(Mini), byref(Maxi))
|
|
130
|
self.ACQ_BUF=self.limitRange(Mini.value,Maxi.value,"ACQ Buffer Size","Sps")
|
|
134
|
self.ACQ_BUF=self.limitRange(Mini.value,Maxi.value,"ACQ Buffer Size","Sps")
|
|
131
|
self.limits.append(self.ACQ_BUF)
|
|
135
|
self.limits.append(self.ACQ_BUF)
|
|
132
|
self.__libdwf.FDwfAnalogInFrequencyInfo(self.__hdwf, byref(Mind), byref(Maxd))
|
|
136
|
self.__libdwf.FDwfAnalogInFrequencyInfo(self.__hdwf, byref(Mind), byref(Maxd))
|
|
133
|
self.ACQ_FREQ=self.limitRange(Mind.value,Maxd.value,"ACQ Frequency","Hz")
|
|
137
|
self.ACQ_FREQ=self.limitRange(Mind.value,Maxd.value,"ACQ Frequency","Hz")
|
|
134
|
self.limits.append(self.ACQ_FREQ)
|
|
138
|
self.limits.append(self.ACQ_FREQ)
|
|
135
|
self.__libdwf.FDwfAnalogInChannelRangeSteps(self.__hdwf, byref(Steps), byref(StepsCount))
|
|
139
|
self.__libdwf.FDwfAnalogInChannelRangeSteps(self.__hdwf, byref(Steps), byref(StepsCount))
|
|
136
|
self.ACQ_IN_RANGES=Steps[0:StepsCount.value]
|
|
140
|
self.ACQ_IN_RANGES=Steps[0:StepsCount.value]
|
|
137
|
self.__libdwf.FDwfAnalogOutNodeAmplitudeInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
|
|
141
|
self.__libdwf.FDwfAnalogOutNodeAmplitudeInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
|
|
138
|
byref(Mind), byref(Maxd))
|
|
142
|
byref(Mind), byref(Maxd))
|
|
139
|
self.GEN_AMPL=self.limitRange(Mind.value,Maxd.value,"GEN Amplitude","V")
|
|
143
|
self.GEN_AMPL=self.limitRange(Mind.value,Maxd.value,"GEN Amplitude","V")
|
|
140
|
self.limits.append(self.GEN_AMPL)
|
|
144
|
self.limits.append(self.GEN_AMPL)
|
|
141
|
self.__libdwf.FDwfAnalogOutNodeFrequencyInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
|
|
145
|
self.__libdwf.FDwfAnalogOutNodeFrequencyInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
|
|
142
|
byref(Mind), byref(Maxd))
|
|
146
|
byref(Mind), byref(Maxd))
|
|
143
|
self.GEN_FREQ=self.limitRange(Mind.value,Maxd.value,"GEN Frequency","Hz")
|
|
147
|
self.GEN_FREQ=self.limitRange(Mind.value,Maxd.value,"GEN Frequency","Hz")
|
|
144
|
self.limits.append(self.GEN_FREQ)
|
|
148
|
self.limits.append(self.GEN_FREQ)
|
|
145
|
self.__libdwf.FDwfAnalogOutNodeOffsetInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
|
|
149
|
self.__libdwf.FDwfAnalogOutNodeOffsetInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
|
|
146
|
byref(Mind), byref(Maxd))
|
|
150
|
byref(Mind), byref(Maxd))
|
|
147
|
self.GEN_OFFSET=self.limitRange(Mind.value,Maxd.value,"GEN Offset","V")
|
|
151
|
self.GEN_OFFSET=self.limitRange(Mind.value,Maxd.value,"GEN Offset","V")
|
|
148
|
self.limits.append(self.GEN_OFFSET)
|
|
152
|
self.limits.append(self.GEN_OFFSET)
|
|
149
|
self.__libdwf.FDwfAnalogOutNodeDataInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
|
|
153
|
self.__libdwf.FDwfAnalogOutNodeDataInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
|
|
150
|
byref(Mini), byref(Maxi))
|
|
154
|
byref(Mini), byref(Maxi))
|
|
151
|
self.GEN_BUFF=self.limitRange(Mini.value,Maxi.value,"GEN Buffer size","Sps")
|
|
155
|
self.GEN_BUFF=self.limitRange(Mini.value,Maxi.value,"GEN Buffer size","Sps")
|
|
152
|
self.limits.append(self.GEN_BUFF)
|
|
156
|
self.limits.append(self.GEN_BUFF)
|
|
153
|
|
|
157
|
|
|
154
|
|
|
158
|
|
|
155
|
def __conformParam(self,minVal,maxVal,val):
|
|
159
|
def __conformParam(self,minVal,maxVal,val):
|
|
156
|
if val<minVal:
|
|
160
|
if val<minVal:
|
|
157
|
raise self.errors.get(1)
|
|
161
|
raise self.errors.get(1)
|
|
158
|
print("Force to "+str(minVal))
|
|
162
|
print("Force to "+str(minVal))
|
|
159
|
return minVal
|
|
163
|
return minVal
|
|
160
|
if val>maxVal:
|
|
164
|
if val>maxVal:
|
|
161
|
raise self.errors.get(1)
|
|
165
|
raise self.errors.get(1)
|
|
162
|
print("Force to "+str(maxVal))
|
|
166
|
print("Force to "+str(maxVal))
|
|
163
|
return maxVal
|
|
167
|
return maxVal
|
|
164
|
return val
|
|
168
|
return val
|
|
165
|
|
|
169
|
|
|
166
|
def acqFreq(self, value):
|
|
170
|
def acqFreq(self, value):
|
|
167
|
return self.ACQ_FREQ.conform(value)
|
|
171
|
return self.ACQ_FREQ.conform(value)
|
|
168
|
|
|
172
|
|
|
169
|
def acqBufSize(self, value):
|
|
173
|
def acqBufSize(self, value):
|
|
170
|
return self.ACQ_BUF.conform(value)
|
|
174
|
return self.ACQ_BUF.conform(value)
|
|
171
|
|
|
175
|
|
|
172
|
def genFreq(self, value):
|
|
176
|
def genFreq(self, value):
|
|
173
|
return self.GEN_FREQ.conform(value)
|
|
177
|
return self.GEN_FREQ.conform(value)
|
|
174
|
|
|
178
|
|
|
175
|
def genAmplitude(self, value):
|
|
179
|
def genAmplitude(self, value):
|
|
176
|
return self.GEN_AMPL.conform(value)
|
|
180
|
return self.GEN_AMPL.conform(value)
|
|
177
|
|
|
181
|
|
|
178
|
def genOffset(self, value):
|
|
182
|
def genOffset(self, value):
|
|
179
|
return self.GEN_OFFSET.conform(value)
|
|
183
|
return self.GEN_OFFSET.conform(value)
|
|
180
|
|
|
184
|
|
|
181
|
def genBuffSize(self, value):
|
|
185
|
def genBuffSize(self, value):
|
|
182
|
return self.GEN_BUFF.conform(value)
|
|
186
|
return self.GEN_BUFF.conform(value)
|
|
183
|
|
|
187
|
|
|
184
|
def __str__(self):
|
|
188
|
def __str__(self):
|
|
185
|
res=str()
|
|
189
|
res=str()
|
|
186
|
for i in self.limits:
|
|
190
|
for i in self.limits:
|
|
187
|
res+=i.__str__()+"\n"
|
|
191
|
res+=i.__str__()+"\n"
|
|
188
|
res+="ACQ Input ranes: "+str(self.ACQ_IN_RANGES)
|
|
192
|
res+="ACQ Input ranes: "+str(self.ACQ_IN_RANGES)
|
|
189
|
return res
|
|
193
|
return res
|
|
190
|
|
|
194
|
|
|
191
|
|
|
195
|
|
|
192
|
class Discovery(object):
|
|
196
|
class Discovery(object):
|
|
193
|
|
|
197
|
|
|
194
|
errors = {0: RuntimeError("No card opened"),
|
|
198
|
errors = {0: RuntimeError("No card opened"),
|
|
195
|
1: UserWarning("Parameter out of bound"),
|
|
199
|
1: UserWarning("Parameter out of bound"),
|
|
196
|
}
|
|
200
|
}
|
|
197
|
def findDevice(self,device):
|
|
201
|
def findDevice(self,device):
|
|
198
|
if not self.__opened:
|
|
202
|
if not self.__opened:
|
|
199
|
raise self.errors.get(0)
|
|
203
|
raise self.errors.get(0)
|
|
200
|
nbDevices = c_int()
|
|
204
|
nbDevices = c_int()
|
|
201
|
self.__libdwf.FDwfEnum(c_int(0), byref(nbDevices))
|
|
205
|
self.__libdwf.FDwfEnum(c_int(0), byref(nbDevices))
|
|
202
|
SN = create_string_buffer(32)
|
|
206
|
SN = create_string_buffer(32)
|
|
203
|
for i in range(nbDevices.value):
|
|
207
|
for i in range(nbDevices.value):
|
|
204
|
self.__libdwf.FDwfEnumSN(c_int(i), SN)
|
|
208
|
self.__libdwf.FDwfEnumSN(c_int(i), SN)
|
|
205
|
if SN.value.decode("UTF-8") == device:
|
|
209
|
if SN.value.decode("UTF-8") == device:
|
|
206
|
return i
|
|
210
|
return i
|
|
207
|
return -1
|
|
211
|
return -1
|
|
208
|
|
|
212
|
|
|
209
|
|
|
213
|
|
|
210
|
def __init__(self,card=-1):
|
|
214
|
def __init__(self,card=-1):
|
|
211
|
if sys.platform.startswith("win"):
|
|
215
|
if sys.platform.startswith("win"):
|
|
212
|
self.__libdwf = cdll.dwf
|
|
216
|
self.__libdwf = cdll.dwf
|
|
213
|
elif sys.platform.startswith("darwin"):
|
|
217
|
elif sys.platform.startswith("darwin"):
|
|
214
|
self.__libdwf = cdll.LoadLibrary("libdwf.dylib")
|
|
218
|
self.__libdwf = cdll.LoadLibrary("libdwf.dylib")
|
|
215
|
else:
|
|
219
|
else:
|
|
216
|
self.__libdwf = cdll.LoadLibrary("libdwf.so")
|
|
220
|
self.__libdwf = cdll.LoadLibrary("libdwf.so")
|
|
217
|
self.__opened = True
|
|
221
|
self.__opened = True
|
|
218
|
self.__hdwf = c_int()
|
|
222
|
self.__hdwf = c_int()
|
|
219
|
if card != -1:
|
|
223
|
if card != -1:
|
|
220
|
SN=card
|
|
224
|
SN=card
|
|
221
|
card = self.findDevice(card)
|
|
225
|
card = self.findDevice(card)
|
|
222
|
if card == -1:
|
|
226
|
if card == -1:
|
|
223
|
raise RuntimeError( "Card not found "+ SN)
|
|
227
|
raise RuntimeError( "Card not found "+ SN)
|
|
224
|
self.__libdwf.FDwfDeviceOpen(c_int(card), byref(self.__hdwf))
|
|
228
|
self.__libdwf.FDwfDeviceOpen(c_int(card), byref(self.__hdwf))
|
|
225
|
if self.__hdwf.value == nodev.value:
|
|
229
|
if self.__hdwf.value == nodev.value:
|
|
226
|
szerr = create_string_buffer(512)
|
|
230
|
szerr = create_string_buffer(512)
|
|
227
|
self.__libdwf.FDwfGetLastErrorMsg(szerr)
|
|
231
|
self.__libdwf.FDwfGetLastErrorMsg(szerr)
|
|
228
|
print(szerr.value)
|
|
232
|
print(szerr.value)
|
|
229
|
print("failed to open device")
|
|
233
|
print("failed to open device")
|
|
230
|
self.__opened=False
|
|
234
|
self.__opened=False
|
|
231
|
self.__limits=DiscoveryLimits(self.__libdwf,self.__hdwf)
|
|
235
|
self.__limits=DiscoveryLimits(self.__libdwf,self.__hdwf)
|
|
232
|
print(self.__limits)
|
|
236
|
print(self.__limits)
|
|
233
|
|
|
237
|
|
|
234
|
@property
|
|
238
|
@property
|
|
235
|
def opened(self):
|
|
239
|
def opened(self):
|
|
236
|
return self.__opened
|
|
240
|
return self.__opened
|
|
237
|
|
|
241
|
|
|
238
|
@property
|
|
242
|
@property
|
|
239
|
def max_sampling_freq(self):
|
|
243
|
def max_sampling_freq(self):
|
|
240
|
return self.__limits.ACQ_FREQ.Max
|
|
244
|
return self.__limits.ACQ_FREQ.Max
|
|
241
|
|
|
245
|
|
|
242
|
@property
|
|
246
|
@property
|
|
243
|
def min_sampling_freq(self):
|
|
247
|
def min_sampling_freq(self):
|
|
244
|
return self.__limits.ACQ_FREQ.Min
|
|
248
|
return self.__limits.ACQ_FREQ.Min
|
|
245
|
|
|
249
|
|
|
246
|
@property
|
|
250
|
@property
|
|
247
|
def max_sampling_buffer(self):
|
|
251
|
def max_sampling_buffer(self):
|
|
248
|
return self.__limits.ACQ_BUF.Max
|
|
252
|
return self.__limits.ACQ_BUF.Max
|
|
249
|
|
|
253
|
|
|
250
|
#############################################################
|
|
254
|
#############################################################
|
|
251
|
# Power Supply
|
|
255
|
# Power Supply
|
|
252
|
#############################################################
|
|
256
|
#############################################################
|
|
253
|
def set_power(self,fiveVolt=1,minusFiveVolt=1,master=True):
|
|
257
|
def set_power(self,fiveVolt=1,minusFiveVolt=1,master=True):
|
|
254
|
if not self.__opened:
|
|
258
|
if not self.__opened:
|
|
255
|
raise self.errors.get(0)
|
|
259
|
raise self.errors.get(0)
|
|
256
|
# enable positive supply
|
|
260
|
# enable positive supply
|
|
257
|
self.__libdwf.FDwfAnalogIOChannelNodeSet(self.__hdwf, 0, 0, c_double(fiveVolt))
|
|
261
|
self.__libdwf.FDwfAnalogIOChannelNodeSet(self.__hdwf, 0, 0, c_double(fiveVolt))
|
|
258
|
# enable negative supply
|
|
262
|
# enable negative supply
|
|
259
|
self.__libdwf.FDwfAnalogIOChannelNodeSet(self.__hdwf, 1, 0, c_double(minusFiveVolt))
|
|
263
|
self.__libdwf.FDwfAnalogIOChannelNodeSet(self.__hdwf, 1, 0, c_double(minusFiveVolt))
|
|
260
|
# master enable
|
|
264
|
# master enable
|
|
261
|
return self.__libdwf.FDwfAnalogIOEnableSet(self.__hdwf, master)
|
|
265
|
return self.__libdwf.FDwfAnalogIOEnableSet(self.__hdwf, master)
|
|
262
|
|
|
266
|
|
|
263
|
def get_power(self):
|
|
267
|
def get_power(self):
|
|
264
|
if not self.__opened:
|
|
268
|
if not self.__opened:
|
|
265
|
raise self.errors.get(0)
|
|
269
|
raise self.errors.get(0)
|
|
266
|
supplyVoltage = c_double()
|
|
270
|
supplyVoltage = c_double()
|
|
267
|
supplyCurrent = c_double()
|
|
271
|
supplyCurrent = c_double()
|
|
268
|
IsEnabled = c_bool()
|
|
272
|
IsEnabled = c_bool()
|
|
269
|
self.__libdwf.FDwfAnalogIOStatus(self.__hdwf)
|
|
273
|
self.__libdwf.FDwfAnalogIOStatus(self.__hdwf)
|
|
270
|
self.__libdwf.FDwfAnalogIOChannelNodeStatus(self.__hdwf, c_int(3), c_int(0), byref(supplyVoltage))
|
|
274
|
self.__libdwf.FDwfAnalogIOChannelNodeStatus(self.__hdwf, c_int(3), c_int(0), byref(supplyVoltage))
|
|
271
|
self.__libdwf.FDwfAnalogIOChannelNodeStatus(self.__hdwf, c_int(3), c_int(1), byref(supplyCurrent))
|
|
275
|
self.__libdwf.FDwfAnalogIOChannelNodeStatus(self.__hdwf, c_int(3), c_int(1), byref(supplyCurrent))
|
|
272
|
self.__libdwf.FDwfAnalogIOEnableStatus(self.__hdwf, byref(IsEnabled))
|
|
276
|
self.__libdwf.FDwfAnalogIOEnableStatus(self.__hdwf, byref(IsEnabled))
|
|
273
|
return [IsEnabled.value,supplyVoltage.value,supplyCurrent.value]
|
|
277
|
return [IsEnabled.value,supplyVoltage.value,supplyCurrent.value]
|
|
274
|
|
|
278
|
|
|
275
|
#############################################################
|
|
279
|
#############################################################
|
|
276
|
# AnalogIn
|
|
280
|
# AnalogIn
|
|
277
|
#############################################################
|
|
281
|
#############################################################
|
|
278
|
def analog_in_read(self,ch1=True,ch2=True,frequency=100000000,samplesCount=100,ch1range=5.0,ch2range=5.0,trigger=trigsrcNone):
|
|
282
|
def analog_in_read(self,ch1=True,ch2=True,frequency=100000000,samplesCount=100,ch1range=5.0,ch2range=5.0,trigger=trigsrcNone):
|
|
279
|
if not self.__opened:
|
|
283
|
if not self.__opened:
|
|
280
|
raise self.errors.get(0)
|
|
284
|
raise self.errors.get(0)
|
|
281
|
cnt=self.__limits.acqBufSize(samplesCount)
|
|
285
|
cnt=self.__limits.acqBufSize(samplesCount)
|
|
282
|
self.__libdwf.FDwfAnalogInFrequencySet(self.__hdwf, c_double(self.__limits.acqFreq(frequency)))
|
|
286
|
self.__libdwf.FDwfAnalogInFrequencySet(self.__hdwf, c_double(self.__limits.acqFreq(frequency)))
|
|
283
|
f=c_double()
|
|
287
|
f=c_double()
|
|
284
|
self.__libdwf.FDwfAnalogInFrequencyGet(self.__hdwf, byref(f))
|
|
288
|
self.__libdwf.FDwfAnalogInFrequencyGet(self.__hdwf, byref(f))
|
|
285
|
frequency=f.value
|
|
289
|
frequency=f.value
|
|
286
|
self.__libdwf.FDwfAnalogInBufferSizeSet(self.__hdwf, c_int(cnt))
|
|
290
|
self.__libdwf.FDwfAnalogInBufferSizeSet(self.__hdwf, c_int(cnt))
|
|
287
|
self.__libdwf.FDwfAnalogInChannelEnableSet(self.__hdwf, c_int(0), c_bool(ch1))
|
|
291
|
range,enabled = [ch1range,ch2range],[ch1,ch2]
|
|
288
|
self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(0), c_double(ch1range))
|
|
292
|
|
|
289
|
self.__libdwf.FDwfAnalogInChannelEnableSet(self.__hdwf, c_int(1), c_bool(ch2))
|
|
293
|
for ch in (0,1):
|
|
290
|
self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(1), c_double(ch2range))
|
|
294
|
self.__libdwf.FDwfAnalogInChannelEnableSet(self.__hdwf, c_int(ch), c_bool(enabled[ch]))
|
|
|
|
|
295
|
self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(ch), c_double(range[ch]))
|
|
|
|
|
296
|
self.__libdwf.FDwfAnalogInChannelFilterSet(self.__hdwf,c_int(ch),filterAverage)
|
|
291
|
self.set_analog_in_trigger(trigger)
|
|
297
|
self.set_analog_in_trigger(trigger)
|
|
292
|
self.__libdwf.FDwfAnalogInConfigure(self.__hdwf, c_bool(False), c_bool(True))
|
|
298
|
self.__libdwf.FDwfAnalogInConfigure(self.__hdwf, c_bool(False), c_bool(True))
|
|
293
|
status = c_byte()
|
|
299
|
status = c_byte()
|
|
294
|
while True:
|
|
300
|
while True:
|
|
295
|
self.__libdwf.FDwfAnalogInStatus(self.__hdwf, c_int(1), byref(status))
|
|
301
|
self.__libdwf.FDwfAnalogInStatus(self.__hdwf, c_int(1), byref(status))
|
|
296
|
if status.value == DwfStateDone.value :
|
|
302
|
if status.value == DwfStateDone.value :
|
|
297
|
break
|
|
303
|
break
|
|
298
|
time.sleep(0.1)
|
|
304
|
time.sleep(0.1)
|
|
299
|
if ch1:
|
|
305
|
if ch1:
|
|
300
|
ch1data = (c_double*cnt)()
|
|
306
|
ch1data = (c_double*cnt)()
|
|
301
|
self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 0, ch1data, cnt)
|
|
307
|
self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 0, ch1data, cnt)
|
|
302
|
if ch2:
|
|
308
|
if ch2:
|
|
303
|
ch2data = (c_double*cnt)()
|
|
309
|
ch2data = (c_double*cnt)()
|
|
304
|
self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
|
|
310
|
self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
|
|
305
|
return [np.array([ch1data,ch2data]),frequency]
|
|
311
|
return [np.array([ch1data,ch2data]),frequency]
|
|
306
|
else:
|
|
312
|
else:
|
|
307
|
return [np.array([ch1data]),frequency]
|
|
313
|
return [np.array([ch1data]),frequency]
|
|
308
|
if ch2:
|
|
314
|
if ch2:
|
|
309
|
ch2data = (c_double*cnt)()
|
|
315
|
ch2data = (c_double*cnt)()
|
|
310
|
self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
|
|
316
|
self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
|
|
311
|
return [np.array([ch2data]),frequency]
|
|
317
|
return [np.array([ch2data]),frequency]
|
|
312
|
|
|
318
|
|
|
313
|
|
|
319
|
|
|
314
|
def set_analog_in_trigger(self,trigger=trigAuto,autoTimeout=0.0):
|
|
320
|
def set_analog_in_trigger(self,trigger=trigAuto,autoTimeout=0.0):
|
|
315
|
if not self.__opened:
|
|
321
|
if not self.__opened:
|
|
316
|
raise self.errors.get(0)
|
|
322
|
raise self.errors.get(0)
|
|
317
|
if trigger == trigAuto:
|
|
323
|
if trigger == trigAuto:
|
|
318
|
self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigsrcDetectorAnalogIn)
|
|
324
|
self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigsrcDetectorAnalogIn)
|
|
319
|
self.__libdwf.FDwfAnalogInTriggerAutoTimeoutSet(self.__hdwf,c_double(autoTimeout))
|
|
325
|
self.__libdwf.FDwfAnalogInTriggerAutoTimeoutSet(self.__hdwf,c_double(autoTimeout))
|
|
320
|
return
|
|
326
|
return
|
|
321
|
if trigger == trigNormal:
|
|
327
|
if trigger == trigNormal:
|
|
322
|
self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigsrcDetectorAnalogIn)
|
|
328
|
self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigsrcDetectorAnalogIn)
|
|
323
|
self.__libdwf.FDwfAnalogInTriggerAutoTimeoutSet(self.__hdwf,c_double(0.0))
|
|
329
|
self.__libdwf.FDwfAnalogInTriggerAutoTimeoutSet(self.__hdwf,c_double(0.0))
|
|
324
|
return
|
|
330
|
return
|
|
325
|
self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigger)
|
|
331
|
self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigger)
|
|
326
|
|
|
332
|
|
|
327
|
#############################################################
|
|
333
|
#############################################################
|
|
328
|
# AnalogOut
|
|
334
|
# AnalogOut
|
|
329
|
#############################################################
|
|
335
|
#############################################################
|
|
|
|
|
336
|
def analog_out_enable(self,channel=0):
|
|
|
|
|
337
|
self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
|
|
|
|
|
338
|
|
|
|
|
|
339
|
def analog_out_disable(self,channel=0):
|
|
|
|
|
340
|
self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
|
|
|
|
|
341
|
|
|
330
|
def analog_out_gen(self,frequency=1000, symmetry=50.0, shape='Sine', channel=0, amplitude=1.0, offset=0.0,phase=0.0, syncOnTrigger=False, triggerFrq=1.0, wait=0.0, runDuration=None):
|
|
342
|
def analog_out_gen(self,frequency=1000, symmetry=50.0, shape='Sine', channel=0, amplitude=1.0, offset=0.0,phase=0.0, syncOnTrigger=False, triggerFrq=1.0, wait=0.0, runDuration=None):
|
|
331
|
self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
|
|
343
|
self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
|
|
332
|
self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
|
|
344
|
self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
|
|
333
|
self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get(shape)))
|
|
345
|
self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get(shape)))
|
|
334
|
self.__libdwf.FDwfAnalogOutNodeSymmetrySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(symmetry))
|
|
346
|
self.__libdwf.FDwfAnalogOutNodeSymmetrySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(symmetry))
|
|
335
|
if shape!="DC":
|
|
347
|
if shape!="DC":
|
|
336
|
self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genFreq(frequency)))
|
|
348
|
self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genFreq(frequency)))
|
|
337
|
self.__libdwf.FDwfAnalogOutNodeAmplitudeSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genAmplitude(amplitude)))
|
|
349
|
self.__libdwf.FDwfAnalogOutNodeAmplitudeSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genAmplitude(amplitude)))
|
|
338
|
self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genOffset(offset)))
|
|
350
|
self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genOffset(offset)))
|
|
339
|
self.__libdwf.FDwfAnalogOutNodePhaseSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(phase))
|
|
351
|
self.__libdwf.FDwfAnalogOutNodePhaseSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(phase))
|
|
340
|
if syncOnTrigger:
|
|
352
|
if syncOnTrigger:
|
|
341
|
self.analog_out_set_trigger(channel)
|
|
353
|
self.analog_out_set_trigger(channel)
|
|
342
|
self.__libdwf.FDwfAnalogOutRepeatSet(self.__hdwf, c_int(channel),c_int(0))
|
|
354
|
self.__libdwf.FDwfAnalogOutRepeatSet(self.__hdwf, c_int(channel),c_int(0))
|
|
343
|
if runDuration is None:
|
|
355
|
if runDuration is None:
|
|
344
|
runDuration = triggerFrq
|
|
356
|
runDuration = triggerFrq
|
|
345
|
self.__libdwf.FDwfAnalogOutRunSet(self.__hdwf, c_int(channel),c_double(runDuration))
|
|
357
|
self.__libdwf.FDwfAnalogOutRunSet(self.__hdwf, c_int(channel),c_double(runDuration))
|
|
346
|
self.__libdwf.FDwfAnalogOutWaitSet(self.__hdwf, c_int(channel), c_double(wait))
|
|
358
|
self.__libdwf.FDwfAnalogOutWaitSet(self.__hdwf, c_int(channel), c_double(wait))
|
|
347
|
self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
|
|
359
|
self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
|
|
348
|
|
|
360
|
|
|
349
|
def analog_out_gen_arbit(self,samplesBuffer ,repeatingFrequency=100, channel=0, amplitude=1.0, offset=0.0):
|
|
361
|
def analog_out_gen_arbit(self,samplesBuffer ,repeatingFrequency=100, channel=0, amplitude=1.0, offset=0.0):
|
|
350
|
self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
|
|
362
|
self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
|
|
351
|
cnt=self.__limits.genBuffSize(len(samplesBuffer))
|
|
363
|
cnt=self.__limits.genBuffSize(len(samplesBuffer))
|
|
352
|
buf=(c_double*cnt)()
|
|
364
|
buf=(c_double*cnt)()
|
|
353
|
buf[:]=samplesBuffer[0:cnt]
|
|
365
|
buf[:]=samplesBuffer[0:cnt]
|
|
354
|
#repeatingFrequency = self.__limits.genFreq(repeatingFrequency*cnt)/cnt
|
|
366
|
#repeatingFrequency = self.__limits.genFreq(repeatingFrequency*cnt)/cnt
|
|
355
|
self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
|
|
367
|
self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
|
|
356
|
self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get("Custom")))
|
|
368
|
self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get("Custom")))
|
|
357
|
self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(repeatingFrequency))
|
|
369
|
self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(repeatingFrequency))
|
|
358
|
self.__libdwf.FDwfAnalogOutNodeAmplitudeSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genAmplitude(amplitude)))
|
|
370
|
self.__libdwf.FDwfAnalogOutNodeAmplitudeSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genAmplitude(amplitude)))
|
|
359
|
self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genOffset(offset)))
|
|
371
|
self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genOffset(offset)))
|
|
360
|
self.__libdwf.FDwfAnalogOutNodeDataSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, buf, c_int(cnt))
|
|
372
|
self.__libdwf.FDwfAnalogOutNodeDataSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, buf, c_int(cnt))
|
|
361
|
self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
|
|
373
|
self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
|
|
362
|
|
|
374
|
|
|
363
|
def analog_out_set_trigger(self, channel=0, trigSrc=trigsrcExternal1, trigRepeat=True):
|
|
375
|
def analog_out_set_trigger(self, channel=0, trigSrc=trigsrcExternal1, trigRepeat=True):
|
|
364
|
self.__libdwf.FDwfAnalogOutTriggerSourceSet(self.__hdwf, c_int(channel), trigSrc)
|
|
376
|
self.__libdwf.FDwfAnalogOutTriggerSourceSet(self.__hdwf, c_int(channel), trigSrc)
|
|
365
|
self.__libdwf.FDwfAnalogOutRepeatTriggerSet(self.__hdwf, c_int(channel), c_bool(trigRepeat))
|
|
377
|
self.__libdwf.FDwfAnalogOutRepeatTriggerSet(self.__hdwf, c_int(channel), c_bool(trigRepeat))
|
|
366
|
|
|
378
|
|
|
|
|
|
379
|
def __del__(self):
|
|
|
|
|
380
|
if self.__opened:
|
|
|
|
|
381
|
self.__libdwf.FDwfDeviceClose(self.__hdwf)
|
|
367
|
|
|
382
|
|
|
368
|
def analog_out_status(self, channel=0):
|
|
383
|
def analog_out_status(self, channel=0):
|
|
369
|
status = c_byte(DwfStateDone.value)
|
|
384
|
status = c_byte(DwfStateDone.value)
|
|
370
|
self.__libdwf.FDwfAnalogOutStatus(self.__hdwf, c_int(channel), byref(status))
|
|
385
|
self.__libdwf.FDwfAnalogOutStatus(self.__hdwf, c_int(channel), byref(status))
|
|
371
|
return status
|
|
386
|
return status
|
|
372
|
# def analog_out_modulation(self, channel=0,
|
|
387
|
# def analog_out_modulation(self, channel=0,
|
|
373
|
# carrier_frequency=10, carrier_shape='Sine', carrier_amplitude=1.0, carrier_offset=0.0, carrier_phase=0.0, carrier_symmetry=0.5,
|
|
388
|
# carrier_frequency=10, carrier_shape='Sine', carrier_amplitude=1.0, carrier_offset=0.0, carrier_phase=0.0, carrier_symmetry=0.5,
|
|
374
|
# AM_frequency=0.2857, AM_shape='Square', AM_amplitude=100.0, AM_offset=0.0, AM_phase=0.0, AM_percentageSymmetry=0.2857,
|
|
389
|
# AM_frequency=0.2857, AM_shape='Square', AM_amplitude=100.0, AM_offset=0.0, AM_phase=0.0, AM_percentageSymmetry=0.2857,
|
|
375
|
# syncOnTrigger=trigsrcExternal1, triggerFrq=1.0, wait=0.0, runDuration=None):
|
|
390
|
# syncOnTrigger=trigsrcExternal1, triggerFrq=1.0, wait=0.0, runDuration=None):
|
|
376
|
# self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
|
|
391
|
# self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
|
|
377
|
# self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
|
|
392
|
# self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
|
|
378
|
#
|
|
393
|
#
|
|
379
|
# self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get(carrier_shape)))
|
|
394
|
# self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get(carrier_shape)))
|
|
380
|
# self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genFreq(carrier_frequency)))
|
|
395
|
# self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genFreq(carrier_frequency)))
|
|
381
|
# self.__libdwf.FDwfAnalogOutNodeAmplitudeSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genAmplitude(carrier_amplitude)))
|
|
396
|
# self.__libdwf.FDwfAnalogOutNodeAmplitudeSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genAmplitude(carrier_amplitude)))
|
|
382
|
# self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genOffset(carrier_offset)))
|
|
397
|
# self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genOffset(carrier_offset)))
|
|
383
|
# self.__libdwf.FDwfAnalogOutNodePhaseSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(carrier_phase))
|
|
398
|
# self.__libdwf.FDwfAnalogOutNodePhaseSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(carrier_phase))
|
|
384
|
# self.__libdwf.FDwfAnalogOutNodeSymmetrySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(carrier_percentageSymmetry))
|
|
399
|
# self.__libdwf.FDwfAnalogOutNodeSymmetrySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(carrier_percentageSymmetry))
|
|
385
|
#
|
|
400
|
#
|
|
386
|
# self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_bool(True))
|
|
401
|
# self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_bool(True))
|
|
387
|
# self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_int(shapes.get(AM_shape)))
|
|
402
|
# self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_int(shapes.get(AM_shape)))
|
|
388
|
# self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(self.__limits.genFreqAM_frequency)))
|
|
403
|
# self.__libdwf.FDwfAnalogOutNodeFrequencySet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(self.__limits.genFreqAM_frequency)))
|
|
389
|
# self.__libdwf.FDwfAnalogOutNodeAmplitudeSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(self.__limits.genAmplitude(AM_amplitude)))
|
|
404
|
# self.__libdwf.FDwfAnalogOutNodeAmplitudeSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(self.__limits.genAmplitude(AM_amplitude)))
|
|
390
|
# self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(self.__limits.genOffset(AM_offset)))
|
|
405
|
# self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(self.__limits.genOffset(AM_offset)))
|
|
391
|
# self.__libdwf.FDwfAnalogOutNodePhaseSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(AM_phase))
|
|
406
|
# self.__libdwf.FDwfAnalogOutNodePhaseSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(AM_phase))
|
|
392
|
# self.__libdwf.FDwfAnalogOutNodeSymmetrySet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(AM_percentageSymmetry))
|
|
407
|
# self.__libdwf.FDwfAnalogOutNodeSymmetrySet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(AM_percentageSymmetry))
|
|
393
|
#
|
|
408
|
#
|
|
394
|
# if syncOnTrigger:
|
|
409
|
# if syncOnTrigger:
|
|
395
|
# self.analog_out_set_trigger(channel)
|
|
410
|
# self.analog_out_set_trigger(channel)
|
|
396
|
# self.__libdwf.FDwfAnalogOutRepeatSet(self.__hdwf, c_int(channel),c_int(0))
|
|
411
|
# self.__libdwf.FDwfAnalogOutRepeatSet(self.__hdwf, c_int(channel),c_int(0))
|
|
397
|
# if runDuration is None:
|
|
412
|
# if runDuration is None:
|
|
398
|
# runDuration = triggerFrq
|
|
413
|
# runDuration = triggerFrq
|
|
399
|
# self.__libdwf.FDwfAnalogOutRunSet(self.__hdwf, c_int(channel),c_double(runDuration))
|
|
414
|
# self.__libdwf.FDwfAnalogOutRunSet(self.__hdwf, c_int(channel),c_double(runDuration))
|
|
400
|
# self.__libdwf.FDwfAnalogOutWaitSet(self.__hdwf, c_int(channel), c_double(wait))
|
|
415
|
# self.__libdwf.FDwfAnalogOutWaitSet(self.__hdwf, c_int(channel), c_double(wait))
|
|
401
|
# self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
|
|
416
|
# self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
|
|
402
|
|
|
417
|
|
|
|
|
|
418
|
def digital_io_output_enable(self, value):
|
|
|
|
|
419
|
self.__libdwf.FDwfDigitalIOOutputEnableSet(self.__hdwf, c_int(value))
|
|
403
|
|
|
420
|
|
|
404
|
|
|
421
|
def digital_io_get(self):
|
|
|
|
|
422
|
dwRead = c_uint32()
|
|
|
|
|
423
|
self.__libdwf.FDwfDigitalIOStatus (self.__hdwf)
|
|
|
|
|
424
|
self.__libdwf.FDwfDigitalIOInputStatus(self.__hdwf, byref(dwRead))
|
|
|
|
|
425
|
return dwRead.value
|
|
405
|
|
|
426
|
|
|
406
|
def __del__(self):
|
|
427
|
def digital_io_set(self,value):
|
|
407
|
if self.__opened:
|
|
428
|
self.__libdwf.FDwfDigitalIOOutputSet(self.__hdwf, c_int(value))
|
|
408
|
self.__libdwf.FDwfDeviceClose(self.__hdwf)
|
|
|
|
|
409
|
|
|
429
|
|
|
|
|
|
430
|
@property
|
|
|
|
|
431
|
def digital_io(self):
|
|
|
|
|
432
|
return self.digital_io_get()
|
|
|
|
|
433
|
|
|
|
|
|
434
|
@digital_io.setter
|
|
|
|
|
435
|
def digital_io(self,value):
|
|
|
|
|
436
|
self.digital_io_set(value)
|
|
410
|
|
|
437
|
|
|
411
|
if __name__ == '__main__':
|
|
438
|
if __name__ == '__main__':
|
|
412
|
print("open first dev")
|
|
439
|
print("open first dev")
|
|
413
|
test = Discovery()
|
|
440
|
test = Discovery()
|
|
414
|
test.set_power()
|
|
441
|
test.set_power()
|
|
415
|
for i in range(2):
|
|
442
|
for i in range(2):
|
|
416
|
time.sleep(0.2)
|
|
443
|
time.sleep(0.2)
|
|
417
|
print(test.get_power())
|
|
444
|
print(test.get_power())
|
|
418
|
test.analog_out_gen()
|
|
445
|
test.analog_out_gen()
|
|
419
|
res=test.analog_in_read(frequency=1000000,samplesCount=1000)
|
|
446
|
res=test.analog_in_read(frequency=1000000,samplesCount=1000)
|
|
420
|
print(res)
|
|
447
|
print(res)
|
|
421
|
plt.plot(range(len(res[0][0])),res[0][0])
|
|
448
|
plt.plot(range(len(res[0][0])),res[0][0])
|
|
422
|
plt.plot(range(len(res[0][0])),res[0][1])
|
|
449
|
plt.plot(range(len(res[0][0])),res[0][1])
|
|
423
|
plt.show()
|
|
450
|
plt.show()
|
|
424
|
test.temp()
|
|
451
|
test.temp()
|
|
425
|
# del test
|
|
452
|
# del test
|
|
426
|
quit()
|
|
453
|
quit()
|
|
427
|
|
|
454
|
|
|
428
|
|
|
455
|
|
|
429
|
|
|
456
|
|
|
430
|
|
|
457
|
|
|
431
|
|
|
458
|
|