From 47f13345d8beb8547d5944d2792feb07e1f430b9 Mon Sep 17 00:00:00 2001 From: robotmad Date: Tue, 20 Aug 2024 21:45:02 +0100 Subject: [PATCH] exception handling for hexpansion I2C --- modules/lib/eeprom_i2c.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/lib/eeprom_i2c.py b/modules/lib/eeprom_i2c.py index 2b7b86b..733a439 100644 --- a/modules/lib/eeprom_i2c.py +++ b/modules/lib/eeprom_i2c.py @@ -98,10 +98,20 @@ def readwrite(self, addr, buf, read): # Offset address into chip: one or two bytes vaddr = self._addrbuf[1:] if self._onebyte else self._addrbuf if read: - self._i2c.writeto(self._i2c_addr, vaddr) - self._i2c.readfrom_into(self._i2c_addr, mvb[start : start + npage]) + try: + self._i2c.writeto(self._i2c_addr, vaddr) + self._i2c.readfrom_into(self._i2c_addr, mvb[start : start + npage]) + except OSError: + # failure - possibly a hexpansion has been removed + nbytes = 0 else: - self._i2c.writevto(self._i2c_addr, (vaddr, buf[start : start + npage])) + try: + self._i2c.writevto( + self._i2c_addr, (vaddr, buf[start : start + npage]) + ) + except OSError: + # failure - possibly a hexpansion has been removed + nbytes = 0 self._wait_rdy() nbytes -= npage start += npage