diff options
Diffstat (limited to 'zerk')
-rwxr-xr-x | zerk | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -52,9 +52,7 @@ PROG_NAME = 'zerk' try: import serial except ImportError: - # treat serial as special since it is not part of standard Python - sys.stderr.write("%s: failed to import pyserial\n" % PROG_NAME) - sys.exit(2) + serial = None # Defer complaining until we know we need it. try: import gps @@ -1458,11 +1456,11 @@ class gps_io(object): ser = None input_is_device = False - def __init__(self, serial_class): + def __init__(self): "Initialize class" - Serial = serial_class - Serial_v3 = Serial.VERSION.split('.')[0] >= '3' + Serial = serial + Serial_v3 = Serial and Serial.VERSION.split('.')[0] >= '3' # buffer to hold read data self.out = b'' @@ -1536,6 +1534,9 @@ class gps_io(object): timeout=0.05, **{write_timeout_arg: 0.5} ) + except AttributeError: + sys.stderr.write('%s: failed to import pyserial\n' % PROG_NAME) + sys.exit(2) except Serial.serialutil.SerialException: # this exception happens on bad serial port device name sys.stderr.write('%s: failed to open serial port "%s"\n' @@ -1853,7 +1854,7 @@ try: sys.exit(1) # create the I/O instance - io_handle = gps_io(serial) + io_handle = gps_io() # keep it simple, only one of -O, -c -d -e or -S if opts['oaf_name'] is not None: |