diff options
author | Fred Wright <fw@fwright.net> | 2018-11-17 14:11:36 -0800 |
---|---|---|
committer | Fred Wright <fw@fwright.net> | 2018-11-17 14:11:36 -0800 |
commit | e900dae226203d8d99f6fd7ce068ef7e50ee6bd3 (patch) | |
tree | 09f32814c3875de3a6650b8acb2492fdaff307d2 | |
parent | 9214a397bc58ec7d932780b4e160360b950fc042 (diff) | |
download | gpsd-e900dae226203d8d99f6fd7ce068ef7e50ee6bd3.tar.gz |
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.
-rwxr-xr-x | ubxtool | 14 | ||||
-rwxr-xr-x | zerk | 14 |
2 files changed, 18 insertions, 10 deletions
@@ -2068,6 +2068,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'' @@ -2127,6 +2128,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'], @@ -2137,10 +2141,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 @@ -2158,6 +2159,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: @@ -2214,7 +2217,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 @@ -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 |