Skip to content

Commit

Permalink
Correct folder reupload
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo committed May 15, 2023
1 parent 06fbe85 commit 0420c96
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
74 changes: 74 additions & 0 deletions ZXY6005s.py
Original file line number Diff line number Diff line change
@@ -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



13 changes: 13 additions & 0 deletions testmain.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 0420c96

Please sign in to comment.