lib/ekm-omnimeter/meter.rb in ekm-omnimeter-0.2.0 vs lib/ekm-omnimeter/meter.rb in ekm-omnimeter-0.2.1

- old
+ new

@@ -39,11 +39,11 @@ @logger.debug "remote_address: #{remote_address}" @logger.debug "remote_port: #{remote_port}" # Collect the power configurations if VALID_POWER_CONFIGURATIONS.index(options[:power_configuration]) - power_configuration = options[:power_configuration] + @power_configuration = options[:power_configuration] else raise EkmOmnimeterError, "Invalid power configuration #{options[:power_configuration]}. Valid values are #{VALID_POWER_CONFIGURATIONS.join(', ')}" end # Collect pulse inputs @@ -158,18 +158,19 @@ # iSerial v4 Spec From http://documents.ekmmetering.com/Omnimeter-Pulse-v.4-Protocol.pdf # %w(01 52 31 02 30 30 31 31 28 29 03 13 16).map{|a| a.to_i(16).chr}.join # Returns the correct measurement for voltage, current, and power based on the corresponding power_configuration def calculate_measurement(m1, m2, m3) + puts "****** #{power_configuration.inspect} #{m1}, #{m2}, #{m3}" if power_configuration == :single_phase_2wire - volts_l1 + m1 elsif power_configuration == :single_phase_3wire - (volts_l1 + volts_l2) + (m1 + m2) elsif power_configuration == :three_phase_3wire - (volts_l1 + :volts_l3) + (m1 + m3) elsif power_configuration == :three_phase_4wire - (volts_l1 + volts_l2 + volts_l3) + (m1 + m2 + m3) end end def to_kwh_float(s) to_f_with_decimal_places(s, @values[:kwh_data_decimal_places]) @@ -344,13 +345,13 @@ @values.merge!(d) @last_read_timestamp = Time.now # Calculate totals based on wiring configuration @values[:meter_timestamp] = meter_timestamp - @values[:volts] = calculate_measurement(d[:volts_l1], d[:volts_l2], d[:volts_l3]) - @values[:amps] = calculate_measurement(d[:amps_l1], d[:amps_l2], d[:amps_l3]) - @values[:watts] = calculate_measurement(d[:watts_l1], d[:watts_l2], d[:watts_l3]) + @values[:volts] = calculate_measurement(volts_l1, volts_l2, volts_l3) + @values[:amps] = calculate_measurement(amps_l1, amps_l2, amps_l3) + @values[:watts] = calculate_measurement(watts_l1, watts_l2, watts_l3) @values[:total_forward_kwh] = total_kwh - total_reverse_kwh @values[:net_kwh] = total_forward_kwh - total_reverse_kwh # Return the hash as an open struct return d @@ -435,12 +436,12 @@ @values.merge!(d) @last_read_timestamp = Time.now # Calculate totals based on wiring configuration @values[:meter_timestamp] = meter_timestamp - @values[:volts] = calculate_measurement(d[:volts_l1], d[:volts_l2], d[:volts_l3]) - @values[:amps] = calculate_measurement(d[:amps_l1], d[:amps_l2], d[:amps_l3]) - @values[:watts] = calculate_measurement(d[:watts_l1], d[:watts_l2], d[:watts_l3]) + @values[:volts] = calculate_measurement(volts_l1, volts_l2, volts_l3) + @values[:amps] = calculate_measurement(amps_l1, amps_l2, amps_l3) + @values[:watts] = calculate_measurement(watts_l1, watts_l2, watts_l3) # Return the hash as an open struct return d end