2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 01:09:47 +00:00

OWX_SER: fix hang in initialization when DS2480 does not respond to initial reset

git-svn-id: https://svn.fhem.de/fhem/trunk@5592 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
ntruchsess 2014-04-21 12:20:32 +00:00
parent 8fbe9d6070
commit 8e88412f73
2 changed files with 23 additions and 10 deletions

View File

@ -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;

View File

@ -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") {