Source code for cmd_ki_237

#!/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 ki_237_class(scpi.scpi):
    # Available channels
    channels=["1"]
    curr_limits_ranges=[1e-9,10e-9,100e-9,1e-6,10e-6,100e-6,1e-3,10e-3,100e-3]
    volt_limits_ranges=[1.1,11,110,1100]

    def range_for_value(self,ranges,value):
        for r in ranges:
            if r>=abs(float(value)):
                return ranges.index(r)+1
        return 0

    def __init__(self):
        super(ki_237_class,self).__init__("ki_237")

    def config(self,ki_237_id):
        command="Y3X R1 T0,0,0,0 G13,0,0" # Y3 to set termination char to 10 (\n)
        retcode,res=super(ki_237_class,self).config(ki_237_id,command,0.5)
        if retcode==0:
            return 0,res
        retcode,res=self.free_query(ki_237_id,"H0X")
        if retcode==0:
            return 0,res
        if res[4:5]=="V":
            self.set_param(ki_237_id,"src_mode","voltage")
        else:
            self.set_param(ki_237_id,"src_mode","current")
        return 1,"ok"

    def reset(self,ki_237_id):
        command="++rst"
        return self.free_command(ki_237_id,command)
    
    def set_voltage(self,ki_237_id,voltage):
        retcode,res=self.set_param(ki_237_id,"src_mode","voltage")
        if retcode==0:
            return 0,res
        r=self.range_for_value(self.volt_limits_ranges,voltage)
        command="F0,0 H0X B{voltage:.5e},"+str(r)+",0X"
        return super(ki_237_class,self).set_voltage(ki_237_id,voltage,command)

    def set_current(self,ki_237_id,current):
        retcode,res=self.set_param(ki_237_id,"src_mode","current")
        if retcode==0:
            return 0,res
        r=self.range_for_value(self.curr_limits_ranges,current)
        command="F1,0 H0X B{current:.5e},"+str(r)+",0X"
        return super(ki_237_class,self).set_current(ki_237_id,current,command)

    def set_voltage_limit(self,ki_237_id,voltage_limit):
        r=self.range_for_value(self.volt_limits_ranges,voltage_limit)
        command="F1,0 H0X L{voltage_limit:.5e},"+str(r)+"X"
        return super(ki_237_class,self).set_voltage_limit(ki_237_id,voltage_limit,command)

    def set_current_limit(self,ki_237_id,current_limit):
        r=self.range_for_value(self.curr_limits_ranges,current_limit)
        command="F0,0 H0X L{current_limit:.5e},"+str(r)+"X"
        return super(ki_237_class,self).set_current_limit(ki_237_id,current_limit,command)

    def get_voltage(self,ki_237_id):
        retcode,res=self.get_param(ki_237_id,"src_mode")
        if retcode==0:
            return 0,res
        if res=="voltage":
            index=0
        else:
            index=1
        query="H0X"
        retcode,res=self.simple_query(ki_237_id,query)
        if retcode==0:
            return 0,res
        return 1,res.split(",")[index][5:]

    def get_current(self,ki_237_id):
        retcode,res=self.get_param(ki_237_id,"src_mode")
        if retcode==0:
            return 0,res
        if res=="current":
            index=0
        else:
            index=1
        query="H0X"
        retcode,res=self.simple_query(ki_237_id,query)
        if retcode==0:
            return 0,res
        return 1,res.split(",")[index][5:]

    def power_on(self,ki_237_id):
        command="N1X"
        return self.free_command(ki_237_id,command)

    def power_off(self,ki_237_id):
        command="N0X"
        return self.free_command(ki_237_id,command)

# CREATE POOL ####################################################

me=ki_237_class()

# COMMANDS #######################################################

[docs]def init_ki_237(ki_237_id,conf_string): """Initialize ki_237 power supply identified by *ki_237_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(ki_237_id,conf_string)
[docs]def deinit_ki_237(ki_237_id): "Deinitialize an ki_237" return me.deinit(ki_237_id)
[docs]def config_ki_237(ki_237_id): "Configure an ki_237" return me.config(ki_237_id)
[docs]def inval_ki_237(ki_237_id): "Invalidate an ki_237" return me.inval(ki_237_id)
[docs]def reset_ki_237(ki_237_id): "Send RST signal to PS" return me.reset(ki_237_id)
[docs]def set_voltage_ki_237(ki_237_id,voltage): "Set voltage in Volts." return me.set_voltage(ki_237_id,voltage)
[docs]def set_current_ki_237(ki_237_id,current): "Set current in Ampers." return me.set_current(ki_237_id,current)
[docs]def set_voltage_limit_ki_237(ki_237_id,voltage_limit): "Set voltage limit in Volts. The Over Voltage Protection will be set to 105% of the supplied value." return me.set_voltage_limit(ki_237_id,voltage_limit)
[docs]def set_current_limit_ki_237(ki_237_id,current_limit): "Set current limit in Ampers." return me.set_current_limit(ki_237_id,current_limit)
[docs]def get_voltage_ki_237(ki_237_id): "Get voltage in Volts." return me.get_voltage(ki_237_id)
[docs]def get_current_ki_237(ki_237_id): "Get current in Ampers." return me.get_current(ki_237_id)
[docs]def power_on_ki_237(ki_237_id): "Turn on." return me.power_on(ki_237_id)
[docs]def power_off_ki_237(ki_237_id): "Turn off." return me.power_off(ki_237_id)
[docs]def free_command_ki_237(ki_237_id,command): "Send a raw command to the PS" return me.free_command(ki_237_id,command)
[docs]def free_query_ki_237(ki_237_id,query): "Send a raw command to the PS and read response" return me.free_query(ki_237_id,query)
[docs]def get_error_queue_ki_237(ki_237_id): "Read error queue until the end (code 0)" return me.get_error_queue(ki_237_id)