Source code for cmd_ag_33200

#!/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_33200_pool=pools.pool()

# Functions

class ag_33200_class(scpi.scpi):
    channels=["1"]

    def __init__(self):
        super(ag_33200_class,self).__init__("ag_33200")

    def set_function(self,ag_33200_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="FUNC %s"%(value)
        return self.simple_command(ag_33200_id,command)

    def set_frequency(self,ag_33200_id,frequency):
        if frequency=="undef":
            return 1,"ok"
        command="FREQ %.6f"%(float(frequency))
        return self.simple_command(ag_33200_id,command)

    def get_frequency(self,ag_33200_id):
        command="FREQ?"
        return self.simple_query(ag_33200_id,command)

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

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

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

    def set_pulse_width(self,ag_33200_id,pulse_width):
        if pulse_width=="undef":
            return 1,"ok"
        command="PULS:WIDT %.9f"%(float(pulse_width))
        return self.simple_command(ag_33200_id,command)

    def set_edges(self,ag_33200_id,rising_edge,falling_edge):
        # Verify edges
        if rising_edge.lower()!=falling_edge.lower():
            return 0,"Error, rising and falling edges must be equal"
        if rising_edge.lower() not in ["min","max","undef"]:
            value="%.9f"%(float(rising_edge))
        else:
            value=rising_edge
        if value=="undef":
            return 1,"ok"
        # Send the command
        command="PULS:TRAN %s\n"%(value)
        return self.simple_command(ag_33200_id,command)

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

    def set_phase(self,ag_33200_id,phase):
        if phase=="undef":
            return 1,"ok"
        command="PHAS %.3f"%(float(phase))
        return self.simple_command(ag_33200_id,command)

    def set_delay(self,ag_33200_id,delay):
        if delay=="undef":
            return 1,"ok"
        phase=0
        if float(delay)!=0:
            command="FREQ?"
            retcode,res=self.simple_query(ag_33500_id,command)
            if retcode==0:
                return 0,"error getting frequency: %s"%(res)
            freq=float(res)
            phase=360*float(delay)*freq
        command="PHAS %.3f"%(phase)
        return self.simple_command(ag_33500_id,command)

    def set_sync(self,ag_33200_id,sync):
        if sync=="undef":
            return 1,"ok"
        command="OUTP:SYNC "
        command+="ON" if sync=="1" else "OFF"
        return self.simple_command(ag_33200_id,command)

    def power_on(self,ag_33200_id):
        command="OUTP ON"
        return self.simple_command(ag_33200_id,command)

    def power_off(self,ag_33200_id):
        command="OUTP OFF"
        return self.simple_command(ag_33200_id,command)

me=ag_33200_class()

[docs]def init_ag_33200(ag_33200_id,conf_string): """Initialize ag_33200 pattern generator. *conf_string*: must include: - channel: channel on which the ag_33200_id will act - bus: conf_string of the underlying link module (gpib, tcp, serial, ...)""" return me.init(ag_33200_id,conf_string)
[docs]def deinit_ag_33200(ag_33200_id): "Deregister an ag_33200 from the pool" return me.deinit(ag_33200_id)
[docs]def config_ag_33200(ag_33200_id): "Configure an ag_33200" return me.config(ag_33200_id)
[docs]def inval_ag_33200(ag_33200_id): "Invalidate configuration of an ag_33200" return me.inval(ag_33200_id)
[docs]def reset_ag_33200(ag_33200_id): "Send RST signal to PG" return me.reset(ag_33200_id)
def configure_base(ag_33200_id,frequency,sync,high_level,low_level): retcode,res=me.set_frequency(ag_33200_id,frequency) if retcode==0: return 0,res retcode,res=me.set_sync(ag_33200_id,sync) if retcode==0: return 0,res retcode,res=me.set_high_level(ag_33200_id,high_level) if retcode==0: return 0,res retcode,res=me.set_low_level(ag_33200_id,low_level) if retcode==0: return 0,res return 1,"ok"
[docs]def configure_sine_ag_33200(ag_33200_id,frequency,sync,high_level,low_level,phase): "Configure ag_33200 to a sine wave with the specified parameters" retcode,res=me.set_function(ag_33200_id,"sine") if retcode==0: return 0,res retcode,res=configure_base(ag_33200_id,frequency,sync,high_level,low_level) if retcode==0: return 0,res retcode,res=me.set_phase(ag_33200_id,phase) if retcode==0: return 0,res return 1,"ok"
[docs]def configure_square_ag_33200(ag_33200_id,frequency,sync,high_level,low_level,phase,duty_cycle): "Configure ag_33200 to a square wave with the specified parameters" retcode,res=me.set_function(ag_33200_id,"square") if retcode==0: return 0,res retcode,res=configure_base(ag_33200_id,frequency,sync,high_level,low_level) if retcode==0: return 0,res retcode,res=me.set_phase(ag_33200_id,phase) if retcode==0: return 0,res retcode,res=me.set_duty_cycle(ag_33200_id,duty_cycle) if retcode==0: return 0,res return 1,"ok"
[docs]def configure_ramp_ag_33200(ag_33200_id,frequency,sync,high_level,low_level,phase,symmetry): "Configure ag_33200 to a ramp wave with the specified parameters" retcode,res=me.set_function(ag_33200_id,"ramp") if retcode==0: return 0,res retcode,res=configure_base(ag_33200_id,frequency,sync,high_level,low_level) if retcode==0: return 0,res retcode,res=me.set_phase(ag_33200_id,phase) if retcode==0: return 0,res retcode,res=me.set_symmetry(ag_33200_id,symmetry) if retcode==0: return 0,res return 1,"ok"
[docs]def configure_pulse_ag_33200(ag_33200_id,frequency,sync,high_level,low_level,delay,pulse_width,rising_edge,falling_edge): "Configure ag_33200 to a pulse train with the specified parameters" retcode,res=me.set_function(ag_33200_id,"pulse") if retcode==0: return 0,res retcode,res=configure_base(ag_33200_id,frequency,sync,high_level,low_level) if retcode==0: return 0,res retcode,res=me.set_delay(ag_33200_id,delay) if retcode==0: return 0,res retcode,res=me.set_pulse_width(ag_33200_id,pulse_width) if retcode==0: return 0,res retcode,res=me.set_edges(ag_33200_id,rising_edge,falling_edge) if retcode==0: return 0,res return 1,"ok"
[docs]def power_on_ag_33200(ag_33200_id): "Turn on" return me.power_on(ag_33200_id)
[docs]def power_off_ag_33200(ag_33200_id): "Turn off" return me.power_off(ag_33200_id)