Module: ModBus::TCP
Instance Attribute Summary collapse
-
#ipaddr ⇒ Object
readonly
Returns the value of attribute ipaddr.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#open_tcp_connection(ipaddr, port, opts = {}) ⇒ TCPSocket
Open TCP socket.
Instance Attribute Details
#ipaddr ⇒ Object (readonly)
Returns the value of attribute ipaddr.
8 9 10 |
# File 'lib/rmodbus/tcp.rb', line 8 def ipaddr @ipaddr end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/rmodbus/tcp.rb', line 8 def port @port end |
Instance Method Details
#open_tcp_connection(ipaddr, port, opts = {}) ⇒ TCPSocket
Open TCP socket
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rmodbus/tcp.rb', line 18 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 |