Skip to content

Commit

Permalink
catch remote io error in i2c.command
Browse files Browse the repository at this point in the history
  • Loading branch information
thijstriemstra committed Mar 7, 2017
1 parent fb63197 commit 55423c1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions luma/core/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ def __init__(self, bus=None, port=1, address=0x3C):
# PermissionError
raise luma.core.error.DevicePermissionError(
'I2C device permission denied: {}'.format(e.filename))
elif e.errno == errno.EREMOTEIO:
# Remote I/O error
raise luma.core.error.DeviceNotFoundError(
'I2C device not found on address: {}'.format(address))
else: # pragma: no cover
raise

Expand All @@ -77,9 +73,20 @@ def command(self, *cmd):
:param cmd: a spread of commands
:type cmd: int
:raises luma.core.error.DeviceNotFoundError: I2C device could not be found.
"""
assert(len(cmd) <= 32)
self._bus.write_i2c_block_data(self._addr, self._cmd_mode, list(cmd))

try:
self._bus.write_i2c_block_data(self._addr, self._cmd_mode,
list(cmd))
except OSError as e:
if e.errno == errno.EREMOTEIO:
# Remote I/O error
raise luma.core.error.DeviceNotFoundError(
'I2C device not found on address: {}'.format(self._addr))
else: # pragma: no cover
raise

def data(self, data):
"""
Expand Down

0 comments on commit 55423c1

Please sign in to comment.