From 2b9838f1907a1b9d00e89410fdca31836e37150d Mon Sep 17 00:00:00 2001 From: borisneubert Date: Sat, 28 Jan 2017 15:43:00 +0000 Subject: [PATCH] 66_ECMD: new attribute autoReopen git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@13257 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- CHANGED | 3 ++- FHEM/66_ECMD.pm | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGED b/CHANGED index 13b30c6d2..83ad6b362 100644 --- a/CHANGED +++ b/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. -# Do not insert empty lines here, update check depends on it. +# Do not ins - feature: 66_ECMD: new attribute autoReopen + - feature: 66_ECMD: new attribute autoReopen - bugfix: 98_DOIFtools.pm: fixed bug from last change - update: 98_DOIFtools.pm: some code rework - update: 98_DOIFtools.pm: dynamic column width in report diff --git a/FHEM/66_ECMD.pm b/FHEM/66_ECMD.pm index b842ee76b..d1bb74925 100644 --- a/FHEM/66_ECMD.pm +++ b/FHEM/66_ECMD.pm @@ -86,7 +86,7 @@ ECMD_Initialize($) $hash->{GetFn} = "ECMD_Get"; $hash->{SetFn} = "ECMD_Set"; $hash->{AttrFn} = "ECMD_Attr"; - $hash->{AttrList}= "classdefs split logTraffic:0,1,2,3,4,5 timeout partial requestSeparator responseSeparator"; + $hash->{AttrList}= "classdefs split logTraffic:0,1,2,3,4,5 timeout partial requestSeparator responseSeparator autoReopen"; } ##################################### @@ -623,6 +623,19 @@ ECMD_Write($$$) { my ($hash,$msg,$expect) = @_; my $name= $hash->{NAME}; + + my $lastWrite= defined($hash->{fhem}{".lastWrite"}) ? $hash->{fhem}{".lastWrite"} : 0; + my $now= gettimeofday(); + + my $autoReopen= AttrVal($name, "autoReopen", undef); + if(defined($autoReopen)) { + my ($timeout,$delay)= split(',',$autoReopen); + ECMD_Reopen($hash) if($now>$lastWrite+$timeout); + sleep($delay); + } + + $hash->{fhem}{".lastWrite"}= $now; + my $answer; my $ret= ""; my $requestSeparator= $hash->{fhem}{".requestSeparator"}; @@ -802,6 +815,10 @@ ECMD_Write($$$) The response separator is only appended to commands split by means of a request separator. The default is to have no response separator, i.e. responses are simply concatenated. Use a response separator that does not occur in the actual response. +
  • autoReopen <timeout>,<delay>
    + If this attribute is set, the device is automatically reopened if no bytes were written for <timeout> seconds or more. After reopening + FHEM waits <delay> seconds before writing to the device. Use the delay with care because it stalls FHEM completely. +
  • verbose