From 2682aa8ee6c65efc7a2cbec92042bfc72ffcddac Mon Sep 17 00:00:00 2001 From: tdressler <> Date: Sun, 11 May 2008 21:01:17 +0000 Subject: [PATCH] fixes git-svn-id: https://svn.fhem.de/fhem/trunk@182 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/50_WS300.pm | 13 +++++++------ fhem/FHEM/60_EM.pm | 35 ++++++++++++++++++++--------------- fhem/FHEM/92_FileLog.pm | 4 +++- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/fhem/FHEM/50_WS300.pm b/fhem/FHEM/50_WS300.pm index 1a171f5e4..696a3b392 100644 --- a/fhem/FHEM/50_WS300.pm +++ b/fhem/FHEM/50_WS300.pm @@ -114,7 +114,7 @@ WS300_Define($$) { my ($hash, $def) = @_; my @a = split("[ \t][ \t]*", $def); - + my $po; if($a[0] eq "WS300Device") { $defptr{10} = $hash; @@ -124,13 +124,13 @@ WS300_Define($$) $hash->{SENSOR} = 10; $hash->{READINGS}{WS300Device}{VAL} = "Initializing"; $hash->{READINGS}{WS300Device}{TIME} = TimeNow; - + if ($^O=~/Win/) { eval ("use Win32::SerialPort;"); - my $po = new Win32::SerialPort ($DeviceName); + $po = new Win32::SerialPort ($DeviceName); }else{ eval ("use Device::SerialPort;"); - my $po = new Device::SerialPort ($DeviceName); + $po = new Device::SerialPort ($DeviceName); } if(!$po) { @@ -514,6 +514,7 @@ WS300_Poll($) my $hash = shift; my $bstring=" "; my $count; + my $po; my $inchar=''; my $escape=0; my $ll = GetLogLevel("WS300Device"); @@ -541,9 +542,9 @@ NEXTPOLL: $hash->{READINGS}{WS300Device}{TIME} = TimeNow; sleep(1); if ($^O=~/Win/) { - my $po = new Win32::SerialPort ($devname); + $po = new Win32::SerialPort ($devname); }else{ - my $po = new Device::SerialPort ($devname); + $po = new Device::SerialPort ($devname); } if($po) { diff --git a/fhem/FHEM/60_EM.pm b/fhem/FHEM/60_EM.pm index 4d0cf8650..02efdc899 100755 --- a/fhem/FHEM/60_EM.pm +++ b/fhem/FHEM/60_EM.pm @@ -42,7 +42,7 @@ EM_Define($$) { my ($hash, $def) = @_; my @a = split("[ \t][ \t]*", $def); - + my $po; $hash->{STATE} = "Initialized"; delete $hash->{PortObj}; @@ -62,10 +62,10 @@ EM_Define($$) Log 3, "EM opening device $dev"; if ($^O=~/Win/) { eval ("use Win32::SerialPort;"); - my $po = new Win32::SerialPort ($dev); + $po = new Win32::SerialPort ($dev); }else{ eval ("use Device::SerialPort;"); - my $po = new Device::SerialPort ($dev); + $po = new Device::SerialPort ($dev); } return "Can't open $dev: $!" if(!$po); @@ -282,12 +282,13 @@ EmGetData($$) { my ($dev, $d) = @_; $d = EmMakeMsg(pack('H*', $d)); - + my $serport; return undef if(!$dev); + #OS depends if ($^O=~/Win/) { - my $serport = new Win32::SerialPort ($dev); + $serport = new Win32::SerialPort ($dev); }else{ - my $serport = new Device::SerialPort ($dev); + $serport = new Device::SerialPort ($dev); } if(!$serport) { @@ -313,15 +314,19 @@ EmGetData($$) my $started = 0; my $complete = 0; for(;;) { - my ($rout, $rin) = ('', ''); - vec($rin, $serport->FILENO, 1) = 1; - my $nfound = select($rout=$rin, undef, undef, 1.0); - - if($nfound < 0) { - $rm = "EM Select error $nfound / $!"; - goto DONE; - } - last if($nfound == 0); + #select will not work on windows, replaced with status + # + #my ($rout, $rin) = ('', ''); + #vec($rin, $serport->FILENO, 1) = 1; + #my $nfound = select($rout=$rin, undef, undef, 1.0); + # + #if($nfound < 0) { + # $rm = "EM Select error $nfound / $!"; + # goto DONE; + #} + #last if($nfound == 0); + my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags)=$serport->status; + last if ($InBytes<1); my $buf = $serport->input(); if(!defined($buf) || length($buf) == 0) { diff --git a/fhem/FHEM/92_FileLog.pm b/fhem/FHEM/92_FileLog.pm index cf379f67d..ac05b2945 100755 --- a/fhem/FHEM/92_FileLog.pm +++ b/fhem/FHEM/92_FileLog.pm @@ -149,9 +149,11 @@ FileLog_Get($@) return "Usage: get $a[0] " if(int(@a) != 4); my $fh = new IO::File $hash->{currentlogfile}; seekTo($fh, $hash, $a[1]); -# my @arr = +# my @arr = + my $data=''; while(my $l = <$fh>) { last if($l gt $a[2]); + $data.=$l; } close($fh); return "EOF" if(!defined($data));