mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
44_S7:disable attribute added
git-svn-id: https://svn.fhem.de/fhem/trunk@20795 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
9619fcb298
commit
c6718e153a
@ -57,7 +57,7 @@ sub S7_Initialize($) { #S5_OK
|
||||
$hash->{SetFn} = "S7_Set";
|
||||
|
||||
$hash->{AttrFn} = "S7_Attr";
|
||||
$hash->{AttrList} = "MaxMessageLength Intervall receiveTimeoutMs " . $readingFnAttributes;
|
||||
$hash->{AttrList} = "disable:0,1 MaxMessageLength Intervall receiveTimeoutMs " . $readingFnAttributes;
|
||||
|
||||
# $hash->{AttrList} = join( " ", @areasconfig )." PLCTime";
|
||||
}
|
||||
@ -248,11 +248,11 @@ sub S7_Define($$) { # S5 OK
|
||||
$hash->{STATE} = "disconnected";
|
||||
main::readingsSingleUpdate( $hash, "state", "disconnected", 1 );
|
||||
|
||||
S7_connect($hash);
|
||||
|
||||
InternalTimer( gettimeofday() + $hash->{Interval},
|
||||
"S7_GetUpdate", $hash, 0 );
|
||||
|
||||
if (!S7_isDisabled($hash)) {
|
||||
S7_connect($hash);
|
||||
InternalTimer( gettimeofday() + $hash->{Interval},
|
||||
"S7_GetUpdate", $hash, 0 );
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
@ -339,9 +339,18 @@ sub S7_Attr(@) {
|
||||
$hash->{S7PLCClient}->setRecvTimeout($hash->{receiveTimeoutMs}) if ( defined( $hash->{S7PLCClient} ) );
|
||||
}
|
||||
|
||||
} elsif ($aName eq "disable") {
|
||||
if ($aVal == 1 && $attr{$name}{disable}==0) {
|
||||
#disconnection will be done by the update timer
|
||||
|
||||
} elsif ($aVal == 0 && $attr{$name}{disable}==1) {
|
||||
#reconnect
|
||||
S7_reconnect($hash);
|
||||
InternalTimer( gettimeofday() + $hash->{Interval} + 3,
|
||||
"S7_GetUpdate", $hash, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
###########
|
||||
|
||||
if ( $aName eq "WriteInputs-Config"
|
||||
@ -787,16 +796,18 @@ sub S7_GetUpdate($) {
|
||||
|
||||
my $res = S7_readFromPLC($hash);
|
||||
|
||||
if ( $res == 0 ) {
|
||||
InternalTimer( gettimeofday() + $hash->{Interval},
|
||||
"S7_GetUpdate", $hash, 1 );
|
||||
}
|
||||
else {
|
||||
if (!S7_isDisabled($hash)) {
|
||||
if ( $res == 0 ) {
|
||||
InternalTimer( gettimeofday() + $hash->{Interval},
|
||||
"S7_GetUpdate", $hash, 1 );
|
||||
}else {
|
||||
|
||||
#an error has occoured --> 10sec break
|
||||
InternalTimer( gettimeofday() + 10, "S7_GetUpdate", $hash, 1 );
|
||||
#an error has occoured --> 10sec break
|
||||
InternalTimer( gettimeofday() + 10, "S7_GetUpdate", $hash, 1 );
|
||||
}
|
||||
} else {
|
||||
S7_disconnect($hash);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#####################################
|
||||
@ -1115,6 +1126,14 @@ sub S7_readFromPLC($) { #S5 OK
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub S7_isDisabled($) {
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
return $attr{$name}{disable} == 1 if (defined ($attr{$name}{disable}));
|
||||
return 0;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user