Module: ModBus::TCP
- Includes:
- Errors, Timeout
- Included in:
- RTUViaTCPClient, TCPClient
- Defined in:
- lib/rmodbus/tcp.rb
Instance Attribute Summary (collapse)
-
- (Object) ipaddr
readonly
Returns the value of attribute ipaddr.
-
- (Object) port
readonly
Returns the value of attribute port.
Instance Method Summary (collapse)
-
- (TCPSocket) open_tcp_connection(ipaddr, port, opts = {})
Open TCP socket.
Instance Attribute Details
- (Object) ipaddr (readonly)
Returns the value of attribute ipaddr
21 22 23 |
# File 'lib/rmodbus/tcp.rb', line 21 def ipaddr @ipaddr end |
- (Object) port (readonly)
Returns the value of attribute port
21 22 23 |
# File 'lib/rmodbus/tcp.rb', line 21 def port @port end |
Instance Method Details
- (TCPSocket) open_tcp_connection(ipaddr, port, opts = {})
Open TCP socket
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rmodbus/tcp.rb', line 31 def open_tcp_connection(ipaddr, port, opts = {}) @ipaddr, @port = ipaddr, port opts[:connect_timeout] ||= 1 io = nil begin timeout(opts[:connect_timeout], ModBusTimeout) do io = TCPSocket.new(@ipaddr, @port) end rescue ModBusTimeout => err raise ModBusTimeout.new, 'Timed out attempting to create connection' end io end |