2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-20 19:36:02 +00:00

open/close by Holger

git-svn-id: https://svn.fhem.de/fhem/trunk@795 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2011-01-08 09:55:41 +00:00
parent 254365650b
commit 659a54ef74

View File

@ -48,6 +48,9 @@ my %sets = (
"raw" => "xx xx", "raw" => "xx xx",
"initfull" => "xx xx", "initfull" => "xx xx",
"reopen" => "xx xx", "reopen" => "xx xx",
"close" => "xx xx",
"open" => "xx xx",
); );
my %setnrparam = ( my %setnrparam = (
"time" => 0, "time" => 0,
@ -59,6 +62,9 @@ my %setnrparam = (
"raw" => 2, "raw" => 2,
"initfull" => 0, "initfull" => 0,
"reopen" => 0, "reopen" => 0,
"close" => 0,
"open" => 0,
); );
my %codes = ( my %codes = (
@ -179,6 +185,16 @@ FHZ_Set($@)
FHZ_Reopen($hash); FHZ_Reopen($hash);
return undef; return undef;
} elsif($a[1] eq "close") {
FHZ_Close($hash);
return undef;
} elsif($a[1] eq "open") {
FHZ_Open($hash);
return undef;
} elsif($a[1] eq "raw") { } elsif($a[1] eq "raw") {
$fn = $a[2]; $fn = $a[2];
@ -637,6 +653,55 @@ FHZ_Reopen($)
} }
} }
#####################################
sub
FHZ_Close($)
{
my ($hash) = @_;
my $dev = $hash->{DeviceName};
return if(!$dev);
my $name = $hash->{NAME};
$hash->{PortObj}->close();
Log 1, "USB device $dev closed";
delete($hash->{PortObj});
delete($hash->{FD});
delete($selectlist{"$name.$dev"});
#$readyfnlist{"$name.$dev"} = $hash; # Start polling
$hash->{STATE} = "disconnected";
# Without the following sleep the open of the device causes a SIGSEGV,
# and following opens block infinitely. Only a reboot helps.
sleep(5);
DoTrigger($name, "DISCONNECTED");
}
#####################################
sub
FHZ_Open($)
{
my ($hash) = @_;
my $dev = $hash->{DeviceName};
return if(!$dev);
my $name = $hash->{NAME};
$readyfnlist{"$name.$dev"} = $hash; # Start polling
$hash->{STATE} = "disconnected";
# Without the following sleep the open of the device causes a SIGSEGV,
# and following opens block infinitely. Only a reboot helps.
sleep(5);
DoTrigger($name, "DISCONNECTED");
}
##################################### #####################################
sub sub
FHZ_Read($) FHZ_Read($)