@@ -0,0 +1,24 | |||||
|
1 | #!/usr/bin/env python | |||
|
2 | #-*- coding: utf-8 -*- | |||
|
3 | """Simple python library to communicate with Agilent 34410A over USB-TMC. | |||
|
4 | """ | |||
|
5 | import time | |||
|
6 | import sys | |||
|
7 | import os | |||
|
8 | import agilenttmc | |||
|
9 | ||||
|
10 | __author__ = "Alexis Jeandet" | |||
|
11 | __copyright__ = "Copyright 2015, Laboratory of Plasma Physics" | |||
|
12 | __credits__ = [] | |||
|
13 | __license__ = "GPLv2" | |||
|
14 | __version__ = "1.0.0" | |||
|
15 | __maintainer__ = "Alexis Jeandet" | |||
|
16 | __email__ = "alexis.jeandet@member.fsf.org" | |||
|
17 | __status__ = "Development" | |||
|
18 | ||||
|
19 | class Agilent3441xA(usbtmc.UsbTmc): | |||
|
20 | def __init__(self,ref,serial=""): | |||
|
21 | isnt=usbtmc.findInstrument(ref,serial) | |||
|
22 | if inst=="": | |||
|
23 | raise UserWarning("Can't find instrument "+ref) | |||
|
24 | self.UsbTmc.__init__(isnt) |
@@ -0,0 +1,26 | |||||
|
1 | #!/usr/bin/env python | |||
|
2 | #-*- coding: utf-8 -*- | |||
|
3 | """Simple python library to communicate with Agilent 34410A over USB-TMC. | |||
|
4 | """ | |||
|
5 | import time | |||
|
6 | import sys | |||
|
7 | import os | |||
|
8 | import agilenttmc | |||
|
9 | ||||
|
10 | __author__ = "Alexis Jeandet" | |||
|
11 | __copyright__ = "Copyright 2015, Laboratory of Plasma Physics" | |||
|
12 | __credits__ = [] | |||
|
13 | __license__ = "GPLv2" | |||
|
14 | __version__ = "1.0.0" | |||
|
15 | __maintainer__ = "Alexis Jeandet" | |||
|
16 | __email__ = "alexis.jeandet@member.fsf.org" | |||
|
17 | __status__ = "Development" | |||
|
18 | ||||
|
19 | "34410A" | |||
|
20 | ||||
|
21 | class Agilent3441xA(agilentusbtmc.AgilentUsbTmc): | |||
|
22 | def __init__(self,serial=""): | |||
|
23 | isnt=usbtmc.findInstrument("3441[0-1]A",serial) | |||
|
24 | if inst=="": | |||
|
25 | raise UserWarning("Can't find instrument "+ref) | |||
|
26 | self.UsbTmc.__init__(isnt) |
@@ -0,0 +1,24 | |||||
|
1 | #!/usr/bin/env python | |||
|
2 | #-*- coding: utf-8 -*- | |||
|
3 | """Common Agilent USB-TMC/SCPI traits. | |||
|
4 | """ | |||
|
5 | import time | |||
|
6 | import sys | |||
|
7 | import os | |||
|
8 | import usbtmc | |||
|
9 | ||||
|
10 | __author__ = "Alexis Jeandet" | |||
|
11 | __copyright__ = "Copyright 2015, Laboratory of Plasma Physics" | |||
|
12 | __credits__ = [] | |||
|
13 | __license__ = "GPLv2" | |||
|
14 | __version__ = "1.0.0" | |||
|
15 | __maintainer__ = "Alexis Jeandet" | |||
|
16 | __email__ = "alexis.jeandet@member.fsf.org" | |||
|
17 | __status__ = "Development" | |||
|
18 | ||||
|
19 | class AgilentUsbTmc(usbtmc.UsbTmc): | |||
|
20 | def __init__(self,ref,serial=""): | |||
|
21 | isnt=usbtmc.findInstrument(ref,serial) | |||
|
22 | if inst=="": | |||
|
23 | raise UserWarning("Can't find instrument "+ref) | |||
|
24 | self.UsbTmc.__init__(isnt) |
@@ -0,0 +1,55 | |||||
|
1 | #!/usr/bin/env python | |||
|
2 | #-*- coding: utf-8 -*- | |||
|
3 | """Simple python library to communicate over USB-TMC protocol with linux's | |||
|
4 | usbtmc module. | |||
|
5 | """ | |||
|
6 | import time | |||
|
7 | import sys | |||
|
8 | import os | |||
|
9 | import glob | |||
|
10 | import re | |||
|
11 | ||||
|
12 | __author__ = "Alexis Jeandet" | |||
|
13 | __copyright__ = "Copyright 2015, Laboratory of Plasma Physics" | |||
|
14 | __credits__ = [] | |||
|
15 | __license__ = "GPLv2" | |||
|
16 | __version__ = "1.0.0" | |||
|
17 | __maintainer__ = "Alexis Jeandet" | |||
|
18 | __email__ = "alexis.jeandet@member.fsf.org" | |||
|
19 | __status__ = "Development" | |||
|
20 | ||||
|
21 | ||||
|
22 | def find_instrument(ref,serial=""): | |||
|
23 | instruments=glob.glob("/dev/usbtmc[0-9]") | |||
|
24 | p = re.compile(ref) | |||
|
25 | for instrument in instruments: | |||
|
26 | dev=UsbTmc(instrument) | |||
|
27 | idn=dev.idn().split(",") | |||
|
28 | if p.match(idn[1]): | |||
|
29 | if serial=="" or serial == idn[2]: | |||
|
30 | return instrument | |||
|
31 | return "" | |||
|
32 | ||||
|
33 | class UsbTmc(): | |||
|
34 | def __init__(self,dev): | |||
|
35 | self.__PATH__=dev | |||
|
36 | self.__FILE__ = os.open(dev, os.O_RDWR) | |||
|
37 | if self.__FILE__==-1: | |||
|
38 | raise UserWarning("can't open "+dev) | |||
|
39 | self.Manufacturer="" | |||
|
40 | self.Reference="" | |||
|
41 | self.Serial="" | |||
|
42 | self.Version="" | |||
|
43 | ||||
|
44 | def write(self, command): | |||
|
45 | os.write(self.__FILE__, command); | |||
|
46 | ||||
|
47 | def read(self, length = 4000): | |||
|
48 | return os.read(self.__FILE__, length) | |||
|
49 | ||||
|
50 | def idn(self): | |||
|
51 | self.write("*IDN?") | |||
|
52 | return self.read(100) | |||
|
53 | ||||
|
54 | def __str__(self): | |||
|
55 | return self.idn() +"\n"+ self.__PATH__ |
@@ -7,4 +7,4 | |||||
7 | __version__ = "1.0.0" |
|
7 | __version__ = "1.0.0" | |
8 | __maintainer__ = "Alexis Jeandet" |
|
8 | __maintainer__ = "Alexis Jeandet" | |
9 | __email__ = "alexis.jeandet@member.fsf.org" |
|
9 | __email__ = "alexis.jeandet@member.fsf.org" | |
10 |
__status__ = " |
|
10 | __status__ = "Development" |
@@ -71,7 +71,7 closed=False | |||||
71 | opened=True |
|
71 | opened=True | |
72 |
|
72 | |||
73 |
|
73 | |||
74 |
class |
|
74 | class DiscoveryLimits(): | |
75 | class limitRange(): |
|
75 | class limitRange(): | |
76 | def __init__(self,Min,Max,name="Unknow",unit=""): |
|
76 | def __init__(self,Min,Max,name="Unknow",unit=""): | |
77 | self.Min = Min |
|
77 | self.Min = Min | |
@@ -88,8 +88,8 class discoveryLimits(): | |||||
88 | return self.Max |
|
88 | return self.Max | |
89 | return value |
|
89 | return value | |
90 |
|
90 | |||
91 |
def |
|
91 | def __str__(self): | |
92 |
|
|
92 | return self.name + ":\n Min="+str(self.Min)+" "+self.unit+",Max="+str(self.Max)+" "+self.unit | |
93 |
|
93 | |||
94 | errors = {0: RuntimeError("No card opened"), |
|
94 | errors = {0: RuntimeError("No card opened"), | |
95 | 1: UserWarning("Parameter out of bound"), |
|
95 | 1: UserWarning("Parameter out of bound"), | |
@@ -162,13 +162,15 byref(Mini), byref(Maxi)) | |||||
162 | def genBuffSize(self, value): |
|
162 | def genBuffSize(self, value): | |
163 | return self.GEN_BUFF.conform(value) |
|
163 | return self.GEN_BUFF.conform(value) | |
164 |
|
164 | |||
165 |
def |
|
165 | def __str__(self): | |
|
166 | res=str() | |||
166 | for i in self.limits: |
|
167 | for i in self.limits: | |
167 |
i. |
|
168 | res+=i.__str__()+"\n" | |
168 |
|
|
169 | res+="ACQ Input ranes: "+str(self.ACQ_IN_RANGES) | |
|
170 | return res | |||
169 |
|
171 | |||
170 |
|
172 | |||
171 |
class |
|
173 | class Discovery(): | |
172 |
|
174 | |||
173 | errors = {0: RuntimeError("No card opened"), |
|
175 | errors = {0: RuntimeError("No card opened"), | |
174 | 1: UserWarning("Parameter out of bound"), |
|
176 | 1: UserWarning("Parameter out of bound"), | |
@@ -189,8 +191,8 class discovery(): | |||||
189 | print(szerr.value) |
|
191 | print(szerr.value) | |
190 | print("failed to open device") |
|
192 | print("failed to open device") | |
191 | self.__opened=False |
|
193 | self.__opened=False | |
192 |
self.__limits= |
|
194 | self.__limits=DiscoveryLimits(self.__libdwf,self.__hdwf) | |
193 |
self.__limits |
|
195 | print(self.__limits) | |
194 |
|
196 | |||
195 | @property |
|
197 | @property | |
196 | def opened(self): |
|
198 | def opened(self): | |
@@ -200,7 +202,7 class discovery(): | |||||
200 | ############################################################# |
|
202 | ############################################################# | |
201 | # Power Supply |
|
203 | # Power Supply | |
202 | ############################################################# |
|
204 | ############################################################# | |
203 |
def set |
|
205 | def set_power(self,fiveVolt=1,minusFiveVolt=1,master=True): | |
204 | if not self.__opened: |
|
206 | if not self.__opened: | |
205 | raise self.errors.get(0) |
|
207 | raise self.errors.get(0) | |
206 | # enable positive supply |
|
208 | # enable positive supply | |
@@ -210,7 +212,7 class discovery(): | |||||
210 | # master enable |
|
212 | # master enable | |
211 | return self.__libdwf.FDwfAnalogIOEnableSet(self.__hdwf, master) |
|
213 | return self.__libdwf.FDwfAnalogIOEnableSet(self.__hdwf, master) | |
212 |
|
214 | |||
213 |
def get |
|
215 | def get_power(self): | |
214 | if not self.__opened: |
|
216 | if not self.__opened: | |
215 | raise self.errors.get(0) |
|
217 | raise self.errors.get(0) | |
216 | supplyVoltage = c_double() |
|
218 | supplyVoltage = c_double() | |
@@ -225,7 +227,7 class discovery(): | |||||
225 | ############################################################# |
|
227 | ############################################################# | |
226 | # AnalogIn |
|
228 | # AnalogIn | |
227 | ############################################################# |
|
229 | ############################################################# | |
228 |
def analog |
|
230 | def analog_in_read(self,ch1=True,ch2=True,frequency=100000000,samplesCount=100,ch1range=5.0,ch2range=5.0,trigger=trigsrcNone): | |
229 | if not self.__opened: |
|
231 | if not self.__opened: | |
230 | raise self.errors.get(0) |
|
232 | raise self.errors.get(0) | |
231 | cnt=self.__limits.acqBufSize(samplesCount) |
|
233 | cnt=self.__limits.acqBufSize(samplesCount) | |
@@ -238,7 +240,7 class discovery(): | |||||
238 | self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(0), c_double(ch1range)) |
|
240 | self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(0), c_double(ch1range)) | |
239 | self.__libdwf.FDwfAnalogInChannelEnableSet(self.__hdwf, c_int(1), c_bool(ch2)) |
|
241 | self.__libdwf.FDwfAnalogInChannelEnableSet(self.__hdwf, c_int(1), c_bool(ch2)) | |
240 | self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(1), c_double(ch2range)) |
|
242 | self.__libdwf.FDwfAnalogInChannelRangeSet(self.__hdwf, c_int(1), c_double(ch2range)) | |
241 |
self.set |
|
243 | self.set_analog_in_trigger(trigger) | |
242 | self.__libdwf.FDwfAnalogInConfigure(self.__hdwf, c_bool(False), c_bool(True)) |
|
244 | self.__libdwf.FDwfAnalogInConfigure(self.__hdwf, c_bool(False), c_bool(True)) | |
243 | status = c_byte() |
|
245 | status = c_byte() | |
244 | while True: |
|
246 | while True: | |
@@ -261,7 +263,7 class discovery(): | |||||
261 | return [np.array([ch2data]),frequency] |
|
263 | return [np.array([ch2data]),frequency] | |
262 |
|
264 | |||
263 |
|
265 | |||
264 |
def set |
|
266 | def set_analog_in_trigger(self,trigger=trigAuto,autoTimeout=0.0): | |
265 | if not self.__opened: |
|
267 | if not self.__opened: | |
266 | raise self.errors.get(0) |
|
268 | raise self.errors.get(0) | |
267 | if trigger == trigAuto: |
|
269 | if trigger == trigAuto: | |
@@ -277,7 +279,7 class discovery(): | |||||
277 | ############################################################# |
|
279 | ############################################################# | |
278 | # AnalogOut |
|
280 | # AnalogOut | |
279 | ############################################################# |
|
281 | ############################################################# | |
280 |
def analog |
|
282 | def analog_out_gen(self,frequency=1000, shape='Sine', channel=0, amplitude=1.0, offset=0.0): | |
281 | self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False)) |
|
283 | self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False)) | |
282 | self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True)) |
|
284 | self.__libdwf.FDwfAnalogOutNodeEnableSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_bool(True)) | |
283 | self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get(shape))) |
|
285 | self.__libdwf.FDwfAnalogOutNodeFunctionSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_int(shapes.get(shape))) | |
@@ -286,7 +288,7 class discovery(): | |||||
286 | self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genOffset(offset))) |
|
288 | self.__libdwf.FDwfAnalogOutNodeOffsetSet(self.__hdwf, c_int(channel), AnalogOutNodeCarrier, c_double(self.__limits.genOffset(offset))) | |
287 | self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True)) |
|
289 | self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(True)) | |
288 |
|
290 | |||
289 |
def analog |
|
291 | def analog_out_gen_arbit(self,samplesBuffer ,repeatingFrequency=100, channel=0, amplitude=1.0, offset=0.0): | |
290 | self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False)) |
|
292 | self.__libdwf.FDwfAnalogOutConfigure(self.__hdwf, c_int(channel), c_bool(False)) | |
291 | cnt=self.__limits.genBuffSize(len(samplesBuffer)) |
|
293 | cnt=self.__limits.genBuffSize(len(samplesBuffer)) | |
292 | buf=(c_double*cnt)() |
|
294 | buf=(c_double*cnt)() | |
@@ -310,13 +312,13 class discovery(): | |||||
310 |
|
312 | |||
311 | if __name__ == '__main__': |
|
313 | if __name__ == '__main__': | |
312 | print("open first dev") |
|
314 | print("open first dev") | |
313 |
test = |
|
315 | test = Discovery() | |
314 |
test.set |
|
316 | test.set_power() | |
315 | for i in range(2): |
|
317 | for i in range(2): | |
316 | time.sleep(0.2) |
|
318 | time.sleep(0.2) | |
317 |
print(test.get |
|
319 | print(test.get_power()) | |
318 |
test.analog |
|
320 | test.analog_out_gen() | |
319 |
res=test.analog |
|
321 | res=test.analog_in_read(frequency=1000000,samplesCount=1000) | |
320 | print(res) |
|
322 | print(res) | |
321 | plt.plot(range(len(res[0][0])),res[0][0]) |
|
323 | plt.plot(range(len(res[0][0])),res[0][0]) | |
322 | plt.plot(range(len(res[0][0])),res[0][1]) |
|
324 | plt.plot(range(len(res[0][0])),res[0][1]) |
@@ -1,19 +1,7 | |||||
|
1 | #!/usr/bin/env python | |||
1 | #-*- coding: utf-8 -*- |
|
2 | #-*- coding: utf-8 -*- | |
2 | #Copyright 2015 Alexis Jeandet |
|
3 | """Simple python library to communicate with GW Instek GPD-Series power supplies. | |
3 | #This file is part of lppinstru. |
|
4 | """ | |
4 |
|
||||
5 | #lppinstru is free software: you can redistribute it and/or modify |
|
|||
6 | #it under the terms of the GNU General Public License as published by |
|
|||
7 | #the Free Software Foundation, either version 3 of the License, or |
|
|||
8 | #(at your option) any later version. |
|
|||
9 |
|
||||
10 | #pydiscovery is distributed in the hope that it will be useful, |
|
|||
11 | #but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|||
12 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|||
13 | #GNU General Public License for more details. |
|
|||
14 |
|
||||
15 | #You should have received a copy of the GNU General Public License |
|
|||
16 | #along with pydiscovery. If not, see <http://www.gnu.org/licenses/>. |
|
|||
17 | import time |
|
5 | import time | |
18 | import sys |
|
6 | import sys | |
19 | import os |
|
7 | import os | |
@@ -21,6 +9,16 import matplotlib.pyplot as plt | |||||
21 | import numpy as np |
|
9 | import numpy as np | |
22 | import serial |
|
10 | import serial | |
23 |
|
11 | |||
|
12 | __author__ = "Alexis Jeandet" | |||
|
13 | __copyright__ = "Copyright 2015, Laboratory of Plasma Physics" | |||
|
14 | __credits__ = [] | |||
|
15 | __license__ = "GPLv2" | |||
|
16 | __version__ = "1.0.0" | |||
|
17 | __maintainer__ = "Alexis Jeandet" | |||
|
18 | __email__ = "alexis.jeandet@member.fsf.org" | |||
|
19 | __status__ = "Development" | |||
|
20 | ||||
|
21 | ||||
24 | class gpd_xxx(): |
|
22 | class gpd_xxx(): | |
25 | conf = {"GPD-3303S" : (2,0.0,30.0), |
|
23 | conf = {"GPD-3303S" : (2,0.0,30.0), | |
26 | "GPD-3303" : (), |
|
24 | "GPD-3303" : (), |
@@ -16,7 +16,7 from scipy import fftpack | |||||
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__ = " |
|
19 | __status__ = "Development" | |
20 |
|
20 | |||
21 |
|
21 | |||
22 |
|
22 | |||
@@ -33,7 +33,7 def __parseFFT(FFTi,FFTo,signalFreq,samp | |||||
33 | return [signalFreq,mod,arg] |
|
33 | return [signalFreq,mod,arg] | |
34 |
|
34 | |||
35 | def __step(device,freq,offset=0.0,maxAmp=5.0,lastAmp=1.0): |
|
35 | def __step(device,freq,offset=0.0,maxAmp=5.0,lastAmp=1.0): | |
36 |
device.analog |
|
36 | device.analog_out_gen(freq, shape='Sine', channel=0, amplitude=lastAmp, offset=offset) | |
37 | samplesCount=8192 |
|
37 | samplesCount=8192 | |
38 | if freq > 500000: |
|
38 | if freq > 500000: | |
39 | FS=freq*samplesCount/500.0 |
|
39 | FS=freq*samplesCount/500.0 | |
@@ -41,7 +41,7 def __step(device,freq,offset=0.0,maxAmp | |||||
41 | FS=freq*samplesCount/50.0 |
|
41 | FS=freq*samplesCount/50.0 | |
42 | else: |
|
42 | else: | |
43 | FS=freq*samplesCount/10.0 |
|
43 | FS=freq*samplesCount/10.0 | |
44 |
res=device.analog |
|
44 | res=device.analog_in_read(ch1=True,ch2=True,frequency=FS,samplesCount=samplesCount,ch1range=5.0,ch2range=5.0) | |
45 | FFTi=fftpack.fft(res[0][0]) |
|
45 | FFTi=fftpack.fft(res[0][0]) | |
46 | FFTo=fftpack.fft(res[0][1]) |
|
46 | FFTo=fftpack.fft(res[0][1]) | |
47 | return __parseFFT(FFTi,FFTo,freq,res[1]) |
|
47 | return __parseFFT(FFTi,FFTo,freq,res[1]) |
General Comments 0
You need to be logged in to leave comments.
Login now