浏览代码

Correctly send ^D at the start of communications

Before, we sent ^D, but didn't read past the prompt that appeared.  This
put us one command behind the most recent, causing all manner of mayhem.
It's all fixed now I believe, but this really shows the need for unit
testing.  I'm working on that.
Clara Hobbs 7 年前
父节点
当前提交
c0c7a460bb
共有 1 个文件被更改,包括 11 次插入5 次删除
  1. 11
    5
      pdbuddy/__init__.py

+ 11
- 5
pdbuddy/__init__.py 查看文件

@@ -31,8 +31,7 @@ class Sink:
31 31
 
32 32
         # Put communications in a known state, cancelling any partially-entered
33 33
         # command that may be sitting in the buffer.
34
-        self._port.write("\x04".encode("utf-8"))
35
-        self._port.flush()
34
+        self.send_command("\x04", newline=False)
36 35
 
37 36
     def __enter__(self):
38 37
         return self
@@ -40,17 +39,24 @@ class Sink:
40 39
     def __exit__(self, exc_type, exc_value, traceback):
41 40
         self._port.close()
42 41
 
43
-    def send_command(self, cmd):
42
+    def send_command(self, cmd, newline=True):
44 43
         """Send a command to the PD Buddy Sink, returning the result
45 44
         
46 45
         :param cmd: the text to send to the Sink
47
-        :type sp: str
46
+        :param newline: whether to append a ``\r\n`` to the command
47
+        :type cmd: str
48
+        :type newline: bool
48 49
         
49 50
         :returns: a list of zero or more bytes objects, each being one line
50 51
             printed as a response to the command.
51 52
         """
53
+        # Build the command
54
+        cmd = cmd.encode("utf-8")
55
+        if newline:
56
+            cmd += b"\r\n"
57
+
52 58
         # Send the command
53
-        self._port.write(cmd.encode("utf-8") + b"\r\n")
59
+        self._port.write(cmd)
54 60
         self._port.flush()
55 61
 
56 62
         # Read the result

正在加载...
取消
保存