From 659a54ef74bad7f660cc79adaab7512b0bd8b841 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sat, 8 Jan 2011 09:55:41 +0000 Subject: [PATCH] open/close by Holger git-svn-id: https://svn.fhem.de/fhem/trunk@795 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_FHZ.pm | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/fhem/FHEM/00_FHZ.pm b/fhem/FHEM/00_FHZ.pm index 0f7e94a84..657746c0d 100755 --- a/fhem/FHEM/00_FHZ.pm +++ b/fhem/FHEM/00_FHZ.pm @@ -48,6 +48,9 @@ my %sets = ( "raw" => "xx xx", "initfull" => "xx xx", "reopen" => "xx xx", + "close" => "xx xx", + "open" => "xx xx", + ); my %setnrparam = ( "time" => 0, @@ -59,6 +62,9 @@ my %setnrparam = ( "raw" => 2, "initfull" => 0, "reopen" => 0, + "close" => 0, + "open" => 0, + ); my %codes = ( @@ -179,6 +185,16 @@ FHZ_Set($@) FHZ_Reopen($hash); 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") { $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 FHZ_Read($)