|
1 | 1 | # nxt.sensor module -- Classes to read LEGO Mindstorms NXT sensors |
2 | 2 | # Copyright (C) 2006,2007 Douglas P Lau |
3 | 3 | # Copyright (C) 2009 Marcus Wanner, Paulo Vieira, rhn |
4 | | -# Copyright (C) 2010 Marcus Wanner |
| 4 | +# Copyright (C) 2010,2011 Marcus Wanner |
5 | 5 | # |
6 | 6 | # This program is free software: you can redistribute it and/or modify |
7 | 7 | # it under the terms of the GNU General Public License as published by |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 | # GNU General Public License for more details. |
15 | 15 |
|
16 | | -from nxt.error import I2CError, I2CPendingError |
| 16 | +from nxt.error import I2CError, I2CPendingError, DirProtError |
17 | 17 |
|
18 | 18 | from common import * |
19 | 19 | from time import sleep, time |
@@ -128,7 +128,13 @@ def read_value(self, name): |
128 | 128 | tuples containing only one element. |
129 | 129 | """ |
130 | 130 | address, fmt = self.I2C_ADDRESS[name] |
131 | | - return self._i2c_query(address, fmt) |
| 131 | + for n in range(3): |
| 132 | + try: |
| 133 | + return self._i2c_query(address, fmt) |
| 134 | + except DirProtError: |
| 135 | + print "DEBUG: DirProtError averted!" |
| 136 | + pass |
| 137 | + raise I2CError, "read_value timeout" |
132 | 138 |
|
133 | 139 | def write_value(self, name, value): |
134 | 140 | """Writes value to the sensor. Name must be a string found in |
|
0 commit comments