Created
October 10, 2022 00:29
-
-
Save projectgus/a6b93c8a384be8761bf410be5672781f to your computer and use it in GitHub Desktop.
Quick and dirty register logger for HL100100 DC motor controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Place in same directory as https://github.com/burpen/hl200200-controller-uart-utility code | |
from controller import * | |
import serial | |
import struct | |
import time | |
s = serial.Serial('/dev/ttyUSB0', 19200) | |
def readReg(reg, mask=0xFFF): | |
s.write(bytes([0x80, reg.value])) | |
res = s.read(3) | |
if (res[0] + res[1] + reg.value) & 0x7f != res[2]: | |
print('WARNING: CMD {:#x} ERROR RESPONSE {}'.format(reg.value, res.hex())) | |
val = (res[0] << 7) + (res[1] & 0x7F) | |
return val | |
SAMPLES = [(ReadCommand.SPEEDADCINPUT, "{:04d}"), | |
(ReadCommand.LOADCURRENT1, "{:04d}"), | |
(ReadCommand.SPEEDMOTOR1, "{:04d}"), | |
(ReadCommand.STATUSREGISTER, "{:#06x}"), | |
(ReadCommand.SUPPLYVOLTAGE, "{:04d}"), | |
] | |
FMT_STR = "{:07.2f}: " + " - ".join(f for _r,f in SAMPLES) | |
start = time.time() | |
print("TIME: " + " - ".join(r.name for r,f in SAMPLES)) | |
while True: | |
res = [readReg(r) for r,f in SAMPLES] | |
res.insert(0, time.time() - start) | |
print(FMT_STR.format(*res)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment