From 0420c96c72bc5b3cfe25b48edc8efafafdec8fe7 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Mon, 15 May 2023 14:42:17 -0700 Subject: [PATCH] Correct folder reupload --- ZXY6005s.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ testmain.py | 13 ++++++++++ 2 files changed, 87 insertions(+) create mode 100644 ZXY6005s.py create mode 100644 testmain.py diff --git a/ZXY6005s.py b/ZXY6005s.py new file mode 100644 index 0000000..9360f06 --- /dev/null +++ b/ZXY6005s.py @@ -0,0 +1,74 @@ +import serial +import time +#import utilities as utils #debugging +import struct + +#v1.1_0514 +# Library that manages the ZXY6005s power supply + + +#these functions to be used for later +#raw bytes to a string +def as_string(raw_data): + return bytearray(raw_data[:-1]) + +#raw bytes to a float +def as_float(raw_data): + f = struct.unpack_from(">f", bytearray(raw_data))[0] + return f + +#raw bytes to a word +def as_word(raw_data): + w = struct.unpack_from(">H", bytearray(raw_data))[0] + return w + + +class ZXY6005s: + def __init__(self, port,input_delay=utils.INPUT_DELAY, baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1): + self.port = port + self.input_delay = input_delay + self.baudrate = baudrate + self.baudrate = baudrate + self.parity = parity + self.bytesize = bytesize + self.timeout = timeout + self.serial = None + utils.log(0, "Powersupply info:\n\tPort: " + str(port) + '\n\tInput delay: ' str(input_delay) + '\n\tBaud rate: ' + str(baudrate) + '\n\tParity: ' + str(parity) + '\n\t stop bits: ' + str(stopbits) + '\n\tByte Size: ' + str(bytesize) + '\n\tTimeout: ' + str(timeout)) + + def is_open(self): + return self.serial.is_open + + def get_device_information(self): + return self.__device_information + + def disconnect(self): + self.serial.close() + + def send_command(self, command): + self.serial.write(command.encode()) + + def set_voltage(self, voltage): + self.send_command(f"VSET:{voltage:.2f}") + + def set_current(self, current): + self.send_command(f"ISET:{current:.3f}") + + def enable_output(self): + self.send_command("OUT1") + + def disable_output(self): + self.send_command("OUT0") + + + + + + + + +#Notes +#Baudrate: speed of communication over a data channel +#Parity: bit added to a string as a form of error detection + + + diff --git a/testmain.py b/testmain.py new file mode 100644 index 0000000..4347e1f --- /dev/null +++ b/testmain.py @@ -0,0 +1,13 @@ +from zxy6005s import ZXY6005s + +psu = ZXY6005s('/dev/ttyUSB0') +psu.connec() + +psu.set_voltage(4.0) +psu.set_current(0.5) + +psu.enable_output() +time.sleep(10) +psu.disable_output() + +psu.disconnect()