##// END OF EJS Templates
Added Discoply...
jeandet -
r9:142b4267322d 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,443
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
78
79 shapes = {'DC' : 0,
79 shapes = {'DC' : 0,
80 'Sine' : 1,
80 'Sine' : 1,
81 'Square' : 2,
81 'Square' : 2,
82 'Triangle' : 3,
82 'Triangle' : 3,
83 'RampUp' : 4,
83 'RampUp' : 4,
84 'RampDown' : 5,
84 'RampDown' : 5,
85 'Noise' : 6,
85 'Noise' : 6,
86 'Custom' : 30,
86 'Custom' : 30,
87 'Play' :31, }
87 'Play' :31, }
88
88
89 closed=False
89 closed=False
90 opened=True
90 opened=True
91
91
92
92
93 class DiscoveryLimits(object):
93 class DiscoveryLimits(object):
94 class limitRange(object):
94 class limitRange(object):
95 def __init__(self,Min,Max,name="Unknow",unit=""):
95 def __init__(self,Min,Max,name="Unknow",unit=""):
96 self.Min = Min
96 self.Min = Min
97 self.Max = Max
97 self.Max = Max
98 self.name = name
98 self.name = name
99 self.unit = unit
99 self.unit = unit
100
100
101 def conform(self,value):
101 def conform(self,value):
102 if value<self.Min:
102 if value<self.Min:
103 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))
104 return self.Min
104 return self.Min
105 if value>self.Max:
105 if value>self.Max:
106 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))
107 return self.Max
107 return self.Max
108 return value
108 return value
109
109
110 def __str__(self):
110 def __str__(self):
111 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
112
112
113 errors = {0: RuntimeError("No card opened"),
113 errors = {0: RuntimeError("No card opened"),
114 1: UserWarning("Parameter out of bound"),
114 1: UserWarning("Parameter out of bound"),
115 }
115 }
116 def __init__(self,libdwf,hdwf):
116 def __init__(self,libdwf,hdwf):
117 self.limits=[]
117 self.limits=[]
118 self.ACQ_IN_RANGES=[0.0]
118 self.ACQ_IN_RANGES=[0.0]
119 if hdwf.value == nodev.value:
119 if hdwf.value == nodev.value:
120 return
120 return
121 self.__hdwf=hdwf
121 self.__hdwf=hdwf
122 self.__libdwf=libdwf
122 self.__libdwf=libdwf
123 Mind=c_double()
123 Mind=c_double()
124 Maxd=c_double()
124 Maxd=c_double()
125 Mini=c_int()
125 Mini=c_int()
126 Maxi=c_int()
126 Maxi=c_int()
127 StepsCount=c_int()
127 StepsCount=c_int()
128 Steps=(c_double*32)()
128 Steps=(c_double*32)()
129 self.__libdwf.FDwfAnalogInBufferSizeInfo(self.__hdwf, byref(Mini), byref(Maxi))
129 self.__libdwf.FDwfAnalogInBufferSizeInfo(self.__hdwf, byref(Mini), byref(Maxi))
130 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")
131 self.limits.append(self.ACQ_BUF)
131 self.limits.append(self.ACQ_BUF)
132 self.__libdwf.FDwfAnalogInFrequencyInfo(self.__hdwf, byref(Mind), byref(Maxd))
132 self.__libdwf.FDwfAnalogInFrequencyInfo(self.__hdwf, byref(Mind), byref(Maxd))
133 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")
134 self.limits.append(self.ACQ_FREQ)
134 self.limits.append(self.ACQ_FREQ)
135 self.__libdwf.FDwfAnalogInChannelRangeSteps(self.__hdwf, byref(Steps), byref(StepsCount))
135 self.__libdwf.FDwfAnalogInChannelRangeSteps(self.__hdwf, byref(Steps), byref(StepsCount))
136 self.ACQ_IN_RANGES=Steps[0:StepsCount.value]
136 self.ACQ_IN_RANGES=Steps[0:StepsCount.value]
137 self.__libdwf.FDwfAnalogOutNodeAmplitudeInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
137 self.__libdwf.FDwfAnalogOutNodeAmplitudeInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
138 byref(Mind), byref(Maxd))
138 byref(Mind), byref(Maxd))
139 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")
140 self.limits.append(self.GEN_AMPL)
140 self.limits.append(self.GEN_AMPL)
141 self.__libdwf.FDwfAnalogOutNodeFrequencyInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
141 self.__libdwf.FDwfAnalogOutNodeFrequencyInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
142 byref(Mind), byref(Maxd))
142 byref(Mind), byref(Maxd))
143 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")
144 self.limits.append(self.GEN_FREQ)
144 self.limits.append(self.GEN_FREQ)
145 self.__libdwf.FDwfAnalogOutNodeOffsetInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
145 self.__libdwf.FDwfAnalogOutNodeOffsetInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
146 byref(Mind), byref(Maxd))
146 byref(Mind), byref(Maxd))
147 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")
148 self.limits.append(self.GEN_OFFSET)
148 self.limits.append(self.GEN_OFFSET)
149 self.__libdwf.FDwfAnalogOutNodeDataInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
149 self.__libdwf.FDwfAnalogOutNodeDataInfo(self.__hdwf,c_int(0), AnalogOutNodeCarrier,
150 byref(Mini), byref(Maxi))
150 byref(Mini), byref(Maxi))
151 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")
152 self.limits.append(self.GEN_BUFF)
152 self.limits.append(self.GEN_BUFF)
153
153
154
154
155 def __conformParam(self,minVal,maxVal,val):
155 def __conformParam(self,minVal,maxVal,val):
156 if val<minVal:
156 if val<minVal:
157 raise self.errors.get(1)
157 raise self.errors.get(1)
158 print("Force to "+str(minVal))
158 print("Force to "+str(minVal))
159 return minVal
159 return minVal
160 if val>maxVal:
160 if val>maxVal:
161 raise self.errors.get(1)
161 raise self.errors.get(1)
162 print("Force to "+str(maxVal))
162 print("Force to "+str(maxVal))
163 return maxVal
163 return maxVal
164 return val
164 return val
165
165
166 def acqFreq(self, value):
166 def acqFreq(self, value):
167 return self.ACQ_FREQ.conform(value)
167 return self.ACQ_FREQ.conform(value)
168
168
169 def acqBufSize(self, value):
169 def acqBufSize(self, value):
170 return self.ACQ_BUF.conform(value)
170 return self.ACQ_BUF.conform(value)
171
171
172 def genFreq(self, value):
172 def genFreq(self, value):
173 return self.GEN_FREQ.conform(value)
173 return self.GEN_FREQ.conform(value)
174
174
175 def genAmplitude(self, value):
175 def genAmplitude(self, value):
176 return self.GEN_AMPL.conform(value)
176 return self.GEN_AMPL.conform(value)
177
177
178 def genOffset(self, value):
178 def genOffset(self, value):
179 return self.GEN_OFFSET.conform(value)
179 return self.GEN_OFFSET.conform(value)
180
180
181 def genBuffSize(self, value):
181 def genBuffSize(self, value):
182 return self.GEN_BUFF.conform(value)
182 return self.GEN_BUFF.conform(value)
183
183
184 def __str__(self):
184 def __str__(self):
185 res=str()
185 res=str()
186 for i in self.limits:
186 for i in self.limits:
187 res+=i.__str__()+"\n"
187 res+=i.__str__()+"\n"
188 res+="ACQ Input ranes: "+str(self.ACQ_IN_RANGES)
188 res+="ACQ Input ranes: "+str(self.ACQ_IN_RANGES)
189 return res
189 return res
190
190
191
191
192 class Discovery(object):
192 class Discovery(object):
193
193
194 errors = {0: RuntimeError("No card opened"),
194 errors = {0: RuntimeError("No card opened"),
195 1: UserWarning("Parameter out of bound"),
195 1: UserWarning("Parameter out of bound"),
196 }
196 }
197 def findDevice(self,device):
197 def findDevice(self,device):
198 if not self.__opened:
198 if not self.__opened:
199 raise self.errors.get(0)
199 raise self.errors.get(0)
200 nbDevices = c_int()
200 nbDevices = c_int()
201 self.__libdwf.FDwfEnum(c_int(0), byref(nbDevices))
201 self.__libdwf.FDwfEnum(c_int(0), byref(nbDevices))
202 SN = create_string_buffer(32)
202 SN = create_string_buffer(32)
203 for i in range(nbDevices.value):
203 for i in range(nbDevices.value):
204 self.__libdwf.FDwfEnumSN(c_int(i), SN)
204 self.__libdwf.FDwfEnumSN(c_int(i), SN)
205 if SN.value.decode("UTF-8") == device:
205 if SN.value.decode("UTF-8") == device:
206 return i
206 return i
207 return -1
207 return -1
208
208
209
209
210 def __init__(self,card=-1):
210 def __init__(self,card=-1):
211 if sys.platform.startswith("win"):
211 if sys.platform.startswith("win"):
212 self.__libdwf = cdll.dwf
212 self.__libdwf = cdll.dwf
213 elif sys.platform.startswith("darwin"):
213 elif sys.platform.startswith("darwin"):
214 self.__libdwf = cdll.LoadLibrary("libdwf.dylib")
214 self.__libdwf = cdll.LoadLibrary("libdwf.dylib")
215 else:
215 else:
216 self.__libdwf = cdll.LoadLibrary("libdwf.so")
216 self.__libdwf = cdll.LoadLibrary("libdwf.so")
217 self.__opened = True
217 self.__opened = True
218 self.__hdwf = c_int()
218 self.__hdwf = c_int()
219 if card != -1:
219 if card != -1:
220 SN=card
220 SN=card
221 card = self.findDevice(card)
221 card = self.findDevice(card)
222 if card == -1:
222 if card == -1:
223 raise RuntimeError( "Card not found "+ SN)
223 raise RuntimeError( "Card not found "+ SN)
224 self.__libdwf.FDwfDeviceOpen(c_int(card), byref(self.__hdwf))
224 self.__libdwf.FDwfDeviceOpen(c_int(card), byref(self.__hdwf))
225 if self.__hdwf.value == nodev.value:
225 if self.__hdwf.value == nodev.value:
226 szerr = create_string_buffer(512)
226 szerr = create_string_buffer(512)
227 self.__libdwf.FDwfGetLastErrorMsg(szerr)
227 self.__libdwf.FDwfGetLastErrorMsg(szerr)
228 print(szerr.value)
228 print(szerr.value)
229 print("failed to open device")
229 print("failed to open device")
230 self.__opened=False
230 self.__opened=False
231 self.__limits=DiscoveryLimits(self.__libdwf,self.__hdwf)
231 self.__limits=DiscoveryLimits(self.__libdwf,self.__hdwf)
232 print(self.__limits)
232 print(self.__limits)
233
233
234 @property
234 @property
235 def opened(self):
235 def opened(self):
236 return self.__opened
236 return self.__opened
237
237
238 @property
238 @property
239 def max_sampling_freq(self):
239 def max_sampling_freq(self):
240 return self.__limits.ACQ_FREQ.Max
240 return self.__limits.ACQ_FREQ.Max
241
241
242 @property
242 @property
243 def min_sampling_freq(self):
243 def min_sampling_freq(self):
244 return self.__limits.ACQ_FREQ.Min
244 return self.__limits.ACQ_FREQ.Min
245
245
246 @property
246 @property
247 def max_sampling_buffer(self):
247 def max_sampling_buffer(self):
248 return self.__limits.ACQ_BUF.Max
248 return self.__limits.ACQ_BUF.Max
249
249
250 #############################################################
250 #############################################################
251 # Power Supply
251 # Power Supply
252 #############################################################
252 #############################################################
253 def set_power(self,fiveVolt=1,minusFiveVolt=1,master=True):
253 def set_power(self,fiveVolt=1,minusFiveVolt=1,master=True):
254 if not self.__opened:
254 if not self.__opened:
255 raise self.errors.get(0)
255 raise self.errors.get(0)
256 # enable positive supply
256 # enable positive supply
257 self.__libdwf.FDwfAnalogIOChannelNodeSet(self.__hdwf, 0, 0, c_double(fiveVolt))
257 self.__libdwf.FDwfAnalogIOChannelNodeSet(self.__hdwf, 0, 0, c_double(fiveVolt))
258 # enable negative supply
258 # enable negative supply
259 self.__libdwf.FDwfAnalogIOChannelNodeSet(self.__hdwf, 1, 0, c_double(minusFiveVolt))
259 self.__libdwf.FDwfAnalogIOChannelNodeSet(self.__hdwf, 1, 0, c_double(minusFiveVolt))
260 # master enable
260 # master enable
261 return self.__libdwf.FDwfAnalogIOEnableSet(self.__hdwf, master)
261 return self.__libdwf.FDwfAnalogIOEnableSet(self.__hdwf, master)
262
262
263 def get_power(self):
263 def get_power(self):
264 if not self.__opened:
264 if not self.__opened:
265 raise self.errors.get(0)
265 raise self.errors.get(0)
266 supplyVoltage = c_double()
266 supplyVoltage = c_double()
267 supplyCurrent = c_double()
267 supplyCurrent = c_double()
268 IsEnabled = c_bool()
268 IsEnabled = c_bool()
269 self.__libdwf.FDwfAnalogIOStatus(self.__hdwf)
269 self.__libdwf.FDwfAnalogIOStatus(self.__hdwf)
270 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))
271 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))
272 self.__libdwf.FDwfAnalogIOEnableStatus(self.__hdwf, byref(IsEnabled))
272 self.__libdwf.FDwfAnalogIOEnableStatus(self.__hdwf, byref(IsEnabled))
273 return [IsEnabled.value,supplyVoltage.value,supplyCurrent.value]
273 return [IsEnabled.value,supplyVoltage.value,supplyCurrent.value]
274
274
275 #############################################################
275 #############################################################
276 # AnalogIn
276 # AnalogIn
277 #############################################################
277 #############################################################
278 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):
279 if not self.__opened:
279 if not self.__opened:
280 raise self.errors.get(0)
280 raise self.errors.get(0)
281 cnt=self.__limits.acqBufSize(samplesCount)
281 cnt=self.__limits.acqBufSize(samplesCount)
282 self.__libdwf.FDwfAnalogInFrequencySet(self.__hdwf, c_double(self.__limits.acqFreq(frequency)))
282 self.__libdwf.FDwfAnalogInFrequencySet(self.__hdwf, c_double(self.__limits.acqFreq(frequency)))
283 f=c_double()
283 f=c_double()
284 self.__libdwf.FDwfAnalogInFrequencyGet(self.__hdwf, byref(f))
284 self.__libdwf.FDwfAnalogInFrequencyGet(self.__hdwf, byref(f))
285 frequency=f.value
285 frequency=f.value
286 self.__libdwf.FDwfAnalogInBufferSizeSet(self.__hdwf, c_int(cnt))
286 self.__libdwf.FDwfAnalogInBufferSizeSet(self.__hdwf, c_int(cnt))
287 self.__libdwf.FDwfAnalogInChannelEnableSet(self.__hdwf, c_int(0), c_bool(ch1))
287 self.__libdwf.FDwfAnalogInChannelEnableSet(self.__hdwf, c_int(0), c_bool(ch1))
288 self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(0), c_double(ch1range))
288 self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(0), c_double(ch1range))
289 self.__libdwf.FDwfAnalogInChannelEnableSet(self.__hdwf, c_int(1), c_bool(ch2))
289 self.__libdwf.FDwfAnalogInChannelEnableSet(self.__hdwf, c_int(1), c_bool(ch2))
290 self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(1), c_double(ch2range))
290 self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(1), c_double(ch2range))
291 self.set_analog_in_trigger(trigger)
291 self.set_analog_in_trigger(trigger)
292 self.__libdwf.FDwfAnalogInConfigure(self.__hdwf, c_bool(False), c_bool(True))
292 self.__libdwf.FDwfAnalogInConfigure(self.__hdwf, c_bool(False), c_bool(True))
293 status = c_byte()
293 status = c_byte()
294 while True:
294 while True:
295 self.__libdwf.FDwfAnalogInStatus(self.__hdwf, c_int(1), byref(status))
295 self.__libdwf.FDwfAnalogInStatus(self.__hdwf, c_int(1), byref(status))
296 if status.value == DwfStateDone.value :
296 if status.value == DwfStateDone.value :
297 break
297 break
298 time.sleep(0.1)
298 time.sleep(0.1)
299 if ch1:
299 if ch1:
300 ch1data = (c_double*cnt)()
300 ch1data = (c_double*cnt)()
301 self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 0, ch1data, cnt)
301 self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 0, ch1data, cnt)
302 if ch2:
302 if ch2:
303 ch2data = (c_double*cnt)()
303 ch2data = (c_double*cnt)()
304 self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
304 self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
305 return [np.array([ch1data,ch2data]),frequency]
305 return [np.array([ch1data,ch2data]),frequency]
306 else:
306 else:
307 return [np.array([ch1data]),frequency]
307 return [np.array([ch1data]),frequency]
308 if ch2:
308 if ch2:
309 ch2data = (c_double*cnt)()
309 ch2data = (c_double*cnt)()
310 self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
310 self.__libdwf.FDwfAnalogInStatusData(self.__hdwf, 1, ch2data, cnt)
311 return [np.array([ch2data]),frequency]
311 return [np.array([ch2data]),frequency]
312
312
313
313
314 def set_analog_in_trigger(self,trigger=trigAuto,autoTimeout=0.0):
314 def set_analog_in_trigger(self,trigger=trigAuto,autoTimeout=0.0):
315 if not self.__opened:
315 if not self.__opened:
316 raise self.errors.get(0)
316 raise self.errors.get(0)
317 if trigger == trigAuto:
317 if trigger == trigAuto:
318 self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigsrcDetectorAnalogIn)
318 self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigsrcDetectorAnalogIn)
319 self.__libdwf.FDwfAnalogInTriggerAutoTimeoutSet(self.__hdwf,c_double(autoTimeout))
319 self.__libdwf.FDwfAnalogInTriggerAutoTimeoutSet(self.__hdwf,c_double(autoTimeout))
320 return
320 return
321 if trigger == trigNormal:
321 if trigger == trigNormal:
322 self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigsrcDetectorAnalogIn)
322 self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigsrcDetectorAnalogIn)
323 self.__libdwf.FDwfAnalogInTriggerAutoTimeoutSet(self.__hdwf,c_double(0.0))
323 self.__libdwf.FDwfAnalogInTriggerAutoTimeoutSet(self.__hdwf,c_double(0.0))
324 return
324 return
325 self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigger)
325 self.__libdwf.FDwfAnalogInTriggerSourceSet(self.__hdwf,trigger)
326
326
327 #############################################################
327 #############################################################
328 # AnalogOut
328 # AnalogOut
329 #############################################################
329 #############################################################
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):
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):
331 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
331 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
332 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))
333 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))
334 self.__libdwf.FDwfAnalogOutNodeSymmetrySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(symmetry))
335 if shape!="DC":
335 if shape!="DC":
336 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)))
337 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)))
338 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)))
339 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))
340 if syncOnTrigger:
340 if syncOnTrigger:
341 self.analog_out_set_trigger(channel)
341 self.analog_out_set_trigger(channel)
342 self.__libdwf.FDwfAnalogOutRepeatSet(self.__hdwf, c_int(channel),c_int(0))
342 self.__libdwf.FDwfAnalogOutRepeatSet(self.__hdwf, c_int(channel),c_int(0))
343 if runDuration is None:
343 if runDuration is None:
344 runDuration = triggerFrq
344 runDuration = triggerFrq
345 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))
346 self.__libdwf.FDwfAnalogOutWaitSet(self.__hdwf, c_int(channel), c_double(wait))
347 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
347 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
348
348
349 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):
350 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
350 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
351 cnt=self.__limits.genBuffSize(len(samplesBuffer))
351 cnt=self.__limits.genBuffSize(len(samplesBuffer))
352 buf=(c_double*cnt)()
352 buf=(c_double*cnt)()
353 buf[:]=samplesBuffer[0:cnt]
353 buf[:]=samplesBuffer[0:cnt]
354 #repeatingFrequency = self.__limits.genFreq(repeatingFrequency*cnt)/cnt
354 #repeatingFrequency = self.__limits.genFreq(repeatingFrequency*cnt)/cnt
355 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))
356 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")))
357 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))
358 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)))
359 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)))
360 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))
361 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
361 self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
362
362
363 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):
364 self.__libdwf.FDwfAnalogOutTriggerSourceSet(self.__hdwf, c_int(channel), trigSrc)
364 self.__libdwf.FDwfAnalogOutTriggerSourceSet(self.__hdwf, c_int(channel), trigSrc)
365 self.__libdwf.FDwfAnalogOutRepeatTriggerSet(self.__hdwf, c_int(channel), c_bool(trigRepeat))
365 self.__libdwf.FDwfAnalogOutRepeatTriggerSet(self.__hdwf, c_int(channel), c_bool(trigRepeat))
366
366
367 def __del__(self):
368 if self.__opened:
369 self.__libdwf.FDwfDeviceClose(self.__hdwf)
367
370
368 def analog_out_status(self, channel=0):
371 def analog_out_status(self, channel=0):
369 status = c_byte(DwfStateDone.value)
372 status = c_byte(DwfStateDone.value)
370 self.__libdwf.FDwfAnalogOutStatus(self.__hdwf, c_int(channel), byref(status))
373 self.__libdwf.FDwfAnalogOutStatus(self.__hdwf, c_int(channel), byref(status))
371 return status
374 return status
372 # def analog_out_modulation(self, channel=0,
375 # 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,
376 # 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,
377 # 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):
378 # syncOnTrigger=trigsrcExternal1, triggerFrq=1.0, wait=0.0, runDuration=None):
376 # self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
379 # self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False))
377 # self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
380 # self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True))
378 #
381 #
379 # self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get(carrier_shape)))
382 # 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)))
383 # 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)))
384 # 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)))
385 # 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))
386 # 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))
387 # self.__libdwf.FDwfAnalogOutNodeSymmetrySet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(carrier_percentageSymmetry))
385 #
388 #
386 # self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_bool(True))
389 # 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)))
390 # 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)))
391 # 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)))
392 # 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)))
393 # 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))
394 # 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))
395 # self.__libdwf.FDwfAnalogOutNodeSymmetrySet(self.__hdwf, c_int(channel), AnalogOutNodeAM, c_double(AM_percentageSymmetry))
393 #
396 #
394 # if syncOnTrigger:
397 # if syncOnTrigger:
395 # self.analog_out_set_trigger(channel)
398 # self.analog_out_set_trigger(channel)
396 # self.__libdwf.FDwfAnalogOutRepeatSet(self.__hdwf, c_int(channel),c_int(0))
399 # self.__libdwf.FDwfAnalogOutRepeatSet(self.__hdwf, c_int(channel),c_int(0))
397 # if runDuration is None:
400 # if runDuration is None:
398 # runDuration = triggerFrq
401 # runDuration = triggerFrq
399 # self.__libdwf.FDwfAnalogOutRunSet(self.__hdwf, c_int(channel),c_double(runDuration))
402 # self.__libdwf.FDwfAnalogOutRunSet(self.__hdwf, c_int(channel),c_double(runDuration))
400 # self.__libdwf.FDwfAnalogOutWaitSet(self.__hdwf, c_int(channel), c_double(wait))
403 # self.__libdwf.FDwfAnalogOutWaitSet(self.__hdwf, c_int(channel), c_double(wait))
401 # self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
404 # self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True))
402
405
403
406 def digital_io_get(self):
404
407 dwRead = c_uint32()
408 self.__libdwf.FDwfDigitalIOStatus (self.__hdwf)
409 self.__libdwf.FDwfDigitalIOInputStatus(self.__hdwf, byref(dwRead))
410 return dwRead.value
405
411
406 def __del__(self):
412 def digital_io_set(self,value):
407 if self.__opened:
413 self.__libdwf.FDwfDigitalIOOutputSet(self.__hdwf, c_int(value))
408 self.__libdwf.FDwfDeviceClose(self.__hdwf)
409
414
415 @property
416 def digital_io(self):
417 return self.digital_io_get()
418
419 @digital_io.setter
420 def digital_io(self,value):
421 self.digital_io_set(value)
410
422
411 if __name__ == '__main__':
423 if __name__ == '__main__':
412 print("open first dev")
424 print("open first dev")
413 test = Discovery()
425 test = Discovery()
414 test.set_power()
426 test.set_power()
415 for i in range(2):
427 for i in range(2):
416 time.sleep(0.2)
428 time.sleep(0.2)
417 print(test.get_power())
429 print(test.get_power())
418 test.analog_out_gen()
430 test.analog_out_gen()
419 res=test.analog_in_read(frequency=1000000,samplesCount=1000)
431 res=test.analog_in_read(frequency=1000000,samplesCount=1000)
420 print(res)
432 print(res)
421 plt.plot(range(len(res[0][0])),res[0][0])
433 plt.plot(range(len(res[0][0])),res[0][0])
422 plt.plot(range(len(res[0][0])),res[0][1])
434 plt.plot(range(len(res[0][0])),res[0][1])
423 plt.show()
435 plt.show()
424 test.temp()
436 test.temp()
425 # del test
437 # del test
426 quit()
438 quit()
427
439
428
440
429
441
430
442
431
443
@@ -1,127 +1,127
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
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__ = "Production"
19 __status__ = "Production"
20
20
21 class dlp_temp(object):
21 class dlp_temp(object):
22 sensors = {0 : b'S',
22 sensors = {0 : b'S',
23 1 : b'T',
23 1 : b'T',
24 2 : b'U',
24 2 : b'U',
25 }
25 }
26 aninputs = {0 : b'A',
26 aninputs = {0 : b'A',
27 1 : b'B',
27 1 : b'B',
28 2 : b'C',
28 2 : b'C',
29 }
29 }
30 digitin= {0 : b'M',
30 digitin= {0 : b'M',
31 1 : b'N',
31 1 : b'N',
32 2 : b'O',
32 2 : b'O',
33 }
33 }
34 digithigh= {0 : b'J',
34 digithigh= {0 : b'J',
35 1 : b'K',
35 1 : b'K',
36 2 : b'L',
36 2 : b'L',
37 }
37 }
38 digitlow= {0 : b'G',
38 digitlow= {0 : b'G',
39 1 : b'H',
39 1 : b'H',
40 2 : b'I',
40 2 : b'I',
41 }
41 }
42 def __init__(self,port):
42 def __init__(self,port):
43 self.i=0
43 self.i=0
44 self.__port=serial.Serial(port,timeout=0.5)
44 self.__port=serial.Serial(port,timeout=0.5)
45
45
46 def ping(self):
46 def ping(self):
47 self.__port.write(b"P")
47 self.__port.write(b"P")
48 return b'Q' == self.__port.read(1)
48 return b'Q' == self.__port.read(1)
49
49
50 def read_sensor(self,index):
50 def read_sensor(self,index):
51 if index < 3:
51 if index < 3:
52 self.__port.write(self.sensors.get(index))
52 self.__port.write(self.sensors.get(index))
53 dat=self.__port.read(9)
53 dat=self.__port.read(9)
54 test=( int(ord(dat[0])) + (int(ord(dat[1]))*256) )
54 test=( int(ord(dat[0])) + (int(ord(dat[1]))*256) )
55 temp=float(test)*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 test=( int(ord(dat[0])) + (int(ord(dat[1]))*256) )
64 val=float(test)/512.0
64 val=float(test)/512.0
65 return val
65 return val
66 raise UserWarning("Parameter out of bound")
66 raise UserWarning("Parameter out of bound")
67
67
68 def digit_in(self,index):
68 def digit_in(self,index):
69 if index < 3:
69 if index < 3:
70 self.__port.write(self.digitin.get(index))
70 self.__port.write(self.digitin.get(index))
71 dat=self.__port.read(1)
71 dat=self.__port.read(1)
72 return dat
72 return dat
73 raise UserWarning("Parameter out of bound")
73 raise UserWarning("Parameter out of bound")
74
74
75 def digit_out(self,index,val):
75 def digit_out(self,index,val):
76 if index < 3:
76 if index < 3:
77 if val:
77 if val:
78 self.__port.write(self.digithigh.get(index))
78 self.__port.write(self.digithigh.get(index))
79 else:
79 else:
80 self.__port.write(self.digitlow.get(index))
80 self.__port.write(self.digitlow.get(index))
81 raise UserWarning("Parameter out of bound")
81 raise UserWarning("Parameter out of bound")
82
82
83 @property
83 @property
84 def sensor1(self):
84 def sensor1(self):
85 return self.read_sensor(0)
85 return self.read_sensor(0)
86
86
87 @property
87 @property
88 def sensor2(self):
88 def sensor2(self):
89 return self.read_sensor(1)
89 return self.read_sensor(1)
90
90
91 @property
91 @property
92 def sensor3(self):
92 def sensor3(self):
93 return self.read_sensor(2)
93 return self.read_sensor(2)
94
94
95 @property
95 @property
96 def AN1(self):
96 def AN1(self):
97 return self.read_analog_in(0)
97 return self.read_analog_in(0)
98 @property
98 @property
99 def AN2(self):
99 def AN2(self):
100 return self.read_analog_in(1)
100 return self.read_analog_in(1)
101 @property
101 @property
102 def AN3(self):
102 def AN3(self):
103 return self.read_analog_in(2)
103 return self.read_analog_in(2)
104
104
105 @property
105 @property
106 def GP2(self):
106 def GP2(self):
107 return self.digit_in(0)
107 return self.digit_in(0)
108 @GP2.setter
108 @GP2.setter
109 def GP2(self,value):
109 def GP2(self,value):
110 return self.digit_out(0,val)
110 return self.digit_out(0,value)
111
111
112 @property
112 @property
113 def GP0(self):
113 def GP0(self):
114 return self.digit_in(1)
114 return self.digit_in(1)
115 @GP0.setter
115 @GP0.setter
116 def GP0(self,value):
116 def GP0(self,value):
117 return self.digit_out(1,val)
117 return self.digit_out(1,value)
118
118
119 @property
119 @property
120 def GP4(self):
120 def GP4(self):
121 return self.digit_in(2)
121 return self.digit_in(2)
122 @GP4.setter
122 @GP4.setter
123 def GP4(self,value):
123 def GP4(self,value):
124 return self.digit_out(2,val)
124 return self.digit_out(2,value)
125
125
126 if __name__ == '__main__':
126 if __name__ == '__main__':
127 print("")
127 print("")
@@ -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