arcs

Amateur Radio Chat Server with a modern interface
git clone git://squid-tech.com/arcs.git
Log | Files | Refs | README

commit 258a0bd32192c7b872aa6c0102565469c5179ae2
parent b4c6bf198ba2840d01f2548db4196e45db7975dd
Author: Josh Moore <jxm5210@g.rit.edu>
Date:   Sun, 22 Dec 2019 17:33:27 -0500

Merge pull request #2 from rouyng/handle-args

Add some error handling and usage message
Diffstat:
Marcs.py | 26++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/arcs.py b/arcs.py @@ -408,6 +408,12 @@ def main(): global _SERVER global _DEBUG + usage = """Usage: python3 arcs.py serial_tnc_path baud_rate [-server] [-debug] + \tserial_tnc_path: serial port connected to KISS TNC + \tbaud_rate: baud rate of connection to KISS TNC, default value for direwolf is 115200 + \t-server (optional): Use if running your own arcs server + \t-debug (optional): Enable verbose debug mode""" + if "-server" in sys.argv: _SERVER = True @@ -415,10 +421,22 @@ def main(): _DEBUG = True # initialize serial port - ser = serial.Serial( - port=sys.argv[1], - baudrate=sys.argv[2] - ) + try: + ser = serial.Serial( + port=sys.argv[1], + baudrate=sys.argv[2] + ) + except IndexError: + print('Error: missing arguments') + print(usage) + sys.exit(1) + except ValueError: + print('Invalid value for port or baud rate') + print(usage) + sys.exit(1) + except serial.serialutil.SerialException as e: + print(f'Error while opening serial connection to TNC: \n{e}') + sys.exit(1) # initialize the KISS TNC KISSinit(ser)