Class: OneWire::Transaction
- Inherits:
-
Object
- Object
- OneWire::Transaction
- Defined in:
- lib/one_wire/transaction.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, path, options = {}) ⇒ Transaction
constructor
A new instance of Transaction.
Constructor Details
#initialize(type, path, options = {}) ⇒ Transaction
Returns a new instance of Transaction.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/one_wire/transaction.rb', line 7 def initialize(type, path, = {}) host = [:host] || OneWire::Config.host port = [:port] || OneWire::Config.port socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) socket.connect(Socket.pack_sockaddr_in(port, host)) OneWire::Request.new(socket, type, path, ) if type == :dir @response = [] while true do response = OneWire::Response.new(socket) response.data ? @response << response : break end else @response = OneWire::Response.new(socket) end ensure socket.close if socket && !socket.closed? end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/one_wire/transaction.rb', line 5 def response @response end |
Class Method Details
.ping(options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/one_wire/transaction.rb', line 37 def ping( = {}) host = [:host] || OneWire::Config.host port = [:port] || OneWire::Config.port socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) socket.connect(Socket.pack_sockaddr_in(port, host)) return true rescue SystemCallError return false ensure socket.close if socket && !socket.closed? end |
.write(path, value, options = {}) ⇒ Object
33 34 35 |
# File 'lib/one_wire/transaction.rb', line 33 def write(path, value, = {}) new(:write, path, .merge(:value => value)) end |