Class: Telos::Device
- Inherits:
-
Object
- Object
- Telos::Device
- Defined in:
- lib/telos/device.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #connect(reader_thread: false) ⇒ Object
- #disconnect ⇒ Object
-
#initialize(host:, port: 9998) ⇒ Device
constructor
A new instance of Device.
- #read ⇒ Object
- #shows ⇒ Object
- #write(command, arguments = {}) ⇒ Object
Constructor Details
#initialize(host:, port: 9998) ⇒ Device
Returns a new instance of Device.
7 8 9 10 |
# File 'lib/telos/device.rb', line 7 def initialize(host:, port: 9998) self.host = host self.port = port end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/telos/device.rb', line 5 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/telos/device.rb', line 5 def port @port end |
Instance Method Details
#connect(reader_thread: false) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/telos/device.rb', line 15 def connect(reader_thread: false) @server = TCPSocket.new host, port start_reader_thread if reader_thread if block_given? yield stop_reader_thread if reader_thread @server.close end end |
#disconnect ⇒ Object
25 26 27 |
# File 'lib/telos/device.rb', line 25 def disconnect @server.close end |
#read ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/telos/device.rb', line 35 def read if @mutex @mutex.synchronize do .shift end else _read end end |
#shows ⇒ Object
12 13 |
# File 'lib/telos/device.rb', line 12 def shows end |
#write(command, arguments = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/telos/device.rb', line 29 def write(command, arguments = {}) = Message.outgoing(command, arguments) @server.write(.to_bytes) end |