Source code for cmd_ki_6517

#!/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 scpi

# CLASS ##########################################################

class ki_6517_class(scpi.scpi):
    # Available channels
    channels=["1"]

    def __init__(self):
        super(ki_6517_class,self).__init__("ki_6517")

    def config(self,ki_6517_id):
        command= r"*CLS\n"
        command+=r":INIT:CONT ON\n"
        command+=r"FORM:DATA ASC\n"
        command+=r"FORM:ELEM ALL"
        return super(ki_6517_class,self).config(ki_6517_id,command)

    def reset(self,ki_6517_id):
        command= r"*RST\n"
        command+=r":INIT:CONT ON\n"
        command+=r"FORM:DATA ASC\n"
        command+=r"FORM:ELEM ALL"
        retcode,res=self.free_command(ki_6517_id,command)
        if retcode==0:
            return 0,res
        time.sleep(1)
        command="SYST:ZCH OFF"
        return self.free_command(ki_6517_id,command)
    
    def set_voltage(self,ki_6517_id,voltage):
        # in ki_6517 current limit is always 1mA. just set current_limit
        # to something so that we can set_voltage afterwards
        retcode,res=self.set_current_limit(ki_6517_id,"1e-3","")
        if retcode==0:
            return 0,res
        voltage=float(voltage)
        if abs(voltage) < 100:
            command=r"SOUR:VOLT:RANG 100\n"
        elif abs(voltage) < 1000:
            command=r"SOUR:VOLT:RANG 1000\n"
        else:
            return 0,"Voltage out of range"
        command+=r"SOUR:VOLT {voltage:.5e}"
        return super(ki_6517_class,self).set_voltage(ki_6517_id,voltage,command)

    def set_voltage_limit(self,ki_6517_id,voltage_limit):
        command=":SOUR:VOLT:LIM:STAT 1"
        command+=r"\n:SOUR:VOLT:LIM {voltage_limit:.5e}"
        return super(ki_6517_class,self).set_voltage_limit(ki_6517_id,voltage_limit,command)

    def get_voltage(self,ki_6517_id):
        query="FETCH?"
        retcode,res=self.simple_query(ki_6517_id,query)
        if retcode==0:
            return 0,res
        if (res.split(",")[6][-4:]!="Vsrc"):
            return 0,"invalid answer. expected Vsrc units, got %s"%(res.split(",")[7])
        return 1,str(float(res.split(",")[6][:-4]))

    def get_current(self,ki_6517_id):
        query="FETCH?"
        retcode,res=self.simple_query(ki_6517_id,query)
        if retcode==0:
            return 0,res
        if (res.split(",")[0][-3:]!="ADC"):
            return 0,"set instrument in current mode"
        return 1,str(float(res.split(",")[0][:-4]))

    def power_on(self,ki_6517_id):
        command="OUTP:STAT ON"
        return self.free_command(ki_6517_id,command)

    def power_off(self,ki_6517_id):
        command="OUTP:STAT OFF"
        return self.free_command(ki_6517_id,command)

    def set_digital(self,ki_6517_id,state,channel,active_level):
        if state:
            s="ON"
        else:
            s="OFF"
        if channel.lower()=="undef":
            print("warning: set_digital: channel is undef. doing nothing")
            return 1,"ok"
        if active_level.lower()=="undef":
            active_level=="high"
        if active_level.lower() not in ["high","low"]:
            return 0,"invalid active level. must be high or low"
        command=r":OUTP2:TTL%d:LSEN A%s\n"%(int(channel),active_level.upper())
        command+=":SOUR:TTL%d:LEV %s"%(int(channel),s)
        return self.free_command(ki_6517_id,command)

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

me=ki_6517_class()

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

[docs]def init_ki_6517(ki_6517_id,conf_string): """Initialize ki_6517 power supply identified by *ki_6517_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_6517_id,conf_string)
[docs]def deinit_ki_6517(ki_6517_id): "Deinitialize an ki_6517" return me.deinit(ki_6517_id)
[docs]def config_ki_6517(ki_6517_id): "Configure an ki_6517" return me.config(ki_6517_id)
[docs]def inval_ki_6517(ki_6517_id): "Invalidate an ki_6517" return me.inval(ki_6517_id)
[docs]def reset_ki_6517(ki_6517_id): "Send RST signal to PS" return me.reset(ki_6517_id)
[docs]def set_voltage_ki_6517(ki_6517_id,voltage): "Set voltage in Volts. Current limit is fixed to 1mA" return me.set_voltage(ki_6517_id,voltage)
[docs]def set_voltage_limit_ki_6517(ki_6517_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_6517_id,voltage_limit)
[docs]def get_voltage_ki_6517(ki_6517_id): "Get voltage in Volts." return me.get_voltage(ki_6517_id)
[docs]def get_current_ki_6517(ki_6517_id): "Get current in Ampers." return me.get_current(ki_6517_id)
[docs]def power_on_ki_6517(ki_6517_id): "Turn on." return me.power_on(ki_6517_id)
[docs]def power_off_ki_6517(ki_6517_id): "Turn off." return me.power_off(ki_6517_id)
[docs]def set_digital_on_ki_6517(ki_6517_id,active_level,channel): "Set digital output *channel* (1 to 4) to ON. Optionally configure the *active_level* to high or low" return me.set_digital(ki_6517_id,True,channel,active_level)
[docs]def set_digital_off_ki_6517(ki_6517_id,active_level,channel): "Set digital output *channel* (1 to 4) to OFF. Optionally configure the *active_level* to high or low" return me.set_digital(ki_6517_id,False,channel,active_level)
[docs]def free_command_ki_6517(ki_6517_id,command): "Send a raw command to the PS" return me.free_command(ki_6517_id,command)
[docs]def free_query_ki_6517(ki_6517_id,query): "Send a raw command to the PS and read response" return me.free_query(ki_6517_id,query)
[docs]def get_error_queue_ki_6517(ki_6517_id): "Read error queue until the end (code 0)" return me.get_error_queue(ki_6517_id)