Source code for cmd_ag_33500

#!/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 time
import pools,conf_strings,scpi

ag_33500_pool=pools.pool()

# Functions

class ag_33500_class(scpi.scpi):
    channels=["1","2"]

    def __init__(self):
        super(ag_33500_class,self).__init__("ag_33500")

    def set_function(self,ag_33500_id,function):
        if function not in ["sine","square","ramp","pulse"]:
            return 0,"invalid function"
        value={"sine":"SIN","square":"SQU","ramp":"RAMP","pulse":"PULS"}.get(function)
        command="SOUR{channel}:FUNC %s"%(value)
        return self.simple_command(ag_33500_id,command)

    def set_frequency(self,ag_33500_id,frequency):
        if frequency=="undef":
            return 1,"ok"
        command="SOUR{channel}:FREQ %.6f"%(float(frequency))
        return self.simple_command(ag_33500_id,command)

    def get_frequency(self,ag_33500_id):
        command="SOUR{channel}:FREQ?"
        return self.simple_query(ag_33500_id,command)

    def set_high_level(self,ag_33500_id,high_level):
        if high_level=="undef":
            return 1,"ok"
        command="SOUR{channel}:VOLT:HIGH %.4f"%(float(high_level))
        return self.simple_command(ag_33500_id,command)

    def set_low_level(self,ag_33500_id,low_level):
        if low_level=="undef":
            return 1,"ok"
        command="SOUR{channel}:VOLT:LOW %.4f"%(float(low_level))
        return self.simple_command(ag_33500_id,command)

    def set_duty_cycle(self,ag_33500_id,duty_cycle):
        if duty_cycle=="undef":
            return 1,"ok"
        command="SOUR{channel}:FUNC:SQU:DCYC %.4f"%(float(duty_cycle))
        return self.simple_command(ag_33500_id,command)

    def set_pulse_width(self,ag_33500_id,pulse_width):
        if pulse_width=="undef":
            return 1,"ok"
        command="SOUR{channel}:FUNC:PULS:WIDT %.9f"%(float(pulse_width))
        return self.simple_command(ag_33500_id,command)

    def set_edges(self,ag_33500_id,rising_edge,falling_edge):
        # Verify edges
        if rising_edge.lower() not in ["min","max","undef"]:
            value_r="%.9f"%(float(rising_edge))
        else:
            value_r=rising_edge
        if falling_edge.lower() not in ["min","max","undef"]:
            value_f="%.9f"%(float(falling_edge))
        else:
            value_f=falling_edge
        # Send the command
        command=""
        if value_r!="undef":
            command+="SOUR{channel}:FUNC:PULS:TRAN:LEAD %s"%(value_r)
        if "undef" not in [value_r,value_f]:
            command+=r"\n"
        if value_f!="undef":
            command+="SOUR{channel}:FUNC:PULS:TRAN:TRA %s"%(value_f)
        return self.simple_command(ag_33500_id,command)

    def set_symmetry(self,ag_33500_id,symmetry):
        if symmetry=="undef":
            return 1,"ok"
        command="SOUR{channel}:FUNC:RAMP:SYMM %.4f"%(float(symmetry))
        return self.simple_command(ag_33500_id,command)

    def set_phase(self,ag_33500_id,phase):
        if phase=="undef":
            return 1,"ok"
        command="SOUR{channel}:PHAS %.3f"%(float(phase))
        return self.simple_command(ag_33500_id,command)

    def set_delay(self,ag_33500_id,delay):
        if delay=="undef":
            return 1,"ok"
        # if in burst mode, set delay
        # otherwise set phase
        # both take seconds
        command="SOUR{channel}:BURS:STAT?"
        retcode,res=self.simple_query(ag_33500_id,command)
        if retcode==0:
            return 0,"error getting usage of BURST: %s"%(res)
        if res=="1":
            # burst mode
            command="TRIG{channel}:DEL %s"%(delay)
        else:
            # not burst mode
            command="SOUR{channel}:PHAS %s"%(delay)
        return self.simple_command(ag_33500_id,command)

    def set_sync(self,ag_33500_id,sync):
        if sync=="undef":
            return 1,"ok"
        command=r"OUTP:SYNC:SOURCE CH{channel}\n"
        command+="OUTP:SYNC "
        command+="ON" if sync=="1" else "OFF"
        return self.simple_command(ag_33500_id,command)

    def power_on(self,ag_33500_id):
        command="OUTP{channel} ON"
        return self.simple_command(ag_33500_id,command)

    def power_off(self,ag_33500_id):
        command="OUTP{channel} OFF"
        return self.simple_command(ag_33500_id,command)

me=ag_33500_class()

[docs]def init_ag_33500(ag_33500_id,conf_string): """Initialize ag_33500 pattern generator. *conf_string*: must include: - channel: channel on which the ag_33500_id will act - bus: conf_string of the underlying link module (gpib, tcp, serial, ...)""" return me.init(ag_33500_id,conf_string)
[docs]def deinit_ag_33500(ag_33500_id): "Deregister an ag_33500 from the pool" return me.deinit(ag_33500_id)
[docs]def config_ag_33500(ag_33500_id): "Configure an ag_33500" return me.config(ag_33500_id)
[docs]def inval_ag_33500(ag_33500_id): "Invalidate configuration of an ag_33500" return me.inval(ag_33500_id)
[docs]def reset_ag_33500(ag_33500_id): "Send RST signal to PG" return me.reset(ag_33500_id)
def configure_base(ag_33500_id,frequency,sync,high_level,low_level): retcode,res=me.set_frequency(ag_33500_id,frequency) if retcode==0: return 0,res retcode,res=me.set_sync(ag_33500_id,sync) if retcode==0: return 0,res retcode,res=me.set_high_level(ag_33500_id,high_level) if retcode==0: return 0,res retcode,res=me.set_low_level(ag_33500_id,low_level) if retcode==0: return 0,res return 1,"ok"
[docs]def configure_sine_ag_33500(ag_33500_id,frequency,sync,high_level,low_level,phase): "Configure ag_33500 to a sine wave with the specified parameters" retcode,res=me.set_function(ag_33500_id,"sine") if retcode==0: return 0,res retcode,res=configure_base(ag_33500_id,frequency,sync,high_level,low_level) if retcode==0: return 0,res retcode,res=me.set_phase(ag_33500_id,phase) if retcode==0: return 0,res return 1,"ok"
[docs]def configure_square_ag_33500(ag_33500_id,frequency,sync,high_level,low_level,phase,duty_cycle): "Configure ag_33500 to a square wave with the specified parameters" retcode,res=me.set_function(ag_33500_id,"square") if retcode==0: return 0,res retcode,res=configure_base(ag_33500_id,frequency,sync,high_level,low_level) if retcode==0: return 0,res retcode,res=me.set_phase(ag_33500_id,phase) if retcode==0: return 0,res retcode,res=me.set_duty_cycle(ag_33500_id,duty_cycle) if retcode==0: return 0,res return 1,"ok"
[docs]def configure_ramp_ag_33500(ag_33500_id,frequency,sync,high_level,low_level,phase,symmetry): "Configure ag_33500 to a ramp wave with the specified parameters" retcode,res=me.set_function(ag_33500_id,"ramp") if retcode==0: return 0,res retcode,res=configure_base(ag_33500_id,frequency,sync,high_level,low_level) if retcode==0: return 0,res retcode,res=me.set_phase(ag_33500_id,phase) if retcode==0: return 0,res retcode,res=me.set_symmetry(ag_33500_id,symmetry) if retcode==0: return 0,res return 1,"ok"
[docs]def configure_pulse_ag_33500(ag_33500_id,frequency,sync,high_level,low_level,delay,pulse_width,rising_edge,falling_edge): "Configure ag_33500 to a pulse train with the specified parameters" retcode,res=me.set_function(ag_33500_id,"pulse") if retcode==0: return 0,res retcode,res=configure_base(ag_33500_id,frequency,sync,high_level,low_level) if retcode==0: return 0,res retcode,res=me.set_delay(ag_33500_id,delay) if retcode==0: return 0,res retcode,res=me.set_pulse_width(ag_33500_id,pulse_width) if retcode==0: return 0,res retcode,res=me.set_edges(ag_33500_id,rising_edge,falling_edge) if retcode==0: return 0,res return 1,"ok"
[docs]def power_on_ag_33500(ag_33500_id): "Turn on" return me.power_on(ag_33500_id)
[docs]def power_off_ag_33500(ag_33500_id): "Turn off" return me.power_off(ag_33500_id)