#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Copyright 2012-2017 Frédéric Magniette, Miguel Rubio-Roy
# This file is part of Pyrame.
#
# Pyrame is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrame is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrame. If not, see <http://www.gnu.org/licenses/>
import scpi
# CLASS ##########################################################
class ag_34401a_class(scpi.scpi):
# Available channels
channels=["1"] # one channel
Vranges=[0.1,1,10,100,1000]
Iranges=[10e-3,100e-3,1,3]
Rranges=[100,1e3,10e3,100e3,1e6,10e6,100e6]
def __init__(self):
super(ag_34401a_class,self).__init__("ag_34401a")
def check_range(self,range,ranges):
retcode,res=super(ag_34401a_class,self).check_range(range,ranges)
if retcode==0:
return 0,res
if retcode==1:
return 1,":AUTO ON"
if retcode==2:
return 1," "+res
def get_dc_voltage(self,ag_34401a_id,range="undef",resolution="undef"):
conf_cmd="CONF:VOLT:DC"
#range
if range!="undef":
retcode,res=self.check_range(range,self.Vranges)
if retcode==0:
return 0,res
range=res
conf_cmd+=r"\nVOLT:DC:RANG{range}"
#resolution
if resolution!="undef":
retcode,res=self.check_resolution(resolution,"plc")
if retcode==0:
return 0,res
resolution=res
if retcode==2:
conf_cmd+=r"\nVOLT:DC:NPLC {resolution}"
if retcode==3:
conf_cmd+=r"\nVOLT:DC:RES {resolution}"
measure_query="READ?"
return self.measure(ag_34401a_id,range,resolution,conf_cmd,measure_query)
def get_ac_voltage(self,ag_34401a_id,range="undef",resolution="undef"):
conf_cmd="CONF:VOLT:AC"
#range
if range!="undef":
retcode,res=self.check_range(range,self.Vranges)
if retcode==0:
return 0,res
range=res
conf_cmd+=r"\nVOLT:AC:RANG{range}"
#resolution
if resolution!="undef":
retcode,res=self.check_resolution(resolution,"plc")
if retcode==0:
return 0,res
resolution=res
if retcode==2:
conf_cmd+=r"\nVOLT:AC:NPLC {resolution}"
if retcode==3:
conf_cmd+=r"\nVOLT:AC:RES {resolution}"
measure_query="READ?"
return self.measure(ag_34401a_id,range,resolution,conf_cmd,measure_query)
def get_dc_current(self,ag_34401a_id,range="undef",resolution="undef"):
conf_cmd="CONF:CURR:DC"
#range
if range!="undef":
retcode,res=self.check_range(range,self.Iranges)
if retcode==0:
return 0,res
range=res
conf_cmd+=r"\nCURR:DC:RANG{range}"
#resolution
if resolution!="undef":
retcode,res=self.check_resolution(resolution,"plc")
if retcode==0:
return 0,res
resolution=res
if retcode==2:
conf_cmd+=r"\nCURR:DC:NPLC {resolution}"
if retcode==3:
conf_cmd+=r"\nCURR:DC:RES {resolution}"
measure_query="READ?"
return self.measure(ag_34401a_id,range,resolution,conf_cmd,measure_query)
def get_ac_current(self,ag_34401a_id,range="undef",resolution="undef"):
conf_cmd="CONF:CURR:AC"
#range
if range!="undef":
retcode,res=self.check_range(range,self.Iranges)
if retcode==0:
return 0,res
range=res
conf_cmd+=r"\nCURR:AC:RANG{range}"
#resolution
if resolution!="undef":
retcode,res=self.check_resolution(resolution,"plc")
if retcode==0:
return 0,res
resolution=res
if retcode==2:
conf_cmd+=r"\nCURR:AC:NPLC {resolution}"
if retcode==3:
conf_cmd+=r"\nCURR:AC:RES {resolution}"
measure_query="READ?"
return self.measure(ag_34401a_id,range,resolution,conf_cmd,measure_query)
def get_2w_resistance(self,ag_34401a_id,range="undef",resolution="undef"):
conf_cmd="CONF:RES"
#range
if range!="undef":
retcode,res=self.check_range(range,self.Rranges)
if retcode==0:
return 0,res
range=res
conf_cmd+=r"\nRES:RANG{range}"
#resolution
if resolution!="undef":
retcode,res=self.check_resolution(resolution,"plc")
if retcode==0:
return 0,res
resolution=res
if retcode==2:
conf_cmd+=r"\nRES:NPLC {resolution}"
if retcode==3:
conf_cmd+=r"\nRES:RES {resolution}"
measure_query="READ?"
return self.measure(ag_34401a_id,range,resolution,conf_cmd,measure_query)
def get_4w_resistance(self,ag_34401a_id,range="undef",resolution="undef"):
conf_cmd="CONF:FRES"
#range
if range!="undef":
retcode,res=self.check_range(range,self.Rranges)
if retcode==0:
return 0,res
range=res
conf_cmd+=r"\nFRES:RANG{range}"
#resolution
if resolution!="undef":
retcode,res=self.check_resolution(resolution,"plc")
if retcode==0:
return 0,res
resolution=res
if retcode==2:
conf_cmd+=r"\nFRES:NPLC {resolution}"
if retcode==3:
conf_cmd+=r"\nFRES:RES {resolution}"
measure_query="READ?"
return self.measure(ag_34401a_id,range,resolution,conf_cmd,measure_query)
def get_frequency(self,ag_34401a_id,resolution="undef"):
conf_cmd="CONF:FREQ"
#resolution
if resolution!="undef":
retcode,res=self.check_resolution(resolution,"s")
if retcode==0:
return 0,res
resolution=res
if retcode==2:
conf_cmd+=r"\nFREQ:APER {resolution}"
if retcode==3:
conf_cmd+=r"\nFREQ:RES {resolution}"
measure_query="READ?"
return self.measure(ag_34401a_id,"undef",resolution,conf_cmd,measure_query)
def get_period(self,ag_34401a_id,resolution="undef"):
conf_cmd="CONF:PER"
#resolution
if resolution!="undef":
retcode,res=self.check_resolution(resolution,"s")
if retcode==0:
return 0,res
resolution=res
if retcode==2:
conf_cmd+=r"\nPER:APER {resolution}"
if retcode==3:
conf_cmd+=r"\nPER:RES {resolution}"
measure_query="READ?"
return self.measure(ag_34401a_id,"undef",resolution,conf_cmd,measure_query)
# CREATE POOL ####################################################
me=ag_34401a_class()
# COMMANDS #######################################################
[docs]def init_ag_34401a(ag_34401a_id,conf_string):
"""Initialize ag_34401a power supply identified by *ag_34401_id*
*conf_string* must include the parameter:
- bus: conf_string of the underlying link module (GPIB, TCP, ...)
- channel: channel on which the id will act"""
return me.init(ag_34401a_id,conf_string)
[docs]def deinit_ag_34401a(ag_34401a_id):
"Deinitialize an ag_34401a"
return me.deinit(ag_34401a_id)
[docs]def config_ag_34401a(ag_34401a_id):
"Configure an ag_34401a"
return me.config(ag_34401a_id)
[docs]def inval_ag_34401a(ag_34401a_id):
"Invalidate an ag_34401a"
return me.inval(ag_34401a_id)
[docs]def reset_ag_34401a(ag_34401a_id):
"Send RST signal to PS"
return me.reset(ag_34401a_id)
[docs]def get_dc_voltage_ag_34401a(ag_34401a_id,range="undef",resolution="undef"):
"""Get DC voltage in Volts.
The optional *range* can be: auto, 0.1, 1, 10, 100 or 1000 Volts. When *range* is undef or absent, it fallbacks to autorange.
The optional *resolution* can be expressed either as a tolerance in Volts (e.g. 0.01), or by the number of power-line cycles that will be used to integrate, followed by PLC (e.g. 10PLC). The following values are accepted: 0.02, 0.2, 1, 10, 100. When *resolution* is undef or absent, the default value of the instrument (10PLC) is used.
MIN or MAX can be used for both parameters (for resolution, MAX means the highest resolution)."""
return me.get_dc_voltage(ag_34401a_id,range,resolution)
[docs]def get_ac_voltage_ag_34401a(ag_34401a_id,range="undef",resolution="undef"):
"""Get AC voltage in Volts.
The optional *range* can be: auto, 0.1, 1, 10, 100 or 1000 Volts. When *range* is undef or absent, it fallbacks to autorange.
The optional *resolution* can be expressed either as a tolerance in Volts (e.g. 0.01), or by the number of power-line cycles that will be used to integrate, followed by PLC (e.g. 10PLC). The following values are accepted: 0.02, 0.2, 1, 10, 100. When *resolution* is undef or absent, the default value of the instrument (10PLC) is used.
MIN or MAX can be used for both parameters (for resolution, MAX means the highest resolution)."""
return me.get_ac_voltage(ag_34401a_id,range,resolution)
[docs]def get_dc_current_ag_34401a(ag_34401a_id,range="undef",resolution="undef"):
"""Get DC current in Ampers.
The optional *range* can be: auto, 0.01, 0.1, 1, 3 Ampers. When *range* is undef or absent, it fallbacks to autorange.
The optional *resolution* can be expressed either as a tolerance in Ampers (e.g. 0.01), or by the number of power-line cycles that will be used to integrate, followed by PLC (e.g. 10PLC). The following values are accepted: 0.02, 0.2, 1, 10, 100. When *resolution* is undef or absent, the default value of the instrument (10PLC) is used.
MIN or MAX can be used for both parameters (for resolution, MAX means the highest resolution)."""
return me.get_dc_current(ag_34401a_id,range,resolution)
[docs]def get_ac_current_ag_34401a(ag_34401a_id,range="undef",resolution="undef"):
"""Get AC current in Ampers.
The optional *range* can be: auto, 0.01, 0.1, 1, 3 Ampers. When *range* is undef or absent, it fallbacks to autorange.
The optional *resolution* can be expressed either as a tolerance in Ampers (e.g. 0.01), or by the number of power-line cycles that will be used to integrate, followed by PLC (e.g. 10PLC). The following values are accepted: 0.02, 0.2, 1, 10, 100. When *resolution* is undef or absent, the default value of the instrument (10PLC) is used.
MIN or MAX can be used for both parameters (for resolution, MAX means the highest resolution)."""
return me.get_ac_current(ag_34401a_id,range,resolution)
[docs]def get_2w_resistance_ag_34401a(ag_34401a_id,range="undef",resolution="undef"):
"""Get 2-wire resistance in Ohms.
The optional *range* can be: auto, 100, 1e3, 10e3, 100e3, 1e6, 10e6 or 100e6 Ohms. When *range* is undef or absent, it fallbacks to autorange.
The optional *resolution* can be expressed either as a tolerance in Ohms (e.g. 0.01), or by the number of power-line cycles that will be used to integrate, followed by PLC (e.g. 10PLC). The following values are accepted: 0.02, 0.2, 1, 10, 100. When *resolution* is undef or absent, the default value of the instrument (10PLC) is used.
MIN or MAX can be used for both parameters (for resolution, MAX means the highest resolution)."""
return me.get_2w_resistance(ag_34401a_id,range,resolution)
[docs]def get_4w_resistance_ag_34401a(ag_34401a_id,range="undef",resolution="undef"):
"""Get 4-wire resistance in Ohms.
The optional *range* can be: auto, 100, 1e3, 10e3, 100e3, 1e6, 10e6 or 100e6 Ohms. When *range* is undef or absent, it fallbacks to autorange.
The optional *resolution* can be expressed either as a tolerance in Ohms (e.g. 0.01), or by the number of power-line cycles that will be used to integrate, followed by PLC (e.g. 10PLC). The following values are accepted: 0.02, 0.2, 1, 10, 100. When *resolution* is undef or absent, the default value of the instrument (10PLC) is used.
MIN or MAX can be used for both parameters (for resolution, MAX means the highest resolution)."""
return me.get_4w_resistance(ag_34401a_id,range,resolution)
[docs]def get_frequency_ag_34401a(ag_34401a_id,resolution="undef"):
"""Get frequency in Hertzs.
The optional *resolution* can be expressed either as a tolerance in Hertzs (e.g. 0.01), or by the time aperture that will be used to integrate, followed by s (e.g. 0.1s for 100 milliseconds). The following values are accepted: 0.01, 0.1, 1. When *resolution* is undef or absent, the default value of the instrument (10PLC) is used.
MIN or MAX can be used for both parameters (for resolution, MAX means the highest resolution)."""
return me.get_frequency(ag_34401a_id,resolution)
[docs]def get_period_ag_34401a(ag_34401a_id,resolution="undef"):
"""Get frequency in seconds.
The optional *resolution* can be expressed either as a tolerance in seconds (e.g. 0.01), or by the time aperture that will be used to integrate, followed by s (e.g. 0.1s for 100 milliseconds). The following values are accepted: 0.01, 0.1, 1. When *resolution* is undef or absent, the default value of the instrument (10PLC) is used.
MIN or MAX can be used for both parameters (for resolution, MAX means the highest resolution)."""
return me.get_period(ag_34401a_id,resolution)
[docs]def free_command_ag_34401a(ag_34401a_id,command):
"Send a raw command to the PS"
return me.free_command(ag_34401a_id,command)
[docs]def get_error_queue_ag_34401a(ag_34401a_id):
"Read error queue until the end (code 0)"
return me.get_error_queue(ag_34401a_id)