THZ: fix for winOS for Matthias-56 (Forum #1179774)

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@25085 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
immi 2021-10-16 19:47:25 +00:00
parent f9191b44e6
commit 6276cbf9ab

View File

@ -1539,17 +1539,28 @@ sub THZ_ReadAnswer($) {
$rtimeout = minNum($rtimeout,1.8) if (AttrVal($name, "nonblocking", "0") eq 0); # set to max 1.8s if nonblocking disabled $rtimeout = minNum($rtimeout,1.8) if (AttrVal($name, "nonblocking", "0") eq 0); # set to max 1.8s if nonblocking disabled
my $count = 0; my $countmax = 20; my $count = 0; my $countmax = 20;
while ((!defined($buf)) and ($count <= $countmax)) { while ((!defined($buf)) and ($count <= $countmax)) {
select(undef, undef, undef, 0.01) if( $^O =~ /Win/ ); ###delay of 5 ms for windows-OS, because SimpleReadWithTimeout does not wait if ($^O =~ /Win/){
select(undef, undef, undef, 0.005); ###delay of 5 ms for windows-OS, because SimpleReadWithTimeout does not wait
$buf = DevIo_DoSimpleRead($hash);
$buf = undef if (length($buf)==0);
}
else {
$buf = DevIo_SimpleReadWithTimeout($hash, (minNum($count,1)*$rtimeout/$countmax + 0.001)); ##pay attention with DevIo_SimpleRead: it closes the connection if no answe given; DevIo_SimpleReadWithTimeout does not close $buf = DevIo_SimpleReadWithTimeout($hash, (minNum($count,1)*$rtimeout/$countmax + 0.001)); ##pay attention with DevIo_SimpleRead: it closes the connection if no answe given; DevIo_SimpleReadWithTimeout does not close
#$hash->{"total_count_$count"}+=1; }
$count ++; $count ++;
} }
return ("THZ_ReadAnswer: InterfaceNotRespondig. Maybe too slow", "") if(!defined($buf)) ; return ("THZ_ReadAnswer: InterfaceNotRespondig. Maybe too slow", "") if(!defined($buf)) ;
my $data = uc(unpack('H*', $buf)); my $data = uc(unpack('H*', $buf));
$count =1; $countmax = 120; #increased to 120 for LeJoke his raspi4 is very fast reading and reaches 60 evry time $count =1; $countmax = 120; #increased to 120 for LeJoke his raspi4 is very fast reading and reaches 60 evry time
while (( (length($data) == 1) or (($data =~ m/^01/) and ($data !~ m/1003$/m ))) and ($count <= $countmax)){ while (( (length($data) == 1) or (($data =~ m/^01/) and ($data !~ m/1003$/m ))) and ($count <= $countmax)){
select(undef, undef, undef, 0.005) if( $^O =~ /Win/ ); ###delay of 5 ms for windows-OS, because SimpleReadWithTimeout does not wait my $buf1=undef;
my $buf1 = DevIo_SimpleReadWithTimeout($hash, 0.02); if ($^O =~ /Win/){
select(undef, undef, undef, 0.005); ###delay of 5 ms for windows-OS, because SimpleReadWithTimeout does not wait
$buf1 =DevIo_DoSimpleRead($hash);
}
else {
$buf1 = DevIo_SimpleReadWithTimeout($hash, 0.02);
}
Log3($hash->{NAME}, 5, "double read $count activated $data"); Log3($hash->{NAME}, 5, "double read $count activated $data");
if(defined($buf1)) { if(defined($buf1)) {
$buf .= $buf1 ; $buf .= $buf1 ;