From f4e35f935ebdd37c09f2e5976fe914e382d15bb7 Mon Sep 17 00:00:00 2001 From: ntruchsess <> Date: Mon, 21 Apr 2014 12:20:32 +0000 Subject: [PATCH] OWX_SER: fix hang in initialization when DS2480 does not respond to initial reset git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@5592 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/OWX_DS2480.pm | 4 ++-- FHEM/OWX_SER.pm | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/FHEM/OWX_DS2480.pm b/FHEM/OWX_DS2480.pm index a77b1cf17..ed28911f7 100644 --- a/FHEM/OWX_DS2480.pm +++ b/FHEM/OWX_DS2480.pm @@ -129,7 +129,7 @@ sub read() { return undef unless (defined $hwdevice); #-- read the data - looping for slow devices suggested by Joachim Herold - my ($count_in, $string_part) = $hwdevice->read(48); + my ($count_in, $string_part) = $hwdevice->read(255); return undef if (not defined $count_in or not defined $string_part); $serial->{string_in} .= $string_part; $serial->{retcount} += $count_in; @@ -153,7 +153,7 @@ sub response_ready() { sub start_query() { my ($serial) = @_; #read and discard any outstanding data from previous commands: - while($serial->read()) {}; + while($serial->read(255)) {}; $serial->{string_in} = ""; $serial->{num_reads} = 0; diff --git a/FHEM/OWX_SER.pm b/FHEM/OWX_SER.pm index d04b1ede5..d4152bc03 100644 --- a/FHEM/OWX_SER.pm +++ b/FHEM/OWX_SER.pm @@ -66,7 +66,7 @@ sub new() { $self->{pt_verify} = PT_THREAD(\&pt_verify); $self->{pt_execute} = PT_THREAD(\&pt_execute); - $self->{timeout} = [1,0]; #default timeout 1 sec. + $self->{timeout} = 1.0; #default timeout 1 sec. return bless $self,$class; } @@ -268,6 +268,7 @@ sub initialize($) { } else { main::Log3($hash->{NAME},1,$msg." defined"); } + $hwdevice->reset_error(); $hwdevice->baudrate(9600); $hwdevice->databits(8); @@ -277,7 +278,14 @@ sub initialize($) { $hwdevice->write_settings; #-- store with OWX device $self->{hwdevice} = $hwdevice; - + + #force master reset in DS2480 + $hwdevice->purge_all; + $hwdevice->baudrate(4800); + $hwdevice->write_settings; + $hwdevice->write(sprintf("\x00")); + select(undef,undef,undef,0.5); + #-- Third step detect busmaster on serial interface my $name = $self->{name}; @@ -292,18 +300,22 @@ sub initialize($) { #-- timing byte for DS2480 $ds2480->start_query(); $ds2480->query("\xC1",1); - do { - $ds2480->read(); - } while (!$ds2480->response_ready()); + eval { #ignore timeout + do { + $ds2480->read(); + } while (!$ds2480->response_ready()); + }; #-- Max 4 tries to detect an interface for($l=0;$l<100;$l++) { #-- write 1-Wire bus (Fig. 2 of Maxim AN192) $ds2480->start_query(); $ds2480->query("\x17\x45\x5B\x0F\x91",5); - do { - $ds2480->read(); - } while (!$ds2480->response_ready()); + eval { #ignore timeout + do { + $ds2480->read(); + } while (!$ds2480->response_ready()); + }; $res = $ds2480->{string_in}; #-- process 4/5-byte string for detection if( !defined($res)){ @@ -347,6 +359,7 @@ sub initialize($) { } } $self->{interface} = $interface; + main::Log3($hash->{NAME},1, $ress); if ($interface eq "DS2480") { return $ds2480; } elsif ($interface eq "DS9097") {