##// END OF EJS Templates
Merge
jeandet -
r16:57e3ff45aefd merge tip default draft
parent child
Show More
@@ -0,0 +1,87
1 #!/usr/bin/env python
2 #-*- coding: utf-8 -*-
3 """Simple python library to drive the analog discovery module from www.digilentinc.com
4 With Discoply addon connected https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/INSTRUMENTATION/PCB/DiscoPli
5 """
6
7 from ctypes import *
8 import time
9 import sys
10 import os
11 import matplotlib.pyplot as plt
12 import numpy as np
13 from lppinstru import discovery
14
15 __author__ = "Alexis Jeandet"
16 __copyright__ = "Copyright 2015, Laboratory of Plasma Physics"
17 __credits__ = []
18 __license__ = "GPLv2"
19 __version__ = "1.0.0"
20 __maintainer__ = "Alexis Jeandet"
21 __email__ = "alexis.jeandet@member.fsf.org"
22 __status__ = "Production"
23
24
25
26 class discoply(discovery.Discovery):
27 _gains={
28 "LTC-6910-1":[0, 1, 2, 5, 10, 20, 50, 100],
29 "LTC-6910-2":[0, 1, 2, 4, 8, 16, 32, 64],
30 "LTC-6910-3":[0, 1, 2, 3, 4, 5, 6, 7]
31 }
32 def __init__(self,card=-1,model="LTC-6910-1",gain_ch1=1,gain_ch2=1):
33 super(discoply,self).__init__(card)
34 self._model=model
35 self.set_power()
36 self.digital_io_output_enable(0x3F)
37 self.gain_idx = [gain_ch1,gain_ch2]
38
39 def auto_remove_offset(self,channel=0):
40 out=0.0
41 for i in range(10):
42 self.analog_out_gen(shape="DC",offset=out)
43 time.sleep(0.2)
44 mean=super(discoply,self).analog_in_read(frequency=1e5,samplesCount=8192)[0][channel].mean()
45 out+=-mean*14./self.gain[channel]
46 return mean
47
48 def analog_in_read(self,ch1=True,ch2=True,frequency=100000000,samplesCount=100,ch1range=5.0,ch2range=5.0,trigger=discovery.trigsrcNone):
49 data=super(discoply,self).analog_in_read(ch1,ch2,frequency,samplesCount,ch1range,ch2range,trigger)
50 if self.gain[0] !=0:
51 data[0][0]=data[0][0]/self.gain[0]
52 if self.gain[1] !=0:
53 data[0][1]=data[0][1]/self.gain[1]
54 return data
55
56 @property
57 def offset(self):
58 data=super(discoply,self).analog_in_read(frequency=1e4,samplesCount=8192)[0]
59 return [data[0].mean(),data[1].mean()]
60
61 @property
62 def gain(self):
63 return [
64 self._gains[self._model][self.gain_idx[0]],
65 self._gains[self._model][self.gain_idx[1]]]
66
67 @property
68 def gain_idx(self):
69 dio=self.digital_io
70 return [dio&7,(dio>>3)&7]
71
72 @gain_idx.setter
73 def gain_idx(self,value):
74 self.digital_io =(value[0]&7) + ((value[1]&7)<<3)
75
76 def set_gain_idx(self,value,channel):
77 gain = self.gain & ~(7 << [0,3][channel])
78 self.gain_idx = gain + (value << [0,3][channel])
79
80
81 if __name__ == '__main__':
82 quit()
83
84
85
86
87
@@ -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
@@ -1,127 +1,139
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 #-*- coding: utf-8 -*-
2 #-*- coding: utf-8 -*-
3 """Simple python library to drive DLP-TEMP module from www.dlpdesign.com
3 """Simple python library to drive DLP-TEMP module from www.dlpdesign.com
4 """
4 """
5 import time
5 import time
6 import sys
6 import sys
7 import os
7 import os
8 import matplotlib.pyplot as plt
8 import matplotlib.pyplot as plt
9 import numpy as np
9 import numpy as np
10 import serial
10 import serial
11 import struct
11
12
12 __author__ = "Alexis Jeandet"
13 __author__ = "Alexis Jeandet"
13 __copyright__ = "Copyright 2015, Laboratory of Plasma Physics"
14 __copyright__ = "Copyright 2015, Laboratory of Plasma Physics"
14 __credits__ = []
15 __credits__ = []
15 __license__ = "GPLv2"
16 __license__ = "GPLv2"
16 __version__ = "1.0.0"
17 __version__ = "1.0.0"
17 __maintainer__ = "Alexis Jeandet"
18 __maintainer__ = "Alexis Jeandet"
18 __email__ = "alexis.jeandet@member.fsf.org"
19 __email__ = "alexis.jeandet@member.fsf.org"
19 __status__ = "Production"
20 __status__ = "Production"
20
21
21 class dlp_temp(object):
22 class dlp_temp(object):
22 sensors = {0 : b'S',
23 sensors = {0 : b'S',
23 1 : b'T',
24 1 : b'T',
24 2 : b'U',
25 2 : b'U',
25 }
26 }
26 aninputs = {0 : b'A',
27 aninputs = {0 : b'A',
27 1 : b'B',
28 1 : b'B',
28 2 : b'C',
29 2 : b'C',
29 }
30 }
30 digitin= {0 : b'M',
31 digitin= {0 : b'M',
31 1 : b'N',
32 1 : b'N',
32 2 : b'O',
33 2 : b'O',
33 }
34 }
34 digithigh= {0 : b'J',
35 digithigh= {0 : b'J',
35 1 : b'K',
36 1 : b'K',
36 2 : b'L',
37 2 : b'L',
37 }
38 }
38 digitlow= {0 : b'G',
39 digitlow= {0 : b'G',
39 1 : b'H',
40 1 : b'H',
40 2 : b'I',
41 2 : b'I',
41 }
42 }
42 def __init__(self,port):
43 def __init__(self,port):
43 self.i=0
44 self.i=0
44 self.__port=serial.Serial(port,timeout=0.5)
45 self.__port=serial.Serial(port,timeout=0.5)
45
46
46 def ping(self):
47 def ping(self):
47 self.__port.write(b"P")
48 self.__port.write(b"P")
48 return b'Q' == self.__port.read(1)
49 return b'Q' == self.__port.read(1)
49
50
50 def read_sensor(self,index):
51 def read_sensor(self,index):
51 if index < 3:
52 if index < 3:
52 self.__port.write(self.sensors.get(index))
53 self.__port.write(self.sensors.get(index))
53 dat=self.__port.read(9)
54 dat=self.__port.read(9)
54 test=( int(ord(dat[0])) + (int(ord(dat[1]))*256) )
55 temp=float(struct.unpack( "h", dat[:2])[0])*0.0625
55 temp=float(test)*0.0625
56 return temp #(temp-32.0)/1.8
56 return temp #(temp-32.0)/1.8
57 raise UserWarning("Parameter out of bound")
57 raise UserWarning("Parameter out of bound")
58
58
59 def read_analog_in(self,index):
59 def read_analog_in(self,index):
60 if index < 3:
60 if index < 3:
61 self.__port.write(self.aninputs.get(index))
61 self.__port.write(self.aninputs.get(index))
62 dat=self.__port.read(2)
62 dat=self.__port.read(2)
63 test=( int(ord(dat[0])) + (int(ord(dat[1]))*256) )
63 val=float(struct.unpack( "h", dat[:2])[0])/512.0
64 val=float(test)/512.0
65 return val
64 return val
66 raise UserWarning("Parameter out of bound")
65 raise UserWarning("Parameter out of bound")
67
66
68 def digit_in(self,index):
67 def digit_in(self,index):
69 if index < 3:
68 if index < 3:
70 self.__port.write(self.digitin.get(index))
69 self.__port.write(self.digitin.get(index))
71 dat=self.__port.read(1)
70 dat=self.__port.read(1)
72 return dat
71 return dat
73 raise UserWarning("Parameter out of bound")
72 raise UserWarning("Parameter out of bound")
74
73
75 def digit_out(self,index,val):
74 def digit_out(self,index,val):
76 if index < 3:
75 if index < 3:
77 if val:
76 if val:
78 self.__port.write(self.digithigh.get(index))
77 self.__port.write(self.digithigh.get(index))
79 else:
78 else:
80 self.__port.write(self.digitlow.get(index))
79 self.__port.write(self.digitlow.get(index))
81 raise UserWarning("Parameter out of bound")
80 raise UserWarning("Parameter out of bound")
82
81
83 @property
82 @property
84 def sensor1(self):
83 def sensor1(self):
85 return self.read_sensor(0)
84 return self.read_sensor(0)
86
85
87 @property
86 @property
88 def sensor2(self):
87 def sensor2(self):
89 return self.read_sensor(1)
88 return self.read_sensor(1)
90
89
91 @property
90 @property
92 def sensor3(self):
91 def sensor3(self):
93 return self.read_sensor(2)
92 return self.read_sensor(2)
94
93
95 @property
94 @property
96 def AN1(self):
95 def AN1(self):
97 return self.read_analog_in(0)
96 return self.read_analog_in(0)
98 @property
97 @property
99 def AN2(self):
98 def AN2(self):
100 return self.read_analog_in(1)
99 return self.read_analog_in(1)
101 @property
100 @property
102 def AN3(self):
101 def AN3(self):
103 return self.read_analog_in(2)
102 return self.read_analog_in(2)
104
103
105 @property
104 @property
106 def GP2(self):
105 def GP2(self):
107 return self.digit_in(0)
106 return self.digit_in(0)
108 @GP2.setter
107 @GP2.setter
109 def GP2(self,value):
108 def GP2(self,value):
110 return self.digit_out(0,val)
109 return self.digit_out(0,value)
111
110
112 @property
111 @property
113 def GP0(self):
112 def GP0(self):
114 return self.digit_in(1)
113 return self.digit_in(1)
115 @GP0.setter
114 @GP0.setter
116 def GP0(self,value):
115 def GP0(self,value):
117 return self.digit_out(1,val)
116 return self.digit_out(1,value)
118
117
119 @property
118 @property
120 def GP4(self):
119 def GP4(self):
121 return self.digit_in(2)
120 return self.digit_in(2)
122 @GP4.setter
121 @GP4.setter
123 def GP4(self,value):
122 def GP4(self,value):
124 return self.digit_out(2,val)
123 return self.digit_out(2,value)
124
125
126 def main(argv):
127 if len(argv)==4:
128 print(argv[3])
129 if len(argv)>=3:
130 dlp=dlp_temp(argv[0])
131 while(True):
132 readout=[dlp.read_sensor(i) for i in range(int(argv[1]))]
133 print("{date}\t{values}".format(date=time.strftime("%Y-%m-%dT%H:%M:%S"),values="\t".join([str(x) for x in readout] )))
134 time.sleep(float(argv[2]))
135
125
136
126 if __name__ == '__main__':
137 if __name__ == '__main__':
127 print("")
138 print(sys.argv)
139 main(sys.argv[1:])
@@ -1,73 +1,88
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 #-*- coding: utf-8 -*-
2 #-*- coding: utf-8 -*-
3 """Simple python library to communicate with Prologix USB GPIB module.
3 """Simple python library to communicate with Prologix USB GPIB module.
4 """
4 """
5 import time
5 import time
6 import sys
6 import sys
7 import os
7 import os
8 import matplotlib.pyplot as plt
8 import matplotlib.pyplot as plt
9 import numpy as np
9 import numpy as np
10 import serial
10 import serial
11
11
12 __author__ = "Alexis Jeandet"
12 __author__ = "Alexis Jeandet"
13 __copyright__ = "Copyright 2015, Laboratory of Plasma Physics"
13 __copyright__ = "Copyright 2015, Laboratory of Plasma Physics"
14 __credits__ = []
14 __credits__ = []
15 __license__ = "GPLv2"
15 __license__ = "GPLv2"
16 __version__ = "1.0.0"
16 __version__ = "1.0.0"
17 __maintainer__ = "Alexis Jeandet"
17 __maintainer__ = "Alexis Jeandet"
18 __email__ = "alexis.jeandet@member.fsf.org"
18 __email__ = "alexis.jeandet@member.fsf.org"
19 __status__ = "Development"
19 __status__ = "Development"
20
20
21 class UsbGpib(object):
21 class UsbGpib(object):
22 modedic = {0:"DEVICE" ,
22 modedic = {0:"DEVICE" ,
23 1:"CONTROLLER" ,}
23 1:"CONTROLLER" ,}
24 revmodedic = {"DEVICE":"0" ,
24 revmodedic = {"DEVICE":"0" ,
25 "CONTROLLER":"1" ,}
25 "CONTROLLER":"1" ,}
26 def __init__(self,port,address=0):
26 def __init__(self,port,address=0,baudrate=9600):
27 self._port=serial.Serial(port,timeout=0.1)
27 self._port=serial.Serial(port,timeout=0.1,baudrate=baudrate)
28 self._address=address
28 self._address=address
29 self._mode=1
29 self.write("++auto 1")
30 self._auto=1
31 self.mode=1
30 self.write("++ver")
32 self.write("++ver")
31 self.version=self.read()
33 self.version=self.read()
32 self.write("++auto 1")
34
33
35
34 def set_as_device(self):
36 def set_as_device(self):
35 self.write("++mode 0")
37 self.write("++mode 0")
36 def set_as_controller(self):
38 def set_as_controller(self):
37 self.write("++mode 1")
39 self.write("++mode 1")
38
40
39 @property
41 @property
40 def mode(self):
42 def mode(self):
41 self.write("++mode")
43 self.write("++mode")
42 self._mode= self.modedic[int(self.read())]
44 self._mode= self.modedic[int(self.read())]
43 return self._mode
45 return self._mode
44
46
45 @mode.setter
47 @mode.setter
46 def mode(self,new_mode):
48 def mode(self,new_mode):
47 self._mode=self.revmodedic[new_mode]
49 if type(new_mode) == type("str"):
50 self._mode=self.revmodedic[new_mode]
51 elif type(new_mode) == type(1):
52 self._mode=new_mode
48 self.write("++mode %d" % self._mode)
53 self.write("++mode %d" % self._mode)
49
54
50 @property
55 @property
51 def address(self):
56 def address(self):
52 self._address=int(self.read("++addr"))
57 self._address=int(self.read("++addr"))
53 return self._address
58 return self._address
54
59
55 @address.setter
60 @address.setter
56 def address(self,value):
61 def address(self,value):
57 self._address=int(value)
62 self._address=int(value)
58 self.write("++addr %d" % self._address)
63 self.write("++addr %d" % self._address)
59
64
60 def write(self,command):
65 def write(self,command):
61 self._port.write(b"%s\n\r" % command)
66 self._port.write(("%s\n\r" % command).encode())
62 self._port.flush()
67 self._port.flush()
63
68
64
69
65 def read(self,command="",GPIB=False):
70 def read(self,command=""):
66 if not command=="":
71 if not command=="":
67 self.write(command)
72 self.write(command)
68 if GPIB:
73 if command[0:2]!="++" and self._auto==0:
69 self.write("++read")
74 self.write("++read")
70 return self._port.readall()
75 return self._port.readall()
71
76
72 def idn(self):
77 def idn(self):
73 return self.read("*IDN?")
78 return self.read("*IDN?")
79
80 @property
81 def auto_read_after_write(self):
82 self._auto=int(self.read("++auto"))
83 return self._auto
84
85 @auto_read_after_write.setter
86 def auto_read_after_write(self,enabled):
87 self._auto=enabled
88 self.write("++auto %d" % self._auto)
General Comments 0
You need to be logged in to leave comments. Login now