From 49db82f0996a720f7a930fd4fb1857cc606dff8d Mon Sep 17 00:00:00 2001 From: Adam Mayer Date: Fri, 15 Dec 2017 17:09:10 -0500 Subject: [PATCH] adding flags for CTS-DSR hack and "safe" flow control --- apple410/__init__.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/apple410/__init__.py b/apple410/__init__.py index 170a4e9..a4838f3 100755 --- a/apple410/__init__.py +++ b/apple410/__init__.py @@ -11,19 +11,28 @@ def plot_to_svg(instream, outstream): class Apple410: """A simple class for queing up commands for the Apple 410""" - def __init__(self, portname, baud=9600): - self.serial = serial.Serial(portname, baud, rtscts=True, dsrdtr=True, timeout=0.1) + def __init__(self, portname, baud=9600, flow_control_safe=False, cts_hack=False): + self.serial = serial.Serial(portname, baud, rtscts=False, dsrdtr=True, timeout=0.1) self.pos = (0,0) self.wd = self.vp = (0,0,2394,1759) + self.flow_control_safe = flow_control_safe + self.cts_hack = cts_hack def sendchar(self, c): - self.serial.flush() - while not self.serial.cts: - time.sleep(0.2) - while not self.serial.dsr: - time.sleep(0.2) - self.serial.write(c.encode('ascii')) - self.serial.flush() + if self.flow_control_safe: + self.serial.write(c.encode('ascii')) + elif self.cts_hack: + self.serial.flush() + while not self.serial.cts: + time.sleep(0.2) + self.serial.write(c.encode('ascii')) + self.serial.flush() + else: + self.serial.flush() + while not self.serial.dsr: + time.sleep(0.2) + self.serial.write(c.encode('ascii')) + self.serial.flush() def send(self, command): for c in command: