Class: Rain8net
- Inherits:
-
Object
- Object
- Rain8net
- Defined in:
- lib/rain8net.rb
Instance Attribute Summary collapse
-
#addresses ⇒ Object
readonly
Returns the value of attribute addresses.
-
#sp ⇒ Object
readonly
Returns the value of attribute sp.
-
#tty ⇒ Object
readonly
Returns the value of attribute tty.
Instance Method Summary collapse
-
#all_off ⇒ Object
Alias for Rain8net#turn_all_off.
-
#initialize(options = {}) ⇒ Rain8net
constructor
Create a new object.
-
#module_address_for_zone(zone = 1) ⇒ Object
Determines which address from the @addresses attribute is hooked up to a given zone.
-
#read_settings ⇒ Object
Read all settings from a given module.
-
#response ⇒ Object
After sending a code that expects a response, call this function to receive the response from the Rain8net module r8.response => “@001”.
-
#send_code(code) ⇒ Object
Sends the given code to the Rain8net module.
-
#turn_all_off ⇒ Object
Turn off all zones for the entire system.
-
#turn_off_zone(zone = 1) ⇒ Object
Turn off an individual zone: r8.turn_off_zone(1).
-
#turn_on_zone(zone = 1) ⇒ Object
Turn on an individual zone: r8.turn_on_zone(1).
-
#zone_status(zone = 1) ⇒ Object
Get the status of the given zone.
Constructor Details
#initialize(options = {}) ⇒ Rain8net
Create a new object. Options include: TTY port (COM port) number on the machine connected to the RS232 port of the first module in the network.
:tty => 0
Address of the Rain8net devices. These are the addresses of the modules in the Rain8 network. The manufacturer default for each module is “01”. Configure the address using the manufacturer’s configuration program before hooking it up to your Rain8 network.
:addresses => ['01', '45', '02']
Make sure your addresses are entered in the order they have been built into your Rain8net system. The zones numbers are determined based on the order they are entered in the addresses array. (See Rain8net#module_address_for_zone)
Example:
r8 = Rain8net.new(:tty => 0, :addresses=>['01'])
Note: values above are the defaults. So, the above is equivilant to:
r8 = Rain8net.new
57 58 59 60 61 62 63 |
# File 'lib/rain8net.rb', line 57 def initialize(={}) = {:tty => 0, :addresses => ["01"]} = .merge() @tty = [:tty] @addresses = [:addresses] @sp = SerialPort.new(@tty, 4800, 8, 1, SerialPort::NONE) end |
Instance Attribute Details
#addresses ⇒ Object (readonly)
Returns the value of attribute addresses.
34 35 36 |
# File 'lib/rain8net.rb', line 34 def addresses @addresses end |
#sp ⇒ Object (readonly)
Returns the value of attribute sp.
34 35 36 |
# File 'lib/rain8net.rb', line 34 def sp @sp end |
#tty ⇒ Object (readonly)
Returns the value of attribute tty.
34 35 36 |
# File 'lib/rain8net.rb', line 34 def tty @tty end |
Instance Method Details
#all_off ⇒ Object
Alias for Rain8net#turn_all_off
88 89 90 |
# File 'lib/rain8net.rb', line 88 def all_off turn_all_off end |
#module_address_for_zone(zone = 1) ⇒ Object
Determines which address from the @addresses attribute is hooked up to a given zone. Note, there is no fancy way to figure out out what your hardware connections actually are. This method uses the convention that your FIRST 8 zones are connected to the FIRST address in the @addresses array. Zones 9-16 are connected to the next address in the array and so on.
r8.module_address_for_zone(5)
=> "01"
128 129 130 131 132 133 134 135 |
# File 'lib/rain8net.rb', line 128 def module_address_for_zone(zone=1) module_position = ((zone.to_f - 0.01) / 8).to_i begin @addresses[module_position] rescue raise "No module found for zone #{zone}" end end |
#read_settings ⇒ Object
Read all settings from a given module. Returns the raw hex response from the module.
settings = r8.read_settings
settings.to_s
=> (a whole bunch of hex info)
TODO: Interpret the settings and format them into something usable.
100 101 102 103 |
# File 'lib/rain8net.rb', line 100 def read_settings send_code("232323") response end |
#response ⇒ Object
After sending a code that expects a response, call this function to receive the response from the Rain8net module
r8.response
=> "@\001"
148 149 150 151 |
# File 'lib/rain8net.rb', line 148 def response sleep(1) sp.read end |
#send_code(code) ⇒ Object
Sends the given code to the Rain8net module.
r8.send_code("205555")
140 141 142 |
# File 'lib/rain8net.rb', line 140 def send_code(code) sp.write([code].pack("H*")) end |
#turn_all_off ⇒ Object
Turn off all zones for the entire system.
r8.turn_all_off
82 83 84 |
# File 'lib/rain8net.rb', line 82 def turn_all_off send_code("205555") end |
#turn_off_zone(zone = 1) ⇒ Object
Turn off an individual zone:
r8.turn_off_zone(1)
75 76 77 |
# File 'lib/rain8net.rb', line 75 def turn_off_zone(zone=1) send_code("40#{module_address_for_zone(zone)}4#{zone}") end |
#turn_on_zone(zone = 1) ⇒ Object
Turn on an individual zone:
r8.turn_on_zone(1)
68 69 70 |
# File 'lib/rain8net.rb', line 68 def turn_on_zone(zone=1) send_code("40#{module_address_for_zone(zone)}3#{zone}") end |
#zone_status(zone = 1) ⇒ Object
Get the status of the given zone. Returns true if a zone is running, false if it is not.
r8.zone_status(1)
=> true
110 111 112 113 114 115 116 117 |
# File 'lib/rain8net.rb', line 110 def zone_status(zone=1) zone = zone.to_i send_code("40#{module_address_for_zone(zone)}F0") # Response includes a status of each of the 8 zones for the module. r = response.reverse.unpack("B*").to_s.match(/(^.{8})/).to_s.split(//).reverse position = (zone - (((zone - 1) / 8).to_i * 8) - 1).to_i (r[position].to_i == 1) ? true : false end |