Created
April 3, 2015 17:21
-
-
Save bruceravel/207ea6b0a53eb091ba8c to your computer and use it in GitHub Desktop.
call bus.read_i2c_block_data with exception handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_i2c_block(address): | |
number = -1 | |
count = 0 | |
count_max = 10 | |
while True: | |
count = count + 1 | |
if count > count_max: break | |
try: | |
number = bus.read_i2c_block_data(address, 1) | |
break | |
except IOError: | |
time.sleep(0.2) | |
continue | |
return number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment