Commit c0c9a4b1530ecac17a5dea542f18560233d3efb6
1 parent
51707558
Exists in
master
Migrated serial port selection to gui dialogue
Showing
1 changed file
with
6 additions
and
13 deletions
Show diff stats
robots/little_john/telemetry/code/monitor/serialselect.py
| @@ -6,6 +6,7 @@ def selectserial(): | @@ -6,6 +6,7 @@ def selectserial(): | ||
| 6 | import platform | 6 | import platform |
| 7 | import serial | 7 | import serial |
| 8 | import os | 8 | import os |
| 9 | + import easygui | ||
| 9 | 10 | ||
| 10 | devpatterns = ['ttyACM', 'ttyUSB', 'rfcomm'] | 11 | devpatterns = ['ttyACM', 'ttyUSB', 'rfcomm'] |
| 11 | targetdevs = [] | 12 | targetdevs = [] |
| @@ -34,21 +35,13 @@ def selectserial(): | @@ -34,21 +35,13 @@ def selectserial(): | ||
| 34 | print("Found multiple serial devices: ") | 35 | print("Found multiple serial devices: ") |
| 35 | for i, dev in enumerate(targetdevs): | 36 | for i, dev in enumerate(targetdevs): |
| 36 | print(" " + str(i) + ": " + dev) | 37 | print(" " + str(i) + ": " + dev) |
| 37 | - while True: | ||
| 38 | - try: | ||
| 39 | - selection = int(input("Please enter your selection (as a digit):\n > ")) | ||
| 40 | - if selection >= 0 and selection < len(targetdevs): | ||
| 41 | - break | ||
| 42 | - except KeyboardInterrupt: | ||
| 43 | - sys.exit() | ||
| 44 | - except: | ||
| 45 | - print("Choice unrecognised: please try again:") | 38 | + message = "Please choose a serial port to recieve data through:" |
| 39 | + title = "Found multiple serial ports!" | ||
| 40 | + serialport = easygui.choicebox(message, title, targetdevs) | ||
| 46 | else: | 41 | else: |
| 47 | print("Only found one likely serial device: " + targetdevs[0]) | 42 | print("Only found one likely serial device: " + targetdevs[0]) |
| 48 | - selection = 0 | ||
| 49 | - | ||
| 50 | - serialport=targetdevs[selection] | ||
| 51 | - | 43 | + serialport = targetdevs[0] |
| 44 | + | ||
| 52 | 45 | ||
| 53 | try: | 46 | try: |
| 54 | datafeed = serial.Serial( | 47 | datafeed = serial.Serial( |