frappy/frappy_psi/bkpower.py
Markus Zolliker a429852c80 adopt frappy_psi and frappy changes from wip
Change-Id: I4e6732e755398d88b73007fb53b758039c5d4483
2024-01-29 10:56:58 +01:00

68 lines
2.6 KiB
Python

# *****************************************************************************
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program 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 General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Module authors:
# Markus Zolliker <markus.zolliker@psi.ch>
# Jael Celia Lorenzana <jael-celia.lorenzana@psi.ch>
# *****************************************************************************
"""Powersupply B&K Precision BK168xB"""
from frappy.core import StringIO, Readable, Parameter, FloatRange, Writable, HasIO, BoolType
class IO(StringIO):
end_of_line = ('OK\r', '\r')
default_settings = {'baudrate': 9600}
class Power(HasIO, Readable):
value = Parameter(datatype=FloatRange(0,300,unit='W'))
def read_value(self):
reply = self.communicate('GETD')
volt = float(reply[0:4])/100
current = float(reply[4:8])/100
return volt*current
class Output(HasIO, Writable):
value = Parameter(datatype=FloatRange(0,100,unit='%'))
target = Parameter(datatype=FloatRange(0,100,unit='%'))
maxvolt = Parameter('voltage at 100%',datatype=FloatRange(0,60,unit='V'),default=50,readonly=False)
maxcurrent = Parameter('current at 100%',datatype=FloatRange(0,5,unit='A'),default=2,readonly=False)
output_enable = Parameter('control on/off', BoolType(), readonly=False)
def initModule(self):
super().initModule()
self.write_output_enable(False)
def write_target(self, target):
self.write_output_enable(target != 0)
self.communicate(f'VOLT{round(max(8,target*self.maxvolt/10)):03d}')
self.communicate(f'CURR{round(target*self.maxcurrent):03d}')
self.value = target
def write_output_enable(self, value):
self.communicate(f'SOUT{int(not value)}')
def write_maxvolt(self, maxvolt):
self.communicate(f'SOVP{round(maxvolt*10):03d}')
def write_maxcurrent(self, maxcurrent):
self.communicate(f'SOCP{round(maxcurrent*100):03d}')
def shutdown(self):
self.write_target(0)