From 7e0f3dec7226c93beea107582fdd1938015563f2 Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Sat, 11 May 2019 15:13:59 +0000 Subject: [PATCH] 98_autocreate.pm: usb scan fixes (Forum #100054) git-svn-id: https://svn.fhem.de/fhem/trunk@19372 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_autocreate.pm | 8 ++++---- fhem/FHEM/DevIo.pm | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fhem/FHEM/98_autocreate.pm b/fhem/FHEM/98_autocreate.pm index 504b64c21..5f2f1d036 100644 --- a/fhem/FHEM/98_autocreate.pm +++ b/fhem/FHEM/98_autocreate.pm @@ -531,8 +531,8 @@ my @usbtable = ( matchList => ["cu.usbserial(.*)", "cu.usbmodem(.*)", "ttyUSB(.*)", "ttyACM(.*)", "ttyAMA(.*)"], DeviceName=> "DEVICE\@19200", - timeout => 1.1, - maxLen => 32, + timeout => 1.0, # msg every second + maxLen => 127, # max packet ist 64 bytes response => "[GW][+-][0-9]{2}\.[0-9]{7}[JN][0-9]{5}". "\.[0-9][JN].*[0-9]{4}\x03", define => "ElsnerWS_PARAM ElsnerWS comtype=rs485 ". @@ -650,8 +650,8 @@ CommandUsb($$) $answer = DevIo_TimeoutRead($hash, 0.1); } elsif($thash->{timeout} && $thash->{maxLen}) { - $answer = DevIo_TimeoutRead($hash, - $thash->{timeout}, $thash->{maxLen}); + $answer = DevIo_TimeoutRead($hash, $thash->{timeout}, + $thash->{maxLen}, $thash->{response}); } if(AttrVal("global", "verbose", 0) >= 5) { diff --git a/fhem/FHEM/DevIo.pm b/fhem/FHEM/DevIo.pm index 58c4883ee..4753ec427 100644 --- a/fhem/FHEM/DevIo.pm +++ b/fhem/FHEM/DevIo.pm @@ -10,7 +10,7 @@ sub DevIo_SetHwHandshake($); sub DevIo_SimpleRead($); sub DevIo_SimpleReadWithTimeout($$); sub DevIo_SimpleWrite($$$;$); -sub DevIo_TimeoutRead($$;$); +sub DevIo_TimeoutRead($$;$$); sub DevIo_setStates($$) @@ -100,9 +100,9 @@ DevIo_SimpleReadWithTimeout($$) # NOTE1: FHEM WILL be blocked for $timeout seconds, DO NOT USE IT! # NOTE2: This works on Windows only for TCP connections sub -DevIo_TimeoutRead($$;$) +DevIo_TimeoutRead($$;$$) { - my ($hash, $timeout, $maxlen) = @_; + my ($hash, $timeout, $maxlen, $regexp) = @_; my $answer = ""; $timeout = 1 if(!$timeout); @@ -111,11 +111,11 @@ DevIo_TimeoutRead($$;$) my $rin = ""; vec($rin, $hash->{FD}, 1) = 1; my $nfound = select($rin, undef, undef, $timeout); - last if($nfound <= 0); + last if($nfound <= 0); # timeout my $r = DevIo_DoSimpleRead($hash); last if(!defined($r) || ($r == "" && $hash->{TCPDev})); $answer .= $r; - last if(length($anser) >= $maxlen); + last if(length($anser) >= $maxlen || ($regexp && $answer =~ m/$regexp/)); } return $answer; }