Class: Telos::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/telos/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/telos/device.rb', line 5

def host
  @host
end

#portObject

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

#disconnectObject



25
26
27
# File 'lib/telos/device.rb', line 25

def disconnect
  @server.close
end

#readObject



35
36
37
38
39
40
41
42
43
# File 'lib/telos/device.rb', line 35

def read
  if @mutex
    @mutex.synchronize do
      @messages.shift
    end
  else
    _read
  end
end

#showsObject



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 = Message.outgoing(command, arguments)

  @server.write(message.to_bytes)
end