mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +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/fhem@5592 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
7fa4645608
commit
f4e35f935e
@ -129,7 +129,7 @@ sub read() {
|
|||||||
return undef unless (defined $hwdevice);
|
return undef unless (defined $hwdevice);
|
||||||
|
|
||||||
#-- read the data - looping for slow devices suggested by Joachim Herold
|
#-- 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);
|
return undef if (not defined $count_in or not defined $string_part);
|
||||||
$serial->{string_in} .= $string_part;
|
$serial->{string_in} .= $string_part;
|
||||||
$serial->{retcount} += $count_in;
|
$serial->{retcount} += $count_in;
|
||||||
@ -153,7 +153,7 @@ sub response_ready() {
|
|||||||
sub start_query() {
|
sub start_query() {
|
||||||
my ($serial) = @_;
|
my ($serial) = @_;
|
||||||
#read and discard any outstanding data from previous commands:
|
#read and discard any outstanding data from previous commands:
|
||||||
while($serial->read()) {};
|
while($serial->read(255)) {};
|
||||||
|
|
||||||
$serial->{string_in} = "";
|
$serial->{string_in} = "";
|
||||||
$serial->{num_reads} = 0;
|
$serial->{num_reads} = 0;
|
||||||
|
@ -66,7 +66,7 @@ sub new() {
|
|||||||
$self->{pt_verify} = PT_THREAD(\&pt_verify);
|
$self->{pt_verify} = PT_THREAD(\&pt_verify);
|
||||||
$self->{pt_execute} = PT_THREAD(\&pt_execute);
|
$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;
|
return bless $self,$class;
|
||||||
}
|
}
|
||||||
@ -268,6 +268,7 @@ sub initialize($) {
|
|||||||
} else {
|
} else {
|
||||||
main::Log3($hash->{NAME},1,$msg." defined");
|
main::Log3($hash->{NAME},1,$msg." defined");
|
||||||
}
|
}
|
||||||
|
|
||||||
$hwdevice->reset_error();
|
$hwdevice->reset_error();
|
||||||
$hwdevice->baudrate(9600);
|
$hwdevice->baudrate(9600);
|
||||||
$hwdevice->databits(8);
|
$hwdevice->databits(8);
|
||||||
@ -278,6 +279,13 @@ sub initialize($) {
|
|||||||
#-- store with OWX device
|
#-- store with OWX device
|
||||||
$self->{hwdevice} = $hwdevice;
|
$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
|
#-- Third step detect busmaster on serial interface
|
||||||
|
|
||||||
my $name = $self->{name};
|
my $name = $self->{name};
|
||||||
@ -292,18 +300,22 @@ sub initialize($) {
|
|||||||
#-- timing byte for DS2480
|
#-- timing byte for DS2480
|
||||||
$ds2480->start_query();
|
$ds2480->start_query();
|
||||||
$ds2480->query("\xC1",1);
|
$ds2480->query("\xC1",1);
|
||||||
|
eval { #ignore timeout
|
||||||
do {
|
do {
|
||||||
$ds2480->read();
|
$ds2480->read();
|
||||||
} while (!$ds2480->response_ready());
|
} while (!$ds2480->response_ready());
|
||||||
|
};
|
||||||
|
|
||||||
#-- Max 4 tries to detect an interface
|
#-- Max 4 tries to detect an interface
|
||||||
for($l=0;$l<100;$l++) {
|
for($l=0;$l<100;$l++) {
|
||||||
#-- write 1-Wire bus (Fig. 2 of Maxim AN192)
|
#-- write 1-Wire bus (Fig. 2 of Maxim AN192)
|
||||||
$ds2480->start_query();
|
$ds2480->start_query();
|
||||||
$ds2480->query("\x17\x45\x5B\x0F\x91",5);
|
$ds2480->query("\x17\x45\x5B\x0F\x91",5);
|
||||||
|
eval { #ignore timeout
|
||||||
do {
|
do {
|
||||||
$ds2480->read();
|
$ds2480->read();
|
||||||
} while (!$ds2480->response_ready());
|
} while (!$ds2480->response_ready());
|
||||||
|
};
|
||||||
$res = $ds2480->{string_in};
|
$res = $ds2480->{string_in};
|
||||||
#-- process 4/5-byte string for detection
|
#-- process 4/5-byte string for detection
|
||||||
if( !defined($res)){
|
if( !defined($res)){
|
||||||
@ -347,6 +359,7 @@ sub initialize($) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$self->{interface} = $interface;
|
$self->{interface} = $interface;
|
||||||
|
main::Log3($hash->{NAME},1, $ress);
|
||||||
if ($interface eq "DS2480") {
|
if ($interface eq "DS2480") {
|
||||||
return $ds2480;
|
return $ds2480;
|
||||||
} elsif ($interface eq "DS9097") {
|
} elsif ($interface eq "DS9097") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user