diff --git a/fhem/CHANGED b/fhem/CHANGED index b3468b86c..055aded7b 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -7,6 +7,7 @@ - feature: .gplot files renamed from type to content - bugfix: FS20 on-for-timer error reporting only in the logfile - bugfix: FHEM2FHEM should work with CUL again, after syntax change + - feature: CUL directio mode (No Device::SerialPort needed) - 2011-07-08 (5.1) - feature: smallscreen optimizations for iPhone diff --git a/fhem/FHEM/00_CUL.pm b/fhem/FHEM/00_CUL.pm index a0780b7cd..4eb3db872 100755 --- a/fhem/FHEM/00_CUL.pm +++ b/fhem/FHEM/00_CUL.pm @@ -106,7 +106,8 @@ CUL_Define($$) my @a = split("[ \t][ \t]*", $def); if(@a < 4 || @a > 5) { - my $msg = "wrong syntax: define CUL devicename[\@baudrate] "; + my $msg = "wrong syntax: define CUL {none | devicename[\@baudrate] ". + "| devicename\@directio | hostname:port} "; Log 2, $msg; return $msg; } @@ -949,6 +950,7 @@ CUL_SimpleWrite(@) $hash->{USBDev}->write($msg) if($hash->{USBDev}); syswrite($hash->{TCPDev}, $msg) if($hash->{TCPDev}); + syswrite($hash->{DIODev}, $msg) if($hash->{DIODev}); select(undef, undef, undef, 0.001); } @@ -958,22 +960,21 @@ sub CUL_SimpleRead($) { my ($hash) = @_; + my ($buf, $res); if($hash->{USBDev}) { - my $buf = $hash->{USBDev}->input(); - #Log 1, "Got $buf"; - return $buf; - } + $buf = $hash->{USBDev}->input(); + + } elsif($hash->{DIODev}) { + $res = sysread($hash->{DIODev}, $buf, 256); + $buf = undef if(!defined($res)); + + } elsif($hash->{TCPDev}) { + $res = sysread($hash->{TCPDev}, $buf, 256); + $buf = undef if(!defined($res)); - if($hash->{TCPDev}) { - my $buf; - if(!defined(sysread($hash->{TCPDev}, $buf, 256))) { - CUL_Disconnected($hash); - return undef; - } - return $buf; } - return undef; + return $buf; } ######################## @@ -994,6 +995,10 @@ CUL_CloseDev($) $hash->{USBDev}->close() ; delete($hash->{USBDev}); + } elsif($hash->{DIODev}) { + close($hash->{DIODev}); + delete($hash->{DIODev}); + } ($dev, undef) = split("@", $dev); # Remove the baudrate delete($selectlist{"$name.$dev"}); @@ -1044,6 +1049,27 @@ CUL_OpenDev($$) delete($readyfnlist{"$name.$dev"}); $selectlist{"$name.$dev"} = $hash; + } elsif(lc($baudrate) eq "directio") { # Without Device::SerialPort + + if(!open($po, "+<$dev")) { + return undef if($reopen); + Log(3, "Can't open $dev: $!"); + $readyfnlist{"$name.$dev"} = $hash; + $hash->{STATE} = "disconnected"; + return ""; + } + + $hash->{DIODev} = $po; + + if( $^O =~ /Win/ ) { + $readyfnlist{"$name.$dev"} = $hash; + } else { + $hash->{FD} = fileno($po); + delete($readyfnlist{"$name.$dev"}); + $selectlist{"$name.$dev"} = $hash; + } + + } else { # USB/Serial device diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index c078e4f40..b67c3c848 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -2048,8 +2048,16 @@ A line ending with \ will be concatenated with the next one, so long lines following command:
    modprobe usbserial vendor=0x03eb product=0x204b
In this case the device is most probably /dev/ttyUSB0.

+ You can also specify a baudrate if the device name contains the @ character, e.g.: /dev/ttyACM0@38400

+ + If the baudrate is "directio" (e.g.: /dev/ttyACM0@directio), then the + perl module Device::SerialPort is not needed, and fhem opens the device + with simple file io. This might work if the operating system uses sane + defaults for the serial parameters, e.g. some Linux distributions and + OSX.

+ Network-connected devices (CUN):
    <device> specifies the host:port of the device. E.g. @@ -2547,16 +2555,16 @@ A line ending with \ will be concatenated with the next one, so long lines
  • day-temp <tmp>
    night-temp <tmp>
    Set the day or night temperature. Temp must be between 6 and 30 - Centigrade, and precision is half a degree. -
  • tempListSat HH:MM temp 24:00 temp ...
    - tempListSun HH:MM temp 24:00 temp ...
    - tempListMon HH:MM temp 24:00 temp ...
    - tempListTue HH:MM temp 24:00 temp ...
    - tempListThu HH:MM temp 24:00 temp ...
    - tempListWed HH:MM temp 24:00 temp ...
    - tempListFri HH:MM temp 24:00 temp ...
    + Celsius, and precision is half a degree. +
  • tempListSat HH:MM temp ... 24:00 temp
    + tempListSun HH:MM temp ... 24:00 temp
    + tempListMon HH:MM temp ... 24:00 temp
    + tempListTue HH:MM temp ... 24:00 temp
    + tempListThu HH:MM temp ... 24:00 temp
    + tempListWed HH:MM temp ... 24:00 temp
    + tempListFri HH:MM temp ... 24:00 temp
    Specify a list of temperature intervals. Up to 24 intervals can be - spacified for each week day, the resolution is 10 Minutes. The + specified for each week day, the resolution is 10 Minutes. The last time spec must always be 24:00.
    Example: set th tempListSat 06:00 19 23:00 22.5 24:00 19
@@ -2567,11 +2575,11 @@ A line ending with \ will be concatenated with the next one, so long lines
  • raw <data> ...
    Only needed for experimentation. - send a list of "raw" commands. The first command will be immediately - sent, the next one after the previous one is acked by the target. The - length will be computed automatically, and the message counter will be - incremented if the first two charcters are ++. - Example (enable AES):
    +             send a list of "raw" commands. The first command will be
    +             immediately sent, the next one after the previous one is acked by
    +             the target.  The length will be computed automatically, and the
    +             message counter will be incremented if the first two charcters are
    +             ++. Example (enable AES):
        set hm1 raw ++A001F100001234560105000000001\
                    ++A001F10000123456010802010AF10B000C00\
                    ++A001F1000012345601080801\