From b139a8561f54b7a764faa54b117a8544b8451d41 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 27 Feb 2018 14:16:16 -0500 Subject: serialhdl: Add a wrapper around the results of lookup_command() Add a lookup_command() method to the SerialReader class that provides a wrapper that stores the serial and commandqueue references. This makes it easier to run the send() method. Signed-off-by: Kevin O'Connor --- klippy/console.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'klippy/console.py') diff --git a/klippy/console.py b/klippy/console.py index cd7facfd..0259864f 100755 --- a/klippy/console.py +++ b/klippy/console.py @@ -86,11 +86,10 @@ class KeyboardReader: self.output("Error: %s" % (str(e),)) return try: - msg = self.ser.msgparser.create_command(' '.join(parts[2:])) + self.ser.send(' '.join(parts[2:]), minclock=val) except msgproto.error as e: self.output("Error: %s" % (str(e),)) return - self.ser.send(msg, minclock=val) def command_FLOOD(self, parts): try: count = int(parts[1]) @@ -98,18 +97,18 @@ class KeyboardReader: except ValueError as e: self.output("Error: %s" % (str(e),)) return + msg = ' '.join(parts[3:]) + delay_clock = int(delay * self.mcu_freq) + msg_clock = int(self.clocksync.get_clock(self.reactor.monotonic()) + + self.mcu_freq * .200) try: - msg = self.ser.msgparser.create_command(' '.join(parts[3:])) + for i in range(count): + next_clock = msg_clock + delay_clock + self.ser.send(msg, minclock=msg_clock, reqclock=next_clock) + msg_clock = next_clock except msgproto.error as e: self.output("Error: %s" % (str(e),)) return - delay_clock = int(delay * self.mcu_freq) - msg_clock = int(self.clocksync.get_clock(self.reactor.monotonic()) - + self.mcu_freq * .200) - for i in range(count): - next_clock = msg_clock + delay_clock - self.ser.send(msg, minclock=msg_clock, reqclock=next_clock) - msg_clock = next_clock def command_SUPPRESS(self, parts): oid = None try: @@ -164,12 +163,7 @@ class KeyboardReader: if parts[0] in self.local_commands: self.local_commands[parts[0]](parts) return None - try: - msg = self.ser.msgparser.create_command(line) - except msgproto.error as e: - self.output("Error: %s" % (str(e),)) - return None - return msg + return line def process_kbd(self, eventtime): self.data += os.read(self.fd, 4096) @@ -184,7 +178,11 @@ class KeyboardReader: msg = self.translate(line.strip(), eventtime) if msg is None: continue - self.ser.send(msg) + try: + self.ser.send(msg) + except msgproto.error as e: + self.output("Error: %s" % (str(e),)) + return None self.data = kbdlines[-1] def main(): -- cgit v1.2.3-70-g09d2