commit 89b656d917233fd720d4a2e32657ae524655cd8d Author: Benjamyn Love Date: Sat Aug 23 15:09:14 2025 +1000 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0540009 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +venv/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a1eefef --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# libmd1200 + +Python library for the MD1200 disk shelf, `VERY WIP` but in rapid development + +## Requirements (Software) + - pyserial + +## Requirements (Hardware) + - MD1200 + - Serial connection + +## Usage +Simply construct a `MD1200` object with the path to the serial device like + +```python +from libmd1200 import MD1200 +SERIAL_DEVICE = "/dev/ttyUSB0" + +md1200 = MD1200(SERIAL_DEVICE) +``` + +From there the following funcitons have been implemented + - MD1200.get_temps() + - Returns a Temperature object + - MD1200.set_speed(SPEED) + - Sends the `_shutup` command with the fan speed in percentage + - MD1200.get_commands(INCLUDE_SUPERS) + - Gets all the available commands from the MD1200 disk shelf, INCLUDE_SUPERS is a bool that includes administrative and debug commands \ No newline at end of file diff --git a/src/get_temps.py b/src/get_temps.py new file mode 100644 index 0000000..1100561 --- /dev/null +++ b/src/get_temps.py @@ -0,0 +1,10 @@ +## Gets the temperature data from the MD1200 disk shelf and prints it out +## SIMPLE REFERENCE IMPLEMENTATION +## Benjamyn Love + +import libmd1200 +SERIAL = '/dev/ttyUSB0' + +md1200 = libmd1200.MD1200(SERIAL) + +md1200.get_temps() diff --git a/src/libmd1200.py b/src/libmd1200.py new file mode 100644 index 0000000..eb8da8b --- /dev/null +++ b/src/libmd1200.py @@ -0,0 +1,67 @@ +import serial +from pprint import pprint +from time import sleep + +class MD1200: + class TemperatureData: + def __init__(self, inp): + data = inp.split("\r\n") + for line in data: + if "BP_1" in line: + self.bp1 = line.split('=')[1].split('c')[0].strip() + if "BP_2" in line: + self.bp2 = line.split('=')[1].split('c')[0].strip() + if "SIM0" in line: + self.sim0 = line.split('=')[1].split('c')[0].strip() + if "EXP0" in line: + self.exp0 = line.split('=')[1].split('c')[0].strip() + if "AVG" in line: + self.avg = line.split('=')[1].split('c')[0].strip() + + def __str__(self): + return f"BP1:\t{self.bp1}\nBP2:\t{self.bp2}\nSIM0:\t{self.sim0}\nEXP0:\t{self.exp0}\nAVG:\t{self.avg}" + + def __init__(self, serial_device, baudrate=38400, timeout=30): + try: + self.serial = serial.Serial(serial_device, baudrate, timeout=timeout) + except serial.serialutil.SerialException as e: + print(f"Failed to serial correctly, please check the port\n, E: {e}") + exit(69) + + def __del__(self): + self.serial.close() + + def send_command(self, command, return_resp=False): + cmd = "\r" + cmd += command + cmd += "\r\n" + + self.serial.reset_input_buffer() + self.serial.reset_output_buffer() + self.serial.write(cmd.encode('ascii')) + return self.get_results().decode() if return_resp else None + + def get_commands(self, include_supers=False): + data = "" + if include_supers: + data += self.send_command("_devils", True) + data += self.send_command("devils", True) + return data + + def get_results(self): + data = "" + #with serial.Serial(self.serial_device, self.baudrate, timeout=1) as ser: + # pprint(ser) + # while ser.out_waiting != 0: + data = self.serial.read_until(b"\r\n\r\nBlueDress.105.001 >") + return data + + def set_speed(self, fan_percentage): + return self.send_command(f"_shutup {fan_percentage}") + + def get_temps(self): + data = self.send_command("_temp_rd", True) + t = self.TemperatureData(data) + print(t) + + diff --git a/src/list_commands.py b/src/list_commands.py new file mode 100644 index 0000000..39096dc --- /dev/null +++ b/src/list_commands.py @@ -0,0 +1,10 @@ +## Prints the command list of the MD1200 disk shelf +## SIMPLE REFERENCE IMPLEMENTATION +## Benjamyn Love + +import libmd1200 + +SERIAL = "/dev/ttyUSB0" + +md1200 = libmd1200.MD1200(SERIAL) +print(md1200.get_commands(True)) diff --git a/src/set_speed.py b/src/set_speed.py new file mode 100644 index 0000000..d50d851 --- /dev/null +++ b/src/set_speed.py @@ -0,0 +1,12 @@ +## Sets the fan speed of an MD1200 disk shelf to 15% +## SIMPLE REFERENCE IMPLEMENTATION +## Benjamyn Love + +import libmd1200 +SERIAL = '/dev/ttyUSB0' + +md1200 = libmd1200.MD1200(SERIAL) + +md1200.set_speed(15) + +