This commit is contained in:
Benjamyn Love 2025-08-23 15:09:14 +10:00
commit 89b656d917
6 changed files with 129 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
__pycache__/
venv/

28
README.md Normal file
View File

@ -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

10
src/get_temps.py Normal file
View File

@ -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()

67
src/libmd1200.py Normal file
View File

@ -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)

10
src/list_commands.py Normal file
View File

@ -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))

12
src/set_speed.py Normal file
View File

@ -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)