1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
# SPDX-FileCopyrightText: All Contributors to the PyTango project
# SPDX-License-Identifier: LGPL-3.0-or-later
"""
Simple socket library to access the "hardware" simulator
provided by ps-simulator.py.
"""
from time import sleep
from socket import create_connection
class PowerSupplyClient:
def __init__(self, host, port):
self.host = host
self.port = port
self.sock = None
self.sock_stream = None
def connect(self):
self.sock = create_connection((self.host, self.port))
self.sock_stream = self.sock.makefile("rwb", newline="\n", buffering=0)
def disconnect(self):
if self.sock_stream:
self.sock_stream.close()
self.sock_stream = None
if self.sock:
self.sock.close()
self.sock = None
def write_readline(self, msg):
if self.sock_stream is None:
self.connect()
self.sock_stream.write(msg)
return self.sock_stream.readline()
def get_voltage(self):
return float(self.write_readline(b"VOL?\n"))
def do_calibration(self):
self.start_calibration()
self.wait_for_calibration()
def start_calibration(self):
self.write_readline(b"CALIB 1\n")
def wait_for_calibration(self):
while self.is_calibration_busy():
sleep(0.1)
def is_calibration_busy(self):
return int(self.write_readline(b"STAT?\n")) > 0
|