tallakt / modbus-cli

Modbus command line utility
102 stars 19 forks source link

Ability to increase timeout #12

Closed jmcphail closed 4 years ago

jmcphail commented 6 years ago

Thank you for the excellent tool. Is it possible to increase the timeout? I am having intermittent communications with a Conext ComBox:

pi@raspberrypi:~ $ modbus read -s 201 192.168.1.176 400061 1 
/var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/tcp.rb:26:in `initialize': Connection refused - connect(2) for "192.168.1.176" port 502 (Errno::ECONNREFUSED)
        from /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/tcp.rb:26:in `new'
        from /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/tcp.rb:26:in `block in open_tcp_connection'
        from /usr/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
        from /usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
        from /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/tcp.rb:25:in `open_tcp_connection'
        from /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/tcp_client.rb:18:in `open_connection'
        from /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/client.rb:23:in `initialize'
        from /var/lib/gems/2.3.0/gems/modbus-cli-0.0.13/lib/modbus-cli/read_command.rb:76:in `new'
        from /var/lib/gems/2.3.0/gems/modbus-cli-0.0.13/lib/modbus-cli/read_command.rb:76:in `execute'
        from /var/lib/gems/2.3.0/gems/clamp-1.3.0/lib/clamp/command.rb:66:in `run'
        from /var/lib/gems/2.3.0/gems/clamp-1.3.0/lib/clamp/subcommand/execution.rb:18:in `execute'
        from /var/lib/gems/2.3.0/gems/clamp-1.3.0/lib/clamp/command.rb:66:in `run'
        from /var/lib/gems/2.3.0/gems/clamp-1.3.0/lib/clamp/command.rb:140:in `run'
        from /var/lib/gems/2.3.0/gems/modbus-cli-0.0.13/bin/modbus:6:in `<top (required)>'
        from /usr/local/bin/modbus:22:in `load'
        from /usr/local/bin/modbus:22:in `<main>'
jmcphail commented 6 years ago

I don't know Ruby well enough to fix this... https://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/

tallakt commented 6 years ago

I have added this as the "--connect-timeout" option. I dont have any way of testing this easily right now, I'd appreciate if you could, and provide some feedback.

Thanks for reporting an issue!

jmcphail commented 5 years ago

Thanks for the quick response! Apologies for not having responded earlier, I was not expecting a resolution.

I am not sure if I have updated the modbus-cli properly as I just reran the gem install modbus-cli

I do see the version update in the trace below... pi@raspberrypi:~ $ modbus read --connect-timeout 5 -s 1 192.168.1.15 400077 1 /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/tcp.rb:26:in `initialize': Connection refused - connect(2) for "192.168.1.15" port 502 (Errno::ECONNREFUSED) from /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/tcp.rb:26:in `new' from /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/tcp.rb:26:in `block in open_tcp_connection' from /usr/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout' from /usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout' from /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/tcp.rb:25:in `open_tcp_connection' from /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/tcp_client.rb:18:in `open_connection' from /var/lib/gems/2.3.0/gems/rmodbus-1.3.3/lib/rmodbus/client.rb:23:in `initialize' from /var/lib/gems/2.3.0/gems/modbus-cli-0.0.14/lib/modbus-cli/read_command.rb:83:in `new' from /var/lib/gems/2.3.0/gems/modbus-cli-0.0.14/lib/modbus-cli/read_command.rb:83:in `execute' from /var/lib/gems/2.3.0/gems/clamp-1.3.0/lib/clamp/command.rb:66:in `run' from /var/lib/gems/2.3.0/gems/clamp-1.3.0/lib/clamp/subcommand/execution.rb:18:in `execute' from /var/lib/gems/2.3.0/gems/clamp-1.3.0/lib/clamp/command.rb:66:in `run' from /var/lib/gems/2.3.0/gems/clamp-1.3.0/lib/clamp/command.rb:140:in `run' from /var/lib/gems/2.3.0/gems/modbus-cli-0.0.14/bin/modbus:6:in `' from /usr/local/bin/modbus:22:in `load' from /usr/local/bin/modbus:22:in `
'
tallakt commented 5 years ago

This indicates a connection problem on a tcpip level. Eg server not accepting requests, wrong address, firewall etc.

jmcphail commented 5 years ago

OK thanks. I am not surprised, being a Schneider Conext product and the fact that other modbus tools seem to act in a similar manner.