Class: Modbus::Connection::TCPClient
- Defined in:
- lib/modbus/connection/tcp_client.rb
Instance Method Summary collapse
-
#connection_completed ⇒ Object
EM callback.
-
#initialize(handler) ⇒ TCPClient
constructor
Initializes a new connection instance.
-
#next_transaction_ident ⇒ Integer
Creates a successor transaction identfication in the range of 0..65535.
-
#pick_pending_transaction(transaction_ident) ⇒ Modbus::Transaction
Looks for a matching transaction in the internal store by a transaction ident and returns it if found.
-
#track_transaction(transaction) ⇒ Object
Adds Transaction object to the list of tracked transactions.
-
#unbind ⇒ Object
EM callback.
Methods inherited from Base
#analyze_buffer, #receive_data, #reset_buffer
Constructor Details
#initialize(handler) ⇒ TCPClient
Initializes a new connection instance.
17 18 19 20 21 22 |
# File 'lib/modbus/connection/tcp_client.rb', line 17 def initialize(handler) super @transaction_ident = 0 @pending_transactions = [] end |
Instance Method Details
#connection_completed ⇒ Object
EM callback. Called when the TCP connection is sucessfully established.
27 28 29 |
# File 'lib/modbus/connection/tcp_client.rb', line 27 def connection_completed @handler.connected self end |
#next_transaction_ident ⇒ Integer
Creates a successor transaction identfication in the range of 0..65535
43 44 45 |
# File 'lib/modbus/connection/tcp_client.rb', line 43 def next_transaction_ident @transaction_ident = @transaction_ident.succ.modulo 2**16 end |
#pick_pending_transaction(transaction_ident) ⇒ Modbus::Transaction
Looks for a matching transaction in the internal store by a transaction ident and returns it if found.
64 65 66 67 68 |
# File 'lib/modbus/connection/tcp_client.rb', line 64 def pick_pending_transaction(transaction_ident) transaction = @pending_transactions.find { |r| r.transaction_ident == transaction_ident } @pending_transactions.delete transaction transaction end |
#track_transaction(transaction) ⇒ Object
Adds Transaction object to the list of tracked transactions
52 53 54 55 56 |
# File 'lib/modbus/connection/tcp_client.rb', line 52 def track_transaction(transaction) # TODO log "exception" # puts "Too many pending pending transactions: #{@pending_transactions.size}" if @pending_transactions.size > 100 @pending_transactions << transaction end |
#unbind ⇒ Object
EM callback. Called when the TCP connection is closed.
34 35 36 |
# File 'lib/modbus/connection/tcp_client.rb', line 34 def unbind @handler.disconnected self end |