Class: Modbus::Connection::Base

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/modbus/connection/base.rb

Direct Known Subclasses

TCPClient, TCPServer

Instance Method Summary collapse

Constructor Details

#initialize(handler) ⇒ Base

Returns a new instance of Base.



10
11
12
13
# File 'lib/modbus/connection/base.rb', line 10

def initialize(handler)
  @handler = handler
  reset_buffer
end

Instance Method Details

#analyze_bufferObject



32
33
34
35
# File 'lib/modbus/connection/base.rb', line 32

def analyze_buffer
  success = transaction_class.recv_adu @buffer, self
  analyze_buffer if success && !@buffer.empty?
end

#receive_data(data) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/modbus/connection/base.rb', line 16

def receive_data(data)
  @buffer << data
  analyze_buffer

rescue => e
  # TODO log exception
  # puts e.message
  reset_buffer
end

#reset_bufferObject



27
28
29
# File 'lib/modbus/connection/base.rb', line 27

def reset_buffer
  @buffer = String.new
end