98_Modbus.pm: smaller changes

git-svn-id: https://svn.fhem.de/fhem/trunk@19979 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
StefanStrobel 2019-08-10 12:52:27 +00:00
parent 8e6b7b834e
commit f0895e86d0

View File

@ -136,6 +136,8 @@
# 2019-04-15 add ModbusReadingsFn to allow the manipulation of readings in a derived module,
# allow parseInfo and deviceInfo in device hash with priority over module hash
# 2019-04-17 better logging
# 2019-05-11 convert multiple spaces, tabs or newlines in maps to just one blank
# 2019-06-01 fix bug where disabling tcp master results in mass log (Close, ready, close ...)
#
#
#
@ -326,7 +328,7 @@ sub ModbusLD_GetIOHash($);
sub ModbusLD_DoRequest($$$;$$$$);
sub ModbusLD_StartUpdateTimer($);
my $Modbus_Version = '4.1.2 - 17.4.2019';
my $Modbus_Version = '4.1.4 - 1.6.2019';
my $Modbus_PhysAttrs =
"queueDelay " .
"queueMax " .
@ -840,6 +842,7 @@ sub ModbusLD_Attr(@)
}
}
$hash->{".updateSetGet"} = 1;
Log3 $name, 5, "$name: attr change set updateGetSetList to 1";
if ($aName eq 'disable' && $init_done) { # if not init_done, nothing to be done here (see NotifyFN)
# disable on a logical device (not physical here!)
@ -935,8 +938,8 @@ sub ModbusLD_UpdateGetSetList($)
}
}
}
#Log3 $name, 5, "$name: UpdateSetList: setList=$hash->{'.setList'}";
#Log3 $name, 5, "$name: UpdateSetList: getList=$hash->{'.getList'}";
Log3 $name, 5, "$name: UpdateSetList: setList=$hash->{'.setList'}";
Log3 $name, 5, "$name: UpdateSetList: getList=$hash->{'.getList'}";
$hash->{".updateSetGet"} = 0;
return;
}
@ -1647,8 +1650,8 @@ sub Modbus_Close($;$$)
}
Log3 $name, 5, "$name: Close called from " . Modbus_Caller() .
($noState || $noDelete ? " with " : "") . ($noState ? "noState" : "") .
($noState && $noDelete ? " and " : "") . ($noDelete ? "noDelete" : "");
($noState || $noDelete ? " with " : "") . ($noState ? "noState" : "") . # set state?
($noState && $noDelete ? " and " : "") . ($noDelete ? "noDelete" : ""); # command delete on connection device?
delete $hash->{LASTOPEN}; # reset so next open will actually call OpenDev
if ($hash->{TCPChild}) {
@ -1676,8 +1679,9 @@ sub Modbus_Close($;$$)
delete $hash->{CONNECTHASH};
Log3 $name, 4, "$name: Close deleted CONNECTHASH";
}
} elsif (DevIo_IsOpen($hash)) {
} else {
Log3 $name, 4, "$name: Close connection with DevIo_CloseDev";
# close even if it was not open yet but on ready list (need to remove entry from readylist)
DevIo_CloseDev($hash);
}
@ -1706,7 +1710,7 @@ sub Modbus_Ready($)
if($hash->{STATE} eq "disconnected") {
if (IsDisabled($name)) {
Log3 $name, 3, "$name: ready called but $name is disabled - don't try to reconnect";
Log3 $name, 3, "$name: ready called but $name is disabled - don't try to reconnect - call Modbus_close";
Modbus_Close($hash, 1); # close, set Expect, clear Buffer, don't set state to disconnected
return;
}
@ -4971,6 +4975,8 @@ sub Modbus_MapConvert($$$;$)
my ($hash, $map, $val, $reverse) = @_;
my $name = $hash->{NAME};
$map =~ s/\s+/ /g; # substitute all \t \n etc. by one space only
if ($reverse) {
$map =~ s/([^, ][^,\$]*):([^,][^,\$]*),? */$2:$1, /g; # reverse map
}
@ -4999,8 +5005,8 @@ sub Modbus_MapToHint($)
{
my ($map) = @_;
my $hint = $map; # create hint from map
$hint =~ s/\s+/ /g; # convert spaces for fhemweb
$hint =~ s/([^,\$]+):([^,\$]+)(,?) */$2$3/g; # allow spaces in names
$hint =~ s/\s/ /g; # convert spaces for fhemweb
return $hint;
}