We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents d86fc7e + aea9d07 commit d8de432Copy full SHA for d8de432
adafruit_bus_device/i2c_device.py
@@ -56,14 +56,24 @@ class I2CDevice:
56
with device:
57
device.write(bytes_read)
58
"""
59
+
60
def __init__(self, i2c, device_address):
- # Verify that a device with that address exists.
61
+ """
62
+ Try to read a byte from an address,
63
+ if you get an OSError it means the device is not there
64
65
while not i2c.try_lock():
66
pass
67
try:
68
i2c.writeto(device_address, b'')
69
except OSError:
- raise ValueError("No I2C device at address: %x" % device_address)
70
+ # some OS's dont like writing an empty bytesting...
71
+ # Retry by reading a byte
72
+ try:
73
+ result = bytearray(1)
74
+ i2c.readfrom_into(device_address, result)
75
+ except OSError:
76
+ raise ValueError("No I2C device at address: %x" % device_address)
77
finally:
78
i2c.unlock()
79
0 commit comments