Module: Test
- Included in:
- Modbus485, ModbusPoller, ModbusTCP
- Defined in:
- lib/LMG_modbus.rb
Overview
Generic Test Class
Constant Summary collapse
- REGISTER =
Constants that define important columns in the spreadsheet
'b'
- RESULT_POS1 =
'k'
- RESULT_POS2 =
'l'
- RESULT_POS3 =
'm'
- RESULT_POS4 =
'n'
- WRITE_VAL_POS1 =
'g'
- WRITE_VAL_POS2 =
'h'
- WRITE_VAL_POS3 =
'i'
- WRITE_VAL_POS4 =
'j'
- XLUP =
'-4162'
Instance Method Summary collapse
- #close ⇒ Object
-
#create_test(path_to_base_ss) ⇒ Object
Every Test requires a spreadsheet that contains the data that drives the test.
- #open_result ⇒ Object
- #run_modbus_write(read_column, write_column) ⇒ Object
Instance Method Details
#close ⇒ Object
62 63 64 |
# File 'lib/LMG_modbus.rb', line 62 def close @wb.Close end |
#create_test(path_to_base_ss) ⇒ Object
Every Test requires a spreadsheet that contains the data that drives the test. path_to_base_ss is the file location of such a spreadsheet
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/LMG_modbus.rb', line 26 def create_test(path_to_base_ss) @base_ss = path_to_base_ss @new_ss = (@base_ss.chomp(".xls")<<'_'<<Time.now.to_a.reverse[5..9].to_s<<(".xls")).gsub('driver','result') @start_time = Time.now @end_time = '' @ss = WIN32OLE::new('excel.Application') @wb = @ss.Workbooks.Open(@base_ss) @wb.SaveAs(@new_ss) @ws = @wb.Worksheets(1) end |
#open_result ⇒ Object
57 58 59 60 61 |
# File 'lib/LMG_modbus.rb', line 57 def open_result @ss.Visible = true @ss.Workbooks.Open(@new_ss) gets end |
#run_modbus_write(read_column, write_column) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/LMG_modbus.rb', line 36 def run_modbus_write(read_column, write_column) @start_time = Time.now @total_rows = @ws.Range("A65536").End(XLUP).Row @row = 2 while (@row <= @total_rows) @inner_row = @row register_value = process_test_case(@ws.Range("#{REGISTER}#{@row}")['Value'],@ws.Range("#{read_column}#{@row}")['Value'] ) register_value.each do |s| @ws.Range("#{write_column}#{@inner_row}")['Value'] = s @inner_row += 1 end unless register_value.is_a?(NilClass) @ws.Range("#{write_column}#{@inner_row}")['Value'] = $! if register_value == nil @row += 1 @wb.Save end @wb.Save @fin = Time.now p @fin @elapsed = (@fin - @start_time) puts " Elapsed time is seconds is: #{@elapsed}" end |