Source code for ppf_moke.powersupply
import socket
from time import sleep
remote_ip = '169.254.99.154' # should match the instrument’s IP address
port = 10001 # the port number of the instrument service
[docs]def open_connection():
""" opens the serial connection with the powersupply
"""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((remote_ip, port))
nay = b'#NAK\r'
s.send(b'MON\r')
if s.recv(port) == nay:
s.send(b'MRESET\r')
s.recv(port)
return(s)
[docs]def close_connection(s):
""" closes the given serial connection with the powersupply should be done at the end of the measurement script
"""
s.close()
[docs]def shutdown_connection(s):
""" shuts down the serial connection with the powersupply should be done at the end of the measurement script
"""
s.shutdown(socket.SHUT_RDWR)
s.close()
[docs]def set_current(s, current):
""" sets a current via a given serial connection to the powersupply
"""
com = f'MRM:{current}\r'
s.send(bytes(com, encoding='utf-8'))
sleep(0.2)
s.recv(port)
[docs]def read_current(s):
""" reads the current via a given serial connection to the powersupply
"""
s.send(b'MRI\r')
sleep(0.25)
v = s.recv(port).decode("utf-8")[5:]
return(float(v))
[docs]def test():
""" prints a confirmation to the console if the module is properly loaded """
print("powersupply module is working")