Module: Modbus::Cli::CommandsCommon::ClassMethods
- Included in:
- DumpCommand, ReadCommand, WriteCommand
- Defined in:
- lib/modbus-cli/commands_common.rb
Instance Method Summary collapse
- #address_parameter ⇒ Object
- #connect_timeout_option ⇒ Object
- #datatype_options ⇒ Object
- #debug_option ⇒ Object
- #format_options ⇒ Object
- #host_option ⇒ Object
- #host_parameter ⇒ Object
- #output_option ⇒ Object
- #slave_option ⇒ Object
- #timeout_option ⇒ Object
Instance Method Details
#address_parameter ⇒ Object
16 17 18 19 20 |
# File 'lib/modbus-cli/commands_common.rb', line 16 def address_parameter parameter 'ADDRESS', 'Start address (eg %M100, %MW100, 101, 400101)', :attribute_name => :address do |a| schneider_match(a) || modicon_match(a) || raise(ArgumentError, "Illegal address #{a}") end end |
#connect_timeout_option ⇒ Object
57 58 59 60 61 |
# File 'lib/modbus-cli/commands_common.rb', line 57 def connect_timeout_option option ["-C", "--connect-timeout"], 'TIMEOUT', "Specify the timeout in seconds when connecting to TCP socket" do |t| Integer(t) end end |
#datatype_options ⇒ Object
22 23 24 25 26 27 |
# File 'lib/modbus-cli/commands_common.rb', line 22 def option ["-w", "--word"], :flag, "use unsigned 16 bit integers" option ["-i", "--int"], :flag, "use signed 16 bit integers" option ["-d", "--dword"], :flag, "use unsigned 32 bit integers" option ["-f", "--float"], :flag, "use signed 32 bit floating point values" end |
#debug_option ⇒ Object
47 48 49 |
# File 'lib/modbus-cli/commands_common.rb', line 47 def debug_option option ["-D", "--debug"], :flag, "show debug messages" end |
#format_options ⇒ Object
29 30 31 32 |
# File 'lib/modbus-cli/commands_common.rb', line 29 def option ["--modicon"], :flag, "use Modicon addressing (eg. coil: 101, word: 400001)" option ["--schneider"], :flag, "use Schneider addressing (eg. coil: %M100, word: %MW0, float: %MF0, dword: %MD0)" end |
#host_option ⇒ Object
40 41 42 |
# File 'lib/modbus-cli/commands_common.rb', line 40 def host_option option ["-p", "--port"], 'PORT', "use TCP port", :default => 502 end |
#host_parameter ⇒ Object
11 12 13 |
# File 'lib/modbus-cli/commands_common.rb', line 11 def host_parameter parameter 'HOST', 'IP address or hostname for the Modbus device', :attribute_name => :host end |
#output_option ⇒ Object
44 45 |
# File 'lib/modbus-cli/commands_common.rb', line 44 def output_option end |
#slave_option ⇒ Object
34 35 36 37 38 |
# File 'lib/modbus-cli/commands_common.rb', line 34 def slave_option option ["-s", "--slave"], 'ID', "use slave id ID", :default => 1 do |s| Integer(s).tap {|slave| raise ArgumentError 'Slave must be in the range 0..255' unless (0..255).member?(slave) } end end |
#timeout_option ⇒ Object
51 52 53 54 55 |
# File 'lib/modbus-cli/commands_common.rb', line 51 def timeout_option option ["-T", "--timeout"], 'TIMEOUT', "Specify the timeout in seconds when talking to the slave" do |t| Integer(t) end end |