From 16c40e17f2a5e67a93f56b3cd7fb7539203ce3eb Mon Sep 17 00:00:00 2001 From: klauswitt <> Date: Fri, 28 Mar 2014 23:03:51 +0000 Subject: [PATCH] added try handling to hardware access removed altitude from readings git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@5359 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/51_I2C_BMP180.pm | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/FHEM/51_I2C_BMP180.pm b/FHEM/51_I2C_BMP180.pm index 27a9adb84..31437910e 100644 --- a/FHEM/51_I2C_BMP180.pm +++ b/FHEM/51_I2C_BMP180.pm @@ -36,7 +36,7 @@ use warnings; use Time::HiRes qw(usleep); use Scalar::Util qw(looks_like_number); -#use Error qw(:try); +use Error qw(:try); use constant { BMP180_I2C_ADDRESS => '0x77', @@ -357,7 +357,7 @@ sub I2C_BMP180_GetPress ($$) { readingsBulkUpdate($hash, 'temperature', $temperature); readingsBulkUpdate($hash, 'pressure', $pressure); readingsBulkUpdate($hash, 'pressure-nn', $pressureNN); - readingsBulkUpdate($hash, 'altitude', $altitude, 0); + #readingsBulkUpdate($hash, 'altitude', $altitude, 0); readingsEndUpdate($hash, 1); } @@ -418,14 +418,18 @@ sub I2C_BMP180_readUncompensatedPressure($$) { sub I2C_BMP180_i2cread($$$) { my ($hash, $reg, $nbyte) = @_; if ($hash->{HiPi_used}) { - my @values = $hash->{devBPM180}->bus_read($reg, $nbyte); - I2C_BMP180_I2CRec($hash, { - direction => "i2cread", - i2caddress => $hash->{I2C_Address}, - reg => $reg, - nbyte => $nbyte, - received => join (' ',@values), - }); + try { + my @values = $hash->{devBPM180}->bus_read($reg, $nbyte); + I2C_BMP180_I2CRec($hash, { + direction => "i2cread", + i2caddress => $hash->{I2C_Address}, + reg => $reg, + nbyte => $nbyte, + received => join (' ',@values), + }); + } catch Error with { + Log3 ($hash, 1, ': ERROR: '. $hash->{NAME} . ': i2c-bus_read failure'); + }; } else { if (defined (my $iodev = $hash->{IODev})) { CallFn($iodev->{NAME}, "I2CWrtFn", $iodev, { @@ -443,13 +447,17 @@ sub I2C_BMP180_i2cread($$$) { sub I2C_BMP180_i2cwrite($$$) { my ($hash, $reg, @data) = @_; if ($hash->{HiPi_used}) { - $hash->{devBPM180}->bus_write($reg, join (' ',@data)); - I2C_BMP180_I2CRec($hash, { - direction => "i2cwrite", - i2caddress => $hash->{I2C_Address}, - reg => $reg, - data => join (' ',@data), - }); + try { + $hash->{devBPM180}->bus_write($reg, join (' ',@data)); + I2C_BMP180_I2CRec($hash, { + direction => "i2cwrite", + i2caddress => $hash->{I2C_Address}, + reg => $reg, + data => join (' ',@data), + }); + } catch Error with { + Log3 ($hash, 1, ': ERROR: ' . $hash->{NAME} . ': i2c-bus_write failure'); + }; } else { if (defined (my $iodev = $hash->{IODev})) { CallFn($iodev->{NAME}, "I2CWrtFn", $iodev, {