Source code for cmd_ki_6487

#!/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_6487_class(scpi.scpi):
    # Available channels
    channels=["1"]
    curr_limits=[25e-6,250e-6,2.5e-3,25e-3]

    def __init__(self):
        super(ki_6487_class,self).__init__("ki_6487")

    def config(self,ki_6487_id):
        command= r"SYST:CLE\n"
        command+=r"SENS:CURR:OHMS OFF\n"
        command+=r"ARM:COUNT 1\n"
        command+=r"FORM:DATA ASC\n"
        command+=r"FORM:ELEM ALL"
        retcode,res=super(ki_6487_class,self).config(ki_6487_id,command)
        if retcode==0:
            return 0,res
        query=r"*IDN?"
        retcode,res=self.simple_query(ki_6487_id,query)
        if retcode==0:
            return 0,res
        fw_version=res.split(",")[3][0:3]
        if fw_version not in ["A03","B02"]:
            return 0,"unsupported firmware version %s"%(fw_version)
        return self.set_fw_version(ki_6487_id,fw_version)

    def reset(self,ki_6487_id):
        command= r"*RST\n"
        command+=r"FORM:DATA ASC\n"
        command+=r"FORM:ELEM ALL"
        retcode,res=self.free_command(ki_6487_id,command)
        if retcode==0:
            return 0,res
        time.sleep(1)
        command="SYST:ZCH OFF"
        return self.free_command(ki_6487_id,command)
    
    def set_voltage(self,ki_6487_id,voltage):
        voltage=float(voltage)
        if abs(voltage) < 10:
            command=r"SOUR:VOLT:RANG 10\n"
        elif abs(voltage) < 50:
            command=r"SOUR:VOLT:RANG 50\n"
        elif abs(voltage) < 505:
            command=r"SOUR:VOLT:RANG 500\n"
        else:
            return 0,"Voltage out of range"
        command+=r"SOUR:VOLT:ILIM {current:.5e}\n"
        command+=r"SOUR:VOLT {voltage:.5e}"
        return super(ki_6487_class,self).set_voltage(ki_6487_id,voltage,command)

    def set_current_limit(self,ki_6487_id,current_limit):
        if float(current_limit) not in self.curr_limits:
            return 0,"valid current limits are: 25e-6, 250e-6, 2.5e-3, 25e-3"
        command=r"SOUR:VOLT:ILIM {current_limit:.5e}"
        return super(ki_6487_class,self).set_current_limit(ki_6487_id,current_limit,command)

    def get_voltage(self,ki_6487_id):
        retcode,res=self.get_fw_version(ki_6487_id)
        if retcode==0:
            return 0,res
        fw_version=res
        query=r"READ?"
        retcode,res=self.simple_query(ki_6487_id,query)
        if retcode==0:
            return 0,res
        rvoltage=float(res.split(",")[3])
        if fw_version=="A03":
            query=r"SOUR:VOLT:RANG?"
            retcode,res=self.simple_query(ki_6487_id,query)
            if retcode==0:
                return 0,res
            factor=float(res)/10
        elif fw_version=="B02":
            factor=1
            if rvoltage==-999:
                return 0,"compliance"
        return 1,str(rvoltage*factor)

    def get_current(self,ki_6487_id):
        query=r"READ?"
        retcode,res=self.simple_query(ki_6487_id,query)
        if retcode==0:
            return 0,res
        return 1,str(float(res.split(",")[0][:-1]))

    def power_on(self,ki_6487_id):
        command="SOUR:VOLT:STAT ON"
        return self.free_command(ki_6487_id,command)

    def power_off(self,ki_6487_id):
        command="SOUR:VOLT:STAT OFF"
        return self.free_command(ki_6487_id,command)

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

me=ki_6487_class()

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

[docs]def init_ki_6487(ki_6487_id,conf_string): """Initialize ki_6487 power supply identified by *ki_6487_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_6487_id,conf_string)
[docs]def deinit_ki_6487(ki_6487_id): "Deinitialize an ki_6487" return me.deinit(ki_6487_id)
[docs]def config_ki_6487(ki_6487_id): "Configure an ki_6487" return me.config(ki_6487_id)
[docs]def inval_ki_6487(ki_6487_id): "Invalidate an ki_6487" return me.inval(ki_6487_id)
[docs]def reset_ki_6487(ki_6487_id): "Send RST signal to PS" return me.reset(ki_6487_id)
[docs]def set_voltage_ki_6487(ki_6487_id,voltage): "Set voltage in Volts." return me.set_voltage(ki_6487_id,voltage)
[docs]def set_voltage_limit_ki_6487(ki_6487_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_6487_id,voltage_limit)
[docs]def set_current_limit_ki_6487(ki_6487_id,current_limit): "Set current limit in Ampers." return me.set_current_limit(ki_6487_id,current_limit)
[docs]def get_voltage_ki_6487(ki_6487_id): "Get voltage in Volts." return me.get_voltage(ki_6487_id)
[docs]def get_current_ki_6487(ki_6487_id): "Get current in Ampers." return me.get_current(ki_6487_id)
[docs]def power_on_ki_6487(ki_6487_id): "Turn on." return me.power_on(ki_6487_id)
[docs]def power_off_ki_6487(ki_6487_id): "Turn off." return me.power_off(ki_6487_id)
[docs]def free_command_ki_6487(ki_6487_id,command): "Send a raw command to the PS" return me.free_command(ki_6487_id,command)
[docs]def get_error_queue_ki_6487(ki_6487_id): "Read error queue until the end (code 0)" return me.get_error_queue(ki_6487_id)