#!/usr/bin/env ruby # $Paefchen: ruby/snd/snd.rb,v 1.1 2008/04/04 12:17:55 as Exp $ module SND class MB def initialize addr, port=502, slaveaddr=0 @addr = addr @port = port @slaveaddr = slaveaddr end #def read_input; end #def read_inputs; end #def read_coil; end #def read_coils; end #def write_coil; end #def write_coils; end #def read_input_register; end #def read_input_registers; end #def read_input_registers; end #def write_registers; end def read_holding_register register raw("read_holding_register #{register}").split('=')[1].to_i end def write_register register, value raw("write_register #{register} #{value.to_i}") end private def raw text `../mb_tcpclient #{@addr} #{@port} #{@slaveaddr} #{text}` end end class Setting def initialize addr, port=502, slaveaddr=0 @mb = MB.new addr, port, slaveaddr @volumen_min = 100 @volumen_max = 250 end def volumen_fadeto to now = volumen_get return true if now == to return volumen_set(0) if to == 0 to = @volumen_min if to < @volumen_min to = @volumen_max if to > @volumen_max if now < to (now+1).upto(to) { |i| volumen_set i } else (now-1).downto(to) { |i| volumen_set i } end end def volumen_get @mb.read_holding_register 0 end def volumen_set value @mb.write_register 0, value end end end