Ver código fonte

Remove timeout for serial port

The timeout was a dirty hack from the start.  It was long enough that
commands have finished running by the time it completes, but it wasn't
the right way to see when a command finished running.  The right way is
to look for the PDBS) prompt, which is what we do now.

This makes the Sink.set_tmpcfg method run noticeably faster.  Neat.
Clara Hobbs 7 anos atrás
pai
commit
5e7239e70c
1 arquivos alterados com 6 adições e 3 exclusões
  1. 6
    3
      pdbuddy/__init__.py

+ 6
- 3
pdbuddy/__init__.py Ver arquivo

@@ -17,7 +17,7 @@ class Sink:
17 17
         Parameters:
18 18
             sp: A serial.tools.list_ports.ListPortInfo object
19 19
         """
20
-        self.port = serial.Serial(sp.device, baudrate=115200, timeout=0.01)
20
+        self.port = serial.Serial(sp.device, baudrate=115200)
21 21
 
22 22
     def send_command(self, cmd):
23 23
         """Send a command to the PD Buddy Sink, returning the result
@@ -30,11 +30,14 @@ class Sink:
30 30
             as a response to the command.
31 31
         """
32 32
         # Send the command
33
-        self.port.write(bytes(cmd, 'utf-8') + b'\r\n')
33
+        self.port.write(bytes(cmd, "utf-8") + b"\r\n")
34 34
         self.port.flush()
35 35
 
36 36
         # Read the result
37
-        answer = self.port.readlines()
37
+        answer = b""
38
+        while not answer.endswith(b"PDBS) "):
39
+            answer += self.port.read(1)
40
+        answer = answer.split(b"\r\n")
38 41
 
39 42
         # Remove the echoed command and prompt
40 43
         answer = answer[1:-1]

Carregando…
Cancelar
Salvar