Class: Modbus::Cli::DumpCommand
Constant Summary
CommandsCommon::DEFAULT_SLAVE, CommandsCommon::MAX_WRITE_COILS, CommandsCommon::MAX_WRITE_WORDS
Instance Method Summary
collapse
address_parameter, connect_timeout_option, datatype_options, debug_option, format_options, host_option, host_parameter, output_option, slave_option, timeout_option
#addr_area, #addr_format, #addr_offset, #addr_type, #data_size, #modicon_match, #schneider_match, #sliced_write_coils, #sliced_write_registers
Instance Method Details
#execute ⇒ Object
34
35
36
37
|
# File 'lib/modbus-cli/dump_command.rb', line 34
def execute
host_ids = files_list.map {|d| d[:host] }.sort.uniq
host_ids.each {|host_id| execute_host host_id }
end
|
#execute_host(host_id) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/modbus-cli/dump_command.rb', line 39
def execute_host(host_id)
slave_ids = files_list.select {|d| d[:host] == host_id }.map {|d| d[:slave] }.sort.uniq
ModBus::TCPClient.connect(host_id, port) do |client|
slave_ids.each {|slave_id| execute_slave host_id, slave_id, client }
end
end
|
#execute_single_file(slave, file_data) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/modbus-cli/dump_command.rb', line 55
def execute_single_file(slave, file_data)
address = modicon_match(file_data[:offset].to_s) || schneider_match(file_data[:offset].to_s)
case address[:datatype]
when :bit
sliced_write_coils slave, address[:offset], file_data[:data]
when :word
sliced_write_registers slave, address[:offset], file_data[:data]
end
end
|
#execute_slave(host_id, slave_id, client) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/modbus-cli/dump_command.rb', line 46
def execute_slave(host_id, slave_id, client)
client.with_slave(slave_id) do |slave|
slave.debug = true if debug?
files_list.select {|d| d[:host] == host_id && d[:slave] == slave_id }.each do |file_data|
execute_single_file slave, file_data
end
end
end
|