From e900dae226203d8d99f6fd7ce068ef7e50ee6bd3 Mon Sep 17 00:00:00 2001 From: Fred Wright Date: Sat, 17 Nov 2018 14:11:36 -0800 Subject: Fixes ubxtool and zerk in direct-serial mode. The attempted workaround for the writeTimeout->write_timeout change in serial.Serial() didn't work, since including the unexpected "alternate" keyword argument caused an error. This was observed with both V2.7 and V3.0 of pySerial, so it's not clear how this code ever worked for anyone. It now uses only the correct argument name. There are two other deprecated items, inWaiting and flushInput, but these have not yet been removed in V3.0, so those are not yet fixed (other than the comments). TESTED: Ran "ubxtool -p VER ..." against a u-Blox LEA-M8T in direct-serial mode, with pySerial both 2.7 and 3.0. Did not test zerk, due to the lack of appropriate hardware, but its changes are identical to those in ubxtool. --- zerk | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'zerk') diff --git a/zerk b/zerk index b630c636..9041b123 100755 --- a/zerk +++ b/zerk @@ -1462,6 +1462,7 @@ class gps_io(object): "Initialize class" Serial = serial_class + Serial_v3 = Serial.VERSION.split('.')[0] >= '3' # buffer to hold read data self.out = b'' @@ -1520,6 +1521,9 @@ class gps_io(object): # configure the serial connections (the parameters refer to # the device you are connecting to) + # pyserial Ver 3.0+ changes writeTimeout to write_timeout + # Using the wrong one causes an error + write_timeout_arg = 'write_timeout' if Serial_v3 else 'writeTimeout' try: self.ser = Serial.Serial( baudrate=opts['input_speed'], @@ -1530,10 +1534,7 @@ class gps_io(object): stopbits=Serial.STOPBITS_ONE, # read timeout timeout=0.05, - # pyserial Ver 3.0+ changes writeTimeout to write_timeout - # just set both - write_timeout=0.5, - writeTimeout=0.5, + **{write_timeout_arg: 0.5} ) except Serial.serialutil.SerialException: # this exception happens on bad serial port device name @@ -1550,6 +1551,8 @@ class gps_io(object): sys.exit(1) # flush input buffer, discarding all its contents + # pyserial 3.0+ deprecates flushInput() in favor of + # reset_input_buffer(), but flushInput() is still present. self.ser.flushInput() else: @@ -1606,7 +1609,8 @@ class gps_io(object): while read_opts['input_wait'] > (time.clock() - start): # First priority is to be sure the input buffer is read. # This is to prevent input buffer overuns - # pyserial 3.0 replaces inWaiting() with in_waiting + # pyserial 3.0+ deprecates inWaiting() in favor of + # in_waiting, but inWaiting() is still present. if 0 < self.ser.inWaiting(): # We have serial input waiting, get it # 1024 is comfortably large, almost always the -- cgit v1.2.1