Class: OWNet::RawConnection
- Inherits:
-
Object
- Object
- OWNet::RawConnection
- Defined in:
- lib/connection.rb
Instance Method Summary collapse
-
#dir(path) ⇒ Object
List the contents of an OW path.
-
#initialize(opts = {}) ⇒ RawConnection
constructor
Connection without any of the hub discovery niceties.
-
#read(path) ⇒ Object
Read a value from an OW path.
-
#write(path, value) ⇒ Object
Write a value to an OW path.
Constructor Details
#initialize(opts = {}) ⇒ RawConnection
Connection without any of the hub discovery niceties
165 166 167 168 |
# File 'lib/connection.rb', line 165 def initialize(opts={}) @server = opts[:server] || 'localhost' @port = opts[:port] || 4304 end |
Instance Method Details
#dir(path) ⇒ Object
List the contents of an OW path.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/connection.rb', line 215 def dir(path) owconnect do |socket| owwrite(socket,:path => path, :function => DIR) fields = [] while true response = owread(socket) if response.data fields << response.data else break end end return fields end end |
#read(path) ⇒ Object
Read a value from an OW path.
199 200 201 202 203 204 |
# File 'lib/connection.rb', line 199 def read(path) owconnect do |socket| owwrite(socket,:path => path, :function => READ) return to_number(owread(socket).data) end end |
#write(path, value) ⇒ Object
Write a value to an OW path.
207 208 209 210 211 212 |
# File 'lib/connection.rb', line 207 def write(path, value) owconnect do |socket| owwrite(socket, :path => path, :value => value.to_s, :function => WRITE) return owread(socket).return_value end end |