From 89bbef89e93c7259b6162a8c4c224d67bfacfa99 Mon Sep 17 00:00:00 2001 From: Raphael Wimmer Date: Mon, 24 Jul 2023 20:17:05 +0200 Subject: [PATCH 1/2] optionally log all serial commands into a log file --- plotink/ebb_serial.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plotink/ebb_serial.py b/plotink/ebb_serial.py index 9079c1f..4b91be0 100644 --- a/plotink/ebb_serial.py +++ b/plotink/ebb_serial.py @@ -46,6 +46,8 @@ logger = logging.getLogger(__name__) +command_log = None + def version(): '''Version number for this document''' return "0.19" # Dated 2022-10-05 @@ -299,6 +301,21 @@ def testPort(port_name): return None +def startLogging(logfile): + global command_log + if logfile and not command_log: + try: + command_log = open(logfile, 'wb') + except PermissionError: + command_log = None # be explicit + + +def stopLogging(): + global command_log + if command_log: + command_log.close() + + def openPort(): ''' Find and open a port to a single attached EiBotBoard. @@ -376,6 +393,8 @@ def command(port_name, cmd, verbose=True): '''General command to send a command to the EiBotBoard''' if port_name is not None and cmd is not None: try: + if command_log: + command_log.write(cmd.encode('ascii')) port_name.write(cmd.encode('ascii')) response = port_name.readline().decode('ascii') n_retry_count = 0 From 9f2ef9d5edaf52fced0c543de0f1d4db87d920eb Mon Sep 17 00:00:00 2001 From: Raphael Wimmer Date: Mon, 24 Jul 2023 20:17:50 +0200 Subject: [PATCH 2/2] new script to replay a command log --- plotink/ebb_replay_log.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 plotink/ebb_replay_log.py diff --git a/plotink/ebb_replay_log.py b/plotink/ebb_replay_log.py new file mode 100755 index 0000000..af014cb --- /dev/null +++ b/plotink/ebb_replay_log.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +HELP = ''' +This simple script replays the commands logged by +the EggBot Inkscape extension. + +Usage: python3 ebb_replay_log.py +''' + +from serial import Serial +import sys + +if len(sys.argv) < 3: + print(HELP) + sys.exit(-1) + +filename = sys.argv[1] +port = sys.argv[2] + +ser = Serial(port, 115200) +commands = open(filename).readlines() + +for command in commands: + ser.write(command.encode('ascii')) + ret = ser.readline() + print(command, ret)