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