[chirp_devel] Patch for #7119 BF-888 "Refused to enter programming mode."

Nicklas Lindgren
Sat Dec 28 07:38:50 PST 2019


Hi,

Here is a new patch, which modifies the serial timeout only in the
specific instances where it is required.

-- 
Nicklas
59D8 27AD 2632 F349 9B20  F5CB D363 3177 0A12 1B95
-------------- next part --------------
# HG changeset patch
# User Nicklas Lindgren <nili at modio.se>
# Date 1577547181 -3600
#      Sat Dec 28 16:33:01 2019 +0100
# Node ID bfb2dee6e956ff0982629e005c253ec275914367
# Parent  b5589aa94c1e6a424d0f713017f68d39caa29be9
[h777] Increase some serial timeouts #7119

This solves the BF-888 refused to enter programming mode problem in
some cases where more time is needed waiting for radio identification
data.

This change also increases the timeout when uploading data blocks,
which is required for some individual radios.

diff --git a/chirp/drivers/h777.py b/chirp/drivers/h777.py
--- a/chirp/drivers/h777.py
+++ b/chirp/drivers/h777.py
@@ -109,11 +109,19 @@
     elif ack != CMD_ACK:
         raise errors.RadioError("Radio refused to enter programming mode")
 
+    original_timeout = serial.timeout
     try:
         serial.write("\x02")
+        # At least one version of the Baofeng BF-888S has a consistent
+        # ~0.33s delay between sending the first five bytes of the
+        # version data and the last three bytes. We need to raise the
+        # timeout so that the read doesn't finish early.
+        serial.timeout = 0.5
         ident = serial.read(8)
     except:
         raise errors.RadioError("Error communicating with radio")
+    finally:
+        serial.timeout = original_timeout
 
     if not ident.startswith("P3107"):
         LOG.debug(util.hexprint(ident))
@@ -172,13 +180,20 @@
     LOG.debug("Writing Data:")
     LOG.debug(util.hexprint(cmd + data))
 
+    original_timeout = serial.timeout
     try:
         serial.write(cmd + data)
+        # Time required to write data blocks varies between individual
+        # radios of the Baofeng BF-888S model. The longest seen is
+        # ~0.31s.
+        serial.timeout = 0.5
         if serial.read(1) != CMD_ACK:
             raise Exception("No ACK")
     except:
         raise errors.RadioError("Failed to send block "
                                 "to radio at %04x" % block_addr)
+    finally:
+        serial.timeout = original_timeout
 
 
 def do_download(radio):


More information about the chirp_devel mailing list