diff --git a/components/actor/hendiCtrl.py b/components/actor/hendiCtrl.py index 325f2be..36e9c9f 100755 --- a/components/actor/hendiCtrl.py +++ b/components/actor/hendiCtrl.py @@ -187,53 +187,3 @@ class HendiCtrl: def close(self): self.remoteEnable(False) - - -if __name__ == '__main__': - - hendi = HendiCtrl('/dev/ttyUSB0', 115200) - -# hendi.firmware_update("HendiCtrl.srec") -# hendi.reset() - time.sleep(1) - - hendi.getState() - hendi.getSoftwareIdentifier() - hendi.getSoftwareVersion() - caps = hendi.getCapabilties() - print("Caps: ", caps) - info = hendi.getInfo() - print("Info: ", info) - - print("Test converters") - for pwr in range(500, 3600, 100): - print("pwr", pwr) - digits = hendi.toDigits(pwr) - print("digits", digits) - power = hendi.toWatts(digits) - print("power", power) - - print("Test Hendi") - with hendi.remote_open(): - hendi.setSwitch(1) - time.sleep(1.0) - for pwr in range(500, 3600, 100): - hendi.setPowerWatts(pwr) - pw = hendi.getPowerWatts() - print("power_w", pw) - time.sleep(1.0) - - hendi.setSwitch(0) - - if 0: - hendi.remoteEnable(True) - if hendi.isRemoteEnable(): - hendi.setSwitch(True) - for p in range(0, 4096, 100): - hendi.setPowerDigits(p) - time.sleep(1) - - hendi.setSwitch(False) - hendi.remoteEnable(False) - - print("End of program.") diff --git a/scripts/hendi_ctrl_app.py b/scripts/hendi_ctrl_app.py new file mode 100644 index 0000000..e7762d7 --- /dev/null +++ b/scripts/hendi_ctrl_app.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +"""CLI tool for talking to a Hendi induction plate over serial - see +components/actor/hendiCtrl.py for the protocol/HendiCtrl class this wraps.""" + +import argparse as ap +import time + +from components.actor.hendiCtrl import HendiCtrl + +DEFAULT_PORT = '/dev/ttyUSB0' +DEFAULT_BAUDRATE = 115200 + + +def print_version(hendi): + print(f"{hendi.getSoftwareIdentifier()}, F/W-Version: {hendi.getSoftwareVersion()}") + + +def print_capabilities(hendi): + print("Capabilities:", hendi.getCapabilties()) + + +def test_converter(hendi): + print("Test converters") + for pwr in range(500, 3600, 100): + digits = hendi.toDigits(pwr) + power = hendi.toWatts(digits) + print(f"pwr={pwr} digits={digits} power={power}") + + +def test_heater(hendi): + print("Test Hendi") + with hendi.remote_open(): + hendi.setSwitch(1) + time.sleep(1.0) + for pwr in range(500, 3600, 100): + hendi.setPowerWatts(pwr) + pw = hendi.getPowerWatts() + print("power_w", pw) + time.sleep(1.0) + + hendi.setSwitch(0) + + +def update_firmware(hendi, filename): + hendi.firmware_update(filename) + + +def main(): + parser = ap.ArgumentParser(description=__doc__) + parser.add_argument("--serial-port", default=DEFAULT_PORT) + parser.add_argument("--baudrate", type=int, default=DEFAULT_BAUDRATE) + parser.add_argument("--version", action="store_true", help="print software identifier/version") + parser.add_argument("--capabilities", action="store_true", help="print power/digit capability info") + parser.add_argument("--test-converter", action="store_true", help="round-trip the watts<->digits polynomials") + parser.add_argument("--test-heater", action="store_true", help="drive the heater through its power range") + parser.add_argument("--update-firmware", metavar="FILE", help="flash the given firmware file") + args = parser.parse_args() + + hendi = HendiCtrl(args.serial_port, args.baudrate) + + if args.version: + print_version(hendi) + if args.capabilities: + print_capabilities(hendi) + if args.test_converter: + test_converter(hendi) + if args.test_heater: + test_heater(hendi) + if args.update_firmware: + update_firmware(hendi, args.update_firmware) + + print("End of program.") + + +if __name__ == '__main__': + main()