|
@@ -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
|