Parcourir la source

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 il y a 7 ans
Parent
révision
5e7239e70c
1 fichiers modifiés avec 6 ajouts et 3 suppressions
  1. 6
    3
      pdbuddy/__init__.py

+ 6
- 3
pdbuddy/__init__.py Voir le fichier

17
         Parameters:
17
         Parameters:
18
             sp: A serial.tools.list_ports.ListPortInfo object
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
     def send_command(self, cmd):
22
     def send_command(self, cmd):
23
         """Send a command to the PD Buddy Sink, returning the result
23
         """Send a command to the PD Buddy Sink, returning the result
30
             as a response to the command.
30
             as a response to the command.
31
         """
31
         """
32
         # Send the command
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
         self.port.flush()
34
         self.port.flush()
35
 
35
 
36
         # Read the result
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
         # Remove the echoed command and prompt
42
         # Remove the echoed command and prompt
40
         answer = answer[1:-1]
43
         answer = answer[1:-1]

Chargement…
Annuler
Enregistrer