2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-22 08:11:44 +00:00

98_autocreate.pm: usb scan fixes (Forum #100054)

git-svn-id: https://svn.fhem.de/fhem/trunk@19372 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2019-05-11 15:13:59 +00:00
parent d0c464f0d9
commit e3fd2c73ee
2 changed files with 9 additions and 9 deletions

View File

@ -531,8 +531,8 @@ my @usbtable = (
matchList => ["cu.usbserial(.*)", "cu.usbmodem(.*)", matchList => ["cu.usbserial(.*)", "cu.usbmodem(.*)",
"ttyUSB(.*)", "ttyACM(.*)", "ttyAMA(.*)"], "ttyUSB(.*)", "ttyACM(.*)", "ttyAMA(.*)"],
DeviceName=> "DEVICE\@19200", DeviceName=> "DEVICE\@19200",
timeout => 1.1, timeout => 1.0, # msg every second
maxLen => 32, maxLen => 127, # max packet ist 64 bytes
response => "[GW][+-][0-9]{2}\.[0-9]{7}[JN][0-9]{5}". response => "[GW][+-][0-9]{2}\.[0-9]{7}[JN][0-9]{5}".
"\.[0-9][JN].*[0-9]{4}\x03", "\.[0-9][JN].*[0-9]{4}\x03",
define => "ElsnerWS_PARAM ElsnerWS comtype=rs485 ". define => "ElsnerWS_PARAM ElsnerWS comtype=rs485 ".
@ -650,8 +650,8 @@ CommandUsb($$)
$answer = DevIo_TimeoutRead($hash, 0.1); $answer = DevIo_TimeoutRead($hash, 0.1);
} elsif($thash->{timeout} && $thash->{maxLen}) { } elsif($thash->{timeout} && $thash->{maxLen}) {
$answer = DevIo_TimeoutRead($hash, $answer = DevIo_TimeoutRead($hash, $thash->{timeout},
$thash->{timeout}, $thash->{maxLen}); $thash->{maxLen}, $thash->{response});
} }
if(AttrVal("global", "verbose", 0) >= 5) { if(AttrVal("global", "verbose", 0) >= 5) {

View File

@ -10,7 +10,7 @@ sub DevIo_SetHwHandshake($);
sub DevIo_SimpleRead($); sub DevIo_SimpleRead($);
sub DevIo_SimpleReadWithTimeout($$); sub DevIo_SimpleReadWithTimeout($$);
sub DevIo_SimpleWrite($$$;$); sub DevIo_SimpleWrite($$$;$);
sub DevIo_TimeoutRead($$;$); sub DevIo_TimeoutRead($$;$$);
sub sub
DevIo_setStates($$) DevIo_setStates($$)
@ -100,9 +100,9 @@ DevIo_SimpleReadWithTimeout($$)
# NOTE1: FHEM WILL be blocked for $timeout seconds, DO NOT USE IT! # NOTE1: FHEM WILL be blocked for $timeout seconds, DO NOT USE IT!
# NOTE2: This works on Windows only for TCP connections # NOTE2: This works on Windows only for TCP connections
sub sub
DevIo_TimeoutRead($$;$) DevIo_TimeoutRead($$;$$)
{ {
my ($hash, $timeout, $maxlen) = @_; my ($hash, $timeout, $maxlen, $regexp) = @_;
my $answer = ""; my $answer = "";
$timeout = 1 if(!$timeout); $timeout = 1 if(!$timeout);
@ -111,11 +111,11 @@ DevIo_TimeoutRead($$;$)
my $rin = ""; my $rin = "";
vec($rin, $hash->{FD}, 1) = 1; vec($rin, $hash->{FD}, 1) = 1;
my $nfound = select($rin, undef, undef, $timeout); my $nfound = select($rin, undef, undef, $timeout);
last if($nfound <= 0); last if($nfound <= 0); # timeout
my $r = DevIo_DoSimpleRead($hash); my $r = DevIo_DoSimpleRead($hash);
last if(!defined($r) || ($r == "" && $hash->{TCPDev})); last if(!defined($r) || ($r == "" && $hash->{TCPDev}));
$answer .= $r; $answer .= $r;
last if(length($anser) >= $maxlen); last if(length($anser) >= $maxlen || ($regexp && $answer =~ m/$regexp/));
} }
return $answer; return $answer;
} }