Module: Modbus::Cli::CommandsCommon::ClassMethods

Included in:
DumpCommand, ReadCommand, WriteCommand
Defined in:
lib/modbus-cli/commands_common.rb

Instance Method Summary collapse

Instance Method Details

#address_parameterObject



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_optionObject



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_optionsObject



22
23
24
25
26
27
# File 'lib/modbus-cli/commands_common.rb', line 22

def datatype_options
  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_optionObject



47
48
49
# File 'lib/modbus-cli/commands_common.rb', line 47

def debug_option
  option ["-D", "--debug"], :flag, "show debug messages"
end

#format_optionsObject



29
30
31
32
# File 'lib/modbus-cli/commands_common.rb', line 29

def format_options
  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_optionObject



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_parameterObject



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_optionObject



44
45
# File 'lib/modbus-cli/commands_common.rb', line 44

def output_option
end

#slave_optionObject



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_optionObject



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