abb.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. class A43(ModbusRTUMeter):
  2. def __init__(self, port, baudrate=38400, slaveaddress=1, timeout=0.5, model=None):
  3. super().__init__(port, baudrate, slaveaddress, timeout)
  4. if model in ABBMeter.REGSETS:
  5. self.REGS = [register for register in ABBMeter._REGS if register['name'] in ABBMeter.REGSETS[type]]
  6. else:
  7. self.REGS = ABBMeter._REGS
  8. # Register map of the ABB A and B series energy meters.
  9. _REGS = [{'name': 'active_import', 'start': 20480, 'length': 4, 'signed': True, 'decimals': 2},
  10. {'name': 'active_export', 'start': 20484, 'length': 4, 'signed': True, 'decimals': 2},
  11. {'name': 'active_net', 'start': 20488, 'length': 4, 'signed': True, 'decimals': 2},
  12. {'name': 'reactive_import', 'start': 20492, 'length': 4, 'signed': True, 'decimals': 2},
  13. {'name': 'reactive_export', 'start': 20496, 'length': 4, 'signed': True, 'decimals': 2},
  14. {'name': 'reactive_net', 'start': 20500, 'length': 4, 'signed': True, 'decimals': 2},
  15. {'name': 'apparent_import', 'start': 20504, 'length': 4, 'signed': True, 'decimals': 2},
  16. {'name': 'apparent_export', 'start': 20508, 'length': 4, 'signed': True, 'decimals': 2},
  17. {'name': 'apparent_net', 'start': 20512, 'length': 4, 'signed': True, 'decimals': 2},
  18. {'name': 'active_import_co2', 'start': 20516, 'length': 4, 'signed': True, 'decimals': 2},
  19. {'name': 'active_import_currency', 'start': 20532, 'length': 4, 'signed': True, 'decimals': 2},
  20. {'name': 'active_import_tariff_1', 'start': 20848, 'length': 4, 'signed': False, 'decimals': 2},
  21. {'name': 'active_import_tariff_2', 'start': 20852, 'length': 4, 'signed': False, 'decimals': 2},
  22. {'name': 'active_import_tariff_3', 'start': 20856, 'length': 4, 'signed': False, 'decimals': 2},
  23. {'name': 'active_import_tariff_4', 'start': 20860, 'length': 4, 'signed': False, 'decimals': 2},
  24. {'name': 'active_export_tariff_1', 'start': 20880, 'length': 4, 'signed': False, 'decimals': 2},
  25. {'name': 'active_export_tariff_2', 'start': 20884, 'length': 4, 'signed': False, 'decimals': 2},
  26. {'name': 'active_export_tariff_3', 'start': 20888, 'length': 4, 'signed': False, 'decimals': 2},
  27. {'name': 'active_export_tariff_4', 'start': 20892, 'length': 4, 'signed': False, 'decimals': 2},
  28. {'name': 'reactive_import_tariff_1', 'start': 20912, 'length': 4, 'signed': False, 'decimals': 2},
  29. {'name': 'reactive_import_tariff_2', 'start': 20916, 'length': 4, 'signed': False, 'decimals': 2},
  30. {'name': 'reactive_import_tariff_3', 'start': 20920, 'length': 4, 'signed': False, 'decimals': 2},
  31. {'name': 'reactive_import_tariff_4', 'start': 20924, 'length': 4, 'signed': False, 'decimals': 2},
  32. {'name': 'reactive_export_tariff_1', 'start': 20944, 'length': 4, 'signed': False, 'decimals': 2},
  33. {'name': 'reactive_export_tariff_2', 'start': 20948, 'length': 4, 'signed': False, 'decimals': 2},
  34. {'name': 'reactive_export_tariff_3', 'start': 20952, 'length': 4, 'signed': False, 'decimals': 2},
  35. {'name': 'reactive_export_tariff_4', 'start': 20956, 'length': 4, 'signed': False, 'decimals': 2},
  36. {'name': 'active_import_l1', 'start': 21600, 'length': 4, 'signed': False, 'decimals': 2},
  37. {'name': 'active_import_l2', 'start': 21604, 'length': 4, 'signed': False, 'decimals': 2},
  38. {'name': 'active_import_l3', 'start': 21608, 'length': 4, 'signed': False, 'decimals': 2},
  39. {'name': 'active_export_l1', 'start': 21612, 'length': 4, 'signed': False, 'decimals': 2},
  40. {'name': 'active_export_l2', 'start': 21616, 'length': 4, 'signed': False, 'decimals': 2},
  41. {'name': 'active_export_l3', 'start': 21620, 'length': 4, 'signed': False, 'decimals': 2},
  42. {'name': 'active_net_l1', 'start': 21624, 'length': 4, 'signed': True, 'decimals': 2},
  43. {'name': 'active_net_l2', 'start': 21628, 'length': 4, 'signed': True, 'decimals': 2},
  44. {'name': 'active_net_l3', 'start': 21632, 'length': 4, 'signed': True, 'decimals': 2},
  45. {'name': 'reactive_import_l1', 'start': 21636, 'length': 4, 'signed': False, 'decimals': 2},
  46. {'name': 'reactive_import_l2', 'start': 21640, 'length': 4, 'signed': False, 'decimals': 2},
  47. {'name': 'reactive_import_l3', 'start': 21644, 'length': 4, 'signed': False, 'decimals': 2},
  48. {'name': 'reactive_export_l1', 'start': 21648, 'length': 4, 'signed': False, 'decimals': 2},
  49. {'name': 'reactive_export_l2', 'start': 21652, 'length': 4, 'signed': False, 'decimals': 2},
  50. {'name': 'reactive_export_l3', 'start': 21656, 'length': 4, 'signed': False, 'decimals': 2},
  51. {'name': 'reactive_net_l1', 'start': 21660, 'length': 4, 'signed': True, 'decimals': 2},
  52. {'name': 'reactive_net_l2', 'start': 21664, 'length': 4, 'signed': True, 'decimals': 2},
  53. {'name': 'reactive_net_l3', 'start': 21668, 'length': 4, 'signed': True, 'decimals': 2},
  54. {'name': 'apparent_import_l1', 'start': 21672, 'length': 4, 'signed': False, 'decimals': 2},
  55. {'name': 'apparent_import_l2', 'start': 21676, 'length': 4, 'signed': False, 'decimals': 2},
  56. {'name': 'apparent_import_l3', 'start': 21680, 'length': 4, 'signed': False, 'decimals': 2},
  57. {'name': 'apparent_export_l1', 'start': 21684, 'length': 4, 'signed': False, 'decimals': 2},
  58. {'name': 'apparent_export_l2', 'start': 21688, 'length': 4, 'signed': False, 'decimals': 2},
  59. {'name': 'apparent_export_l3', 'start': 21692, 'length': 4, 'signed': False, 'decimals': 2},
  60. {'name': 'apparent_net_l1', 'start': 21696, 'length': 4, 'signed': True, 'decimals': 2},
  61. {'name': 'apparent_net_l2', 'start': 21700, 'length': 4, 'signed': True, 'decimals': 2},
  62. {'name': 'apparent_net_l3', 'start': 21704, 'length': 4, 'signed': True, 'decimals': 2},
  63. {'name': 'resettable_active_import', 'start': 21804, 'length': 4, 'signed': False, 'decimals': 2},
  64. {'name': 'resettable_active_export', 'start': 21808, 'length': 4, 'signed': False, 'decimals': 2},
  65. {'name': 'resettable_reactive_import', 'start': 21812, 'length': 4, 'signed': False, 'decimals': 2},
  66. {'name': 'resettable_reactive_export', 'start': 21816, 'length': 4, 'signed': False, 'decimals': 2},
  67. {'name': 'voltage_l1_n', 'start': 23296, 'length': 2, 'signed': False, 'decimals': 1},
  68. {'name': 'voltage_l2_n', 'start': 23298, 'length': 2, 'signed': False, 'decimals': 1},
  69. {'name': 'voltage_l3_n', 'start': 23300, 'length': 2, 'signed': False, 'decimals': 1},
  70. {'name': 'voltage_l1_l2', 'start': 23302, 'length': 2, 'signed': False, 'decimals': 1},
  71. {'name': 'voltage_l3_l2', 'start': 23304, 'length': 2, 'signed': False, 'decimals': 1},
  72. {'name': 'voltage_l1_l3', 'start': 23306, 'length': 2, 'signed': False, 'decimals': 1},
  73. {'name': 'current_l1', 'start': 23308, 'length': 2, 'signed': False, 'decimals': 2},
  74. {'name': 'current_l2', 'start': 23310, 'length': 2, 'signed': False, 'decimals': 2},
  75. {'name': 'current_l3', 'start': 23312, 'length': 2, 'signed': False, 'decimals': 2},
  76. {'name': 'current_n', 'start': 23314, 'length': 2, 'signed': False, 'decimals': 2},
  77. {'name': 'active_power_total', 'start': 23316, 'length': 2, 'signed': True, 'decimals': 2},
  78. {'name': 'active_power_l1', 'start': 23318, 'length': 2, 'signed': True, 'decimals': 2},
  79. {'name': 'active_power_l2', 'start': 23320, 'length': 2, 'signed': True, 'decimals': 2},
  80. {'name': 'active_power_l3', 'start': 23322, 'length': 2, 'signed': True, 'decimals': 2},
  81. {'name': 'reactive_power_total', 'start': 23324, 'length': 2, 'signed': True, 'decimals': 2},
  82. {'name': 'reactive_power_l1', 'start': 23326, 'length': 2, 'signed': True, 'decimals': 2},
  83. {'name': 'reactive_power_l2', 'start': 23328, 'length': 2, 'signed': True, 'decimals': 2},
  84. {'name': 'reactive_power_l3', 'start': 23330, 'length': 2, 'signed': True, 'decimals': 2},
  85. {'name': 'apparent_power_total', 'start': 23332, 'length': 2, 'signed': True, 'decimals': 2},
  86. {'name': 'apparent_power_l1', 'start': 23334, 'length': 2, 'signed': True, 'decimals': 2},
  87. {'name': 'apparent_power_l2', 'start': 23336, 'length': 2, 'signed': True, 'decimals': 2},
  88. {'name': 'apparent_power_l3', 'start': 23338, 'length': 2, 'signed': True, 'decimals': 2},
  89. {'name': 'frequency', 'start': 23340, 'length': 1, 'signed': False, 'decimals': 2},
  90. {'name': 'phase_angle_power_total', 'start': 23341, 'length': 1, 'signed': True, 'decimals': 1},
  91. {'name': 'phase_angle_power_l1', 'start': 23342, 'length': 1, 'signed': True, 'decimals': 1},
  92. {'name': 'phase_angle_power_l2', 'start': 23343, 'length': 1, 'signed': True, 'decimals': 1},
  93. {'name': 'phase_angle_power_l3', 'start': 23344, 'length': 1, 'signed': True, 'decimals': 1},
  94. {'name': 'phase_angle_voltage_l1', 'start': 23345, 'length': 1, 'signed': True, 'decimals': 1},
  95. {'name': 'phase_angle_voltage_l2', 'start': 23346, 'length': 1, 'signed': True, 'decimals': 1},
  96. {'name': 'phase_angle_voltage_l3', 'start': 23347, 'length': 1, 'signed': True, 'decimals': 1},
  97. {'name': 'phase_angle_current_l1', 'start': 23351, 'length': 1, 'signed': True, 'decimals': 1},
  98. {'name': 'phase_angle_current_l2', 'start': 23352, 'length': 1, 'signed': True, 'decimals': 1},
  99. {'name': 'phase_angle_current_l3', 'start': 23353, 'length': 1, 'signed': True, 'decimals': 1},
  100. {'name': 'power_factor_total', 'start': 23354, 'length': 1, 'signed': True, 'decimals': 3},
  101. {'name': 'power_factor_l1', 'start': 23355, 'length': 1, 'signed': True, 'decimals': 3},
  102. {'name': 'power_factor_l2', 'start': 23356, 'length': 1, 'signed': True, 'decimals': 3},
  103. {'name': 'power_factor_l3', 'start': 23357, 'length': 1, 'signed': True, 'decimals': 3},
  104. {'name': 'current_quadrant_total', 'start': 23358, 'length': 1, 'signed': False, 'decimals': 0},
  105. {'name': 'current_quadrant_l1', 'start': 23359, 'length': 1, 'signed': False, 'decimals': 0},
  106. {'name': 'current_quadrant_l2', 'start': 23360, 'length': 1, 'signed': False, 'decimals': 0},
  107. {'name': 'current_quadrant_l3', 'start': 23361, 'length': 1, 'signed': False, 'decimals': 0},
  108. {'name': 'voltage_harmonics_l1_n_thd', 'start': 23808, 'length': 2, 'signed': False, 'decimals': 1},
  109. {'name': 'voltage_harmonics_l1_n_2nd', 'start': 23810, 'length': 2, 'signed': False, 'decimals': 1},
  110. {'name': 'voltage_harmonics_l1_n_3rd', 'start': 23812, 'length': 2, 'signed': False, 'decimals': 1},
  111. {'name': 'voltage_harmonics_l1_n_4th', 'start': 23814, 'length': 2, 'signed': False, 'decimals': 1},
  112. {'name': 'voltage_harmonics_l1_n_5th', 'start': 23816, 'length': 2, 'signed': False, 'decimals': 1},
  113. {'name': 'voltage_harmonics_l1_n_6th', 'start': 23818, 'length': 2, 'signed': False, 'decimals': 1},
  114. {'name': 'voltage_harmonics_l1_n_7th', 'start': 23820, 'length': 2, 'signed': False, 'decimals': 1},
  115. {'name': 'voltage_harmonics_l1_n_8th', 'start': 23822, 'length': 2, 'signed': False, 'decimals': 1},
  116. {'name': 'voltage_harmonics_l1_n_9th', 'start': 23824, 'length': 2, 'signed': False, 'decimals': 1},
  117. {'name': 'voltage_harmonics_l1_n_10th', 'start': 23826, 'length': 2, 'signed': False, 'decimals': 1},
  118. {'name': 'voltage_harmonics_l1_n_11th', 'start': 23828, 'length': 2, 'signed': False, 'decimals': 1},
  119. {'name': 'voltage_harmonics_l1_n_12th', 'start': 23830, 'length': 2, 'signed': False, 'decimals': 1},
  120. {'name': 'voltage_harmonics_l1_n_13th', 'start': 23832, 'length': 2, 'signed': False, 'decimals': 1},
  121. {'name': 'voltage_harmonics_l1_n_14th', 'start': 23834, 'length': 2, 'signed': False, 'decimals': 1},
  122. {'name': 'voltage_harmonics_l1_n_15th', 'start': 23836, 'length': 2, 'signed': False, 'decimals': 1},
  123. {'name': 'voltage_harmonics_l1_n_16th', 'start': 23838, 'length': 2, 'signed': False, 'decimals': 1},
  124. {'name': 'voltage_harmonics_l2_n_thd', 'start': 23936, 'length': 2, 'signed': False, 'decimals': 1},
  125. {'name': 'voltage_harmonics_l2_n_2nd', 'start': 23938, 'length': 2, 'signed': False, 'decimals': 1},
  126. {'name': 'voltage_harmonics_l2_n_3rd', 'start': 23940, 'length': 2, 'signed': False, 'decimals': 1},
  127. {'name': 'voltage_harmonics_l2_n_4th', 'start': 23942, 'length': 2, 'signed': False, 'decimals': 1},
  128. {'name': 'voltage_harmonics_l2_n_5th', 'start': 23944, 'length': 2, 'signed': False, 'decimals': 1},
  129. {'name': 'voltage_harmonics_l2_n_6th', 'start': 23946, 'length': 2, 'signed': False, 'decimals': 1},
  130. {'name': 'voltage_harmonics_l2_n_7th', 'start': 23948, 'length': 2, 'signed': False, 'decimals': 1},
  131. {'name': 'voltage_harmonics_l2_n_8th', 'start': 23950, 'length': 2, 'signed': False, 'decimals': 1},
  132. {'name': 'voltage_harmonics_l2_n_9th', 'start': 23952, 'length': 2, 'signed': False, 'decimals': 1},
  133. {'name': 'voltage_harmonics_l2_n_10th', 'start': 23954, 'length': 2, 'signed': False, 'decimals': 1},
  134. {'name': 'voltage_harmonics_l2_n_11th', 'start': 23956, 'length': 2, 'signed': False, 'decimals': 1},
  135. {'name': 'voltage_harmonics_l2_n_12th', 'start': 23958, 'length': 2, 'signed': False, 'decimals': 1},
  136. {'name': 'voltage_harmonics_l2_n_13th', 'start': 23960, 'length': 2, 'signed': False, 'decimals': 1},
  137. {'name': 'voltage_harmonics_l2_n_14th', 'start': 23962, 'length': 2, 'signed': False, 'decimals': 1},
  138. {'name': 'voltage_harmonics_l2_n_15th', 'start': 23964, 'length': 2, 'signed': False, 'decimals': 1},
  139. {'name': 'voltage_harmonics_l2_n_16th', 'start': 23966, 'length': 2, 'signed': False, 'decimals': 1},
  140. {'name': 'voltage_harmonics_l3_n_thd', 'start': 24064, 'length': 2, 'signed': False, 'decimals': 1},
  141. {'name': 'voltage_harmonics_l3_n_2nd', 'start': 24066, 'length': 2, 'signed': False, 'decimals': 1},
  142. {'name': 'voltage_harmonics_l3_n_3rd', 'start': 24068, 'length': 2, 'signed': False, 'decimals': 1},
  143. {'name': 'voltage_harmonics_l3_n_4th', 'start': 24070, 'length': 2, 'signed': False, 'decimals': 1},
  144. {'name': 'voltage_harmonics_l3_n_5th', 'start': 24072, 'length': 2, 'signed': False, 'decimals': 1},
  145. {'name': 'voltage_harmonics_l3_n_6th', 'start': 24074, 'length': 2, 'signed': False, 'decimals': 1},
  146. {'name': 'voltage_harmonics_l3_n_7th', 'start': 24076, 'length': 2, 'signed': False, 'decimals': 1},
  147. {'name': 'voltage_harmonics_l3_n_8th', 'start': 24078, 'length': 2, 'signed': False, 'decimals': 1},
  148. {'name': 'voltage_harmonics_l3_n_9th', 'start': 24080, 'length': 2, 'signed': False, 'decimals': 1},
  149. {'name': 'voltage_harmonics_l3_n_10th', 'start': 24082, 'length': 2, 'signed': False, 'decimals': 1},
  150. {'name': 'voltage_harmonics_l3_n_11th', 'start': 24084, 'length': 2, 'signed': False, 'decimals': 1},
  151. {'name': 'voltage_harmonics_l3_n_12th', 'start': 24086, 'length': 2, 'signed': False, 'decimals': 1},
  152. {'name': 'voltage_harmonics_l3_n_13th', 'start': 24088, 'length': 2, 'signed': False, 'decimals': 1},
  153. {'name': 'voltage_harmonics_l3_n_14th', 'start': 24090, 'length': 2, 'signed': False, 'decimals': 1},
  154. {'name': 'voltage_harmonics_l3_n_15th', 'start': 24092, 'length': 2, 'signed': False, 'decimals': 1},
  155. {'name': 'voltage_harmonics_l3_n_16th', 'start': 24094, 'length': 2, 'signed': False, 'decimals': 1},
  156. {'name': 'voltage_harmonics_l1_l2_thd', 'start': 24192, 'length': 2, 'signed': False, 'decimals': 1},
  157. {'name': 'voltage_harmonics_l1_l2_2nd', 'start': 24194, 'length': 2, 'signed': False, 'decimals': 1},
  158. {'name': 'voltage_harmonics_l1_l2_3rd', 'start': 24196, 'length': 2, 'signed': False, 'decimals': 1},
  159. {'name': 'voltage_harmonics_l1_l2_4th', 'start': 24198, 'length': 2, 'signed': False, 'decimals': 1},
  160. {'name': 'voltage_harmonics_l1_l2_5th', 'start': 24200, 'length': 2, 'signed': False, 'decimals': 1},
  161. {'name': 'voltage_harmonics_l1_l2_6th', 'start': 24202, 'length': 2, 'signed': False, 'decimals': 1},
  162. {'name': 'voltage_harmonics_l1_l2_7th', 'start': 24204, 'length': 2, 'signed': False, 'decimals': 1},
  163. {'name': 'voltage_harmonics_l1_l2_8th', 'start': 24206, 'length': 2, 'signed': False, 'decimals': 1},
  164. {'name': 'voltage_harmonics_l1_l2_9th', 'start': 24208, 'length': 2, 'signed': False, 'decimals': 1},
  165. {'name': 'voltage_harmonics_l1_l2_10th', 'start': 24210, 'length': 2, 'signed': False, 'decimals': 1},
  166. {'name': 'voltage_harmonics_l1_l2_11th', 'start': 24212, 'length': 2, 'signed': False, 'decimals': 1},
  167. {'name': 'voltage_harmonics_l1_l2_12th', 'start': 24214, 'length': 2, 'signed': False, 'decimals': 1},
  168. {'name': 'voltage_harmonics_l1_l2_13th', 'start': 24216, 'length': 2, 'signed': False, 'decimals': 1},
  169. {'name': 'voltage_harmonics_l1_l2_14th', 'start': 24218, 'length': 2, 'signed': False, 'decimals': 1},
  170. {'name': 'voltage_harmonics_l1_l2_15th', 'start': 24220, 'length': 2, 'signed': False, 'decimals': 1},
  171. {'name': 'voltage_harmonics_l1_l2_16th', 'start': 24222, 'length': 2, 'signed': False, 'decimals': 1},
  172. {'name': 'voltage_harmonics_l3_l2_thd', 'start': 24320, 'length': 2, 'signed': False, 'decimals': 1},
  173. {'name': 'voltage_harmonics_l3_l2_2nd', 'start': 24322, 'length': 2, 'signed': False, 'decimals': 1},
  174. {'name': 'voltage_harmonics_l3_l2_3rd', 'start': 24324, 'length': 2, 'signed': False, 'decimals': 1},
  175. {'name': 'voltage_harmonics_l3_l2_4th', 'start': 24326, 'length': 2, 'signed': False, 'decimals': 1},
  176. {'name': 'voltage_harmonics_l3_l2_5th', 'start': 24328, 'length': 2, 'signed': False, 'decimals': 1},
  177. {'name': 'voltage_harmonics_l3_l2_6th', 'start': 24330, 'length': 2, 'signed': False, 'decimals': 1},
  178. {'name': 'voltage_harmonics_l3_l2_7th', 'start': 24332, 'length': 2, 'signed': False, 'decimals': 1},
  179. {'name': 'voltage_harmonics_l3_l2_8th', 'start': 24334, 'length': 2, 'signed': False, 'decimals': 1},
  180. {'name': 'voltage_harmonics_l3_l2_9th', 'start': 24336, 'length': 2, 'signed': False, 'decimals': 1},
  181. {'name': 'voltage_harmonics_l3_l2_10th', 'start': 24338, 'length': 2, 'signed': False, 'decimals': 1},
  182. {'name': 'voltage_harmonics_l3_l2_11th', 'start': 24340, 'length': 2, 'signed': False, 'decimals': 1},
  183. {'name': 'voltage_harmonics_l3_l2_12th', 'start': 24342, 'length': 2, 'signed': False, 'decimals': 1},
  184. {'name': 'voltage_harmonics_l3_l2_13th', 'start': 24344, 'length': 2, 'signed': False, 'decimals': 1},
  185. {'name': 'voltage_harmonics_l3_l2_14th', 'start': 24346, 'length': 2, 'signed': False, 'decimals': 1},
  186. {'name': 'voltage_harmonics_l3_l2_15th', 'start': 24348, 'length': 2, 'signed': False, 'decimals': 1},
  187. {'name': 'voltage_harmonics_l3_l2_16th', 'start': 24350, 'length': 2, 'signed': False, 'decimals': 1},
  188. {'name': 'voltage_harmonics_l1_l3_thd', 'start': 24448, 'length': 2, 'signed': False, 'decimals': 1},
  189. {'name': 'voltage_harmonics_l1_l3_2nd', 'start': 24450, 'length': 2, 'signed': False, 'decimals': 1},
  190. {'name': 'voltage_harmonics_l1_l3_3rd', 'start': 24452, 'length': 2, 'signed': False, 'decimals': 1},
  191. {'name': 'voltage_harmonics_l1_l3_4th', 'start': 24454, 'length': 2, 'signed': False, 'decimals': 1},
  192. {'name': 'voltage_harmonics_l1_l3_5th', 'start': 24456, 'length': 2, 'signed': False, 'decimals': 1},
  193. {'name': 'voltage_harmonics_l1_l3_6th', 'start': 24458, 'length': 2, 'signed': False, 'decimals': 1},
  194. {'name': 'voltage_harmonics_l1_l3_7th', 'start': 24460, 'length': 2, 'signed': False, 'decimals': 1},
  195. {'name': 'voltage_harmonics_l1_l3_8th', 'start': 24462, 'length': 2, 'signed': False, 'decimals': 1},
  196. {'name': 'voltage_harmonics_l1_l3_9th', 'start': 24464, 'length': 2, 'signed': False, 'decimals': 1},
  197. {'name': 'voltage_harmonics_l1_l3_10th', 'start': 24466, 'length': 2, 'signed': False, 'decimals': 1},
  198. {'name': 'voltage_harmonics_l1_l3_11th', 'start': 24468, 'length': 2, 'signed': False, 'decimals': 1},
  199. {'name': 'voltage_harmonics_l1_l3_12th', 'start': 24470, 'length': 2, 'signed': False, 'decimals': 1},
  200. {'name': 'voltage_harmonics_l1_l3_13th', 'start': 24472, 'length': 2, 'signed': False, 'decimals': 1},
  201. {'name': 'voltage_harmonics_l1_l3_14th', 'start': 24474, 'length': 2, 'signed': False, 'decimals': 1},
  202. {'name': 'voltage_harmonics_l1_l3_15th', 'start': 24476, 'length': 2, 'signed': False, 'decimals': 1},
  203. {'name': 'voltage_harmonics_l1_l3_16th', 'start': 24478, 'length': 2, 'signed': False, 'decimals': 1},
  204. {'name': 'current_harmonics_l1_thd', 'start': 24576, 'length': 2, 'signed': False, 'decimals': 1},
  205. {'name': 'current_harmonics_l1_2nd', 'start': 24578, 'length': 2, 'signed': False, 'decimals': 1},
  206. {'name': 'current_harmonics_l1_3rd', 'start': 24580, 'length': 2, 'signed': False, 'decimals': 1},
  207. {'name': 'current_harmonics_l1_4th', 'start': 24582, 'length': 2, 'signed': False, 'decimals': 1},
  208. {'name': 'current_harmonics_l1_5th', 'start': 24584, 'length': 2, 'signed': False, 'decimals': 1},
  209. {'name': 'current_harmonics_l1_6th', 'start': 24586, 'length': 2, 'signed': False, 'decimals': 1},
  210. {'name': 'current_harmonics_l1_7th', 'start': 24588, 'length': 2, 'signed': False, 'decimals': 1},
  211. {'name': 'current_harmonics_l1_8th', 'start': 24590, 'length': 2, 'signed': False, 'decimals': 1},
  212. {'name': 'current_harmonics_l1_9th', 'start': 24592, 'length': 2, 'signed': False, 'decimals': 1},
  213. {'name': 'current_harmonics_l1_10th', 'start': 24594, 'length': 2, 'signed': False, 'decimals': 1},
  214. {'name': 'current_harmonics_l1_11th', 'start': 24596, 'length': 2, 'signed': False, 'decimals': 1},
  215. {'name': 'current_harmonics_l1_12th', 'start': 24598, 'length': 2, 'signed': False, 'decimals': 1},
  216. {'name': 'current_harmonics_l1_13th', 'start': 24600, 'length': 2, 'signed': False, 'decimals': 1},
  217. {'name': 'current_harmonics_l1_14th', 'start': 24602, 'length': 2, 'signed': False, 'decimals': 1},
  218. {'name': 'current_harmonics_l1_15th', 'start': 24604, 'length': 2, 'signed': False, 'decimals': 1},
  219. {'name': 'current_harmonics_l1_16th', 'start': 24606, 'length': 2, 'signed': False, 'decimals': 1},
  220. {'name': 'current_harmonics_l2_thd', 'start': 24704, 'length': 2, 'signed': False, 'decimals': 1},
  221. {'name': 'current_harmonics_l2_2nd', 'start': 24706, 'length': 2, 'signed': False, 'decimals': 1},
  222. {'name': 'current_harmonics_l2_3rd', 'start': 24708, 'length': 2, 'signed': False, 'decimals': 1},
  223. {'name': 'current_harmonics_l2_4th', 'start': 24710, 'length': 2, 'signed': False, 'decimals': 1},
  224. {'name': 'current_harmonics_l2_5th', 'start': 24712, 'length': 2, 'signed': False, 'decimals': 1},
  225. {'name': 'current_harmonics_l2_6th', 'start': 24714, 'length': 2, 'signed': False, 'decimals': 1},
  226. {'name': 'current_harmonics_l2_7th', 'start': 24716, 'length': 2, 'signed': False, 'decimals': 1},
  227. {'name': 'current_harmonics_l2_8th', 'start': 24718, 'length': 2, 'signed': False, 'decimals': 1},
  228. {'name': 'current_harmonics_l2_9th', 'start': 24720, 'length': 2, 'signed': False, 'decimals': 1},
  229. {'name': 'current_harmonics_l2_10th', 'start': 24722, 'length': 2, 'signed': False, 'decimals': 1},
  230. {'name': 'current_harmonics_l2_11th', 'start': 24724, 'length': 2, 'signed': False, 'decimals': 1},
  231. {'name': 'current_harmonics_l2_12th', 'start': 24726, 'length': 2, 'signed': False, 'decimals': 1},
  232. {'name': 'current_harmonics_l2_13th', 'start': 24728, 'length': 2, 'signed': False, 'decimals': 1},
  233. {'name': 'current_harmonics_l2_14th', 'start': 24730, 'length': 2, 'signed': False, 'decimals': 1},
  234. {'name': 'current_harmonics_l2_15th', 'start': 24732, 'length': 2, 'signed': False, 'decimals': 1},
  235. {'name': 'current_harmonics_l2_16th', 'start': 24734, 'length': 2, 'signed': False, 'decimals': 1},
  236. {'name': 'current_harmonics_l3_thd', 'start': 24832, 'length': 2, 'signed': False, 'decimals': 1},
  237. {'name': 'current_harmonics_l3_2nd', 'start': 24834, 'length': 2, 'signed': False, 'decimals': 1},
  238. {'name': 'current_harmonics_l3_3rd', 'start': 24836, 'length': 2, 'signed': False, 'decimals': 1},
  239. {'name': 'current_harmonics_l3_4th', 'start': 24838, 'length': 2, 'signed': False, 'decimals': 1},
  240. {'name': 'current_harmonics_l3_5th', 'start': 24840, 'length': 2, 'signed': False, 'decimals': 1},
  241. {'name': 'current_harmonics_l3_6th', 'start': 24842, 'length': 2, 'signed': False, 'decimals': 1},
  242. {'name': 'current_harmonics_l3_7th', 'start': 24844, 'length': 2, 'signed': False, 'decimals': 1},
  243. {'name': 'current_harmonics_l3_8th', 'start': 24846, 'length': 2, 'signed': False, 'decimals': 1},
  244. {'name': 'current_harmonics_l3_9th', 'start': 24848, 'length': 2, 'signed': False, 'decimals': 1},
  245. {'name': 'current_harmonics_l3_10th', 'start': 24850, 'length': 2, 'signed': False, 'decimals': 1},
  246. {'name': 'current_harmonics_l3_11th', 'start': 24852, 'length': 2, 'signed': False, 'decimals': 1},
  247. {'name': 'current_harmonics_l3_12th', 'start': 24854, 'length': 2, 'signed': False, 'decimals': 1},
  248. {'name': 'current_harmonics_l3_13th', 'start': 24856, 'length': 2, 'signed': False, 'decimals': 1},
  249. {'name': 'current_harmonics_l3_14th', 'start': 24858, 'length': 2, 'signed': False, 'decimals': 1},
  250. {'name': 'current_harmonics_l3_15th', 'start': 24860, 'length': 2, 'signed': False, 'decimals': 1},
  251. {'name': 'current_harmonics_l3_16th', 'start': 24862, 'length': 2, 'signed': False, 'decimals': 1},
  252. {'name': 'current_harmonics_n_thd', 'start': 24960, 'length': 2, 'signed': False, 'decimals': 1},
  253. {'name': 'current_harmonics_n_2nd', 'start': 24962, 'length': 2, 'signed': False, 'decimals': 1},
  254. {'name': 'current_harmonics_n_3rd', 'start': 24964, 'length': 2, 'signed': False, 'decimals': 1},
  255. {'name': 'current_harmonics_n_4th', 'start': 24966, 'length': 2, 'signed': False, 'decimals': 1},
  256. {'name': 'current_harmonics_n_5th', 'start': 24968, 'length': 2, 'signed': False, 'decimals': 1},
  257. {'name': 'current_harmonics_n_6th', 'start': 24970, 'length': 2, 'signed': False, 'decimals': 1},
  258. {'name': 'current_harmonics_n_7th', 'start': 24972, 'length': 2, 'signed': False, 'decimals': 1},
  259. {'name': 'current_harmonics_n_8th', 'start': 24974, 'length': 2, 'signed': False, 'decimals': 1},
  260. {'name': 'current_harmonics_n_9th', 'start': 24976, 'length': 2, 'signed': False, 'decimals': 1},
  261. {'name': 'current_harmonics_n_10th', 'start': 24978, 'length': 2, 'signed': False, 'decimals': 1},
  262. {'name': 'current_harmonics_n_11th', 'start': 24980, 'length': 2, 'signed': False, 'decimals': 1},
  263. {'name': 'current_harmonics_n_12th', 'start': 24982, 'length': 2, 'signed': False, 'decimals': 1},
  264. {'name': 'current_harmonics_n_13th', 'start': 24984, 'length': 2, 'signed': False, 'decimals': 1},
  265. {'name': 'current_harmonics_n_14th', 'start': 24986, 'length': 2, 'signed': False, 'decimals': 1},
  266. {'name': 'current_harmonics_n_15th', 'start': 24988, 'length': 2, 'signed': False, 'decimals': 1},
  267. {'name': 'current_harmonics_n_16th', 'start': 24990, 'length': 2, 'signed': False, 'decimals': 1}]
  268. REGSETS = {
  269. "A43": ["active_import", "active_export", "active_net",
  270. "reactive_import", "reactive_export", "reactive_net",
  271. "apparent_import", "apparent_export", "apparent_net",
  272. "active_import_co2", "active_import_currency",
  273. "active_import_l1", "active_import_l2", "active_import_l3",
  274. "active_export_l1", "active_export_l2", "active_export_l3",
  275. "active_net_l1", "active_net_l2", "active_net_l3",
  276. "reactive_import_l1", "reactive_import_l2",
  277. "reactive_import_l3", "reactive_export_l1",
  278. "reactive_export_l2", "reactive_export_l3",
  279. "reactive_net_l1", "reactive_net_l2", "reactive_net_l3",
  280. "apparent_import_l1", "apparent_import_l2",
  281. "apparent_import_l3", "apparent_export_l1",
  282. "apparent_export_l2", "apparent_export_l3",
  283. "apparent_net_l1", "apparent_net_l2", "apparent_net_l3",
  284. "voltage_l1_n", "voltage_l2_n", "voltage_l3_n",
  285. "voltage_l1_l2", "voltage_l3_l2", "voltage_l1_l3",
  286. "current_l1", "current_l2", "current_l3",
  287. "active_power_total", "active_power_l1", "active_power_l2",
  288. "active_power_l3", "reactive_power_total",
  289. "reactive_power_l1", "reactive_power_l2",
  290. "reactive_power_l3", "apparent_power_total",
  291. "apparent_power_l1", "apparent_power_l2",
  292. "apparent_power_l3", "frequency", "phase_angle_power_total",
  293. "power_factor_total", "power_factor_l1", "power_factor_l2",
  294. "power_factor_l3", "current_quadrant_total",
  295. "current_quadrant_l1", "current_quadrant_l2",
  296. "current_quadrant_l3"],
  297. "B23": ["active_import", "active_export", "active_net",
  298. "reactive_import", "reactive_export", "reactive_net",
  299. "apparent_import", "apparent_export", "apparent_net",
  300. "active_import_co2", "active_import_currency",
  301. "active_import_l1", "active_import_l2", "active_import_l3",
  302. "active_export_l1", "active_export_l2", "active_export_l3",
  303. "active_net_l1", "active_net_l2", "active_net_l3",
  304. "reactive_import_l1", "reactive_import_l2",
  305. "reactive_import_l3", "reactive_export_l1",
  306. "reactive_export_l2", "reactive_export_l3",
  307. "reactive_net_l1", "reactive_net_l2", "reactive_net_l3",
  308. "apparent_import_l1", "apparent_import_l2",
  309. "apparent_import_l3", "apparent_export_l1",
  310. "apparent_export_l2", "apparent_export_l3",
  311. "apparent_net_l1", "apparent_net_l2", "apparent_net_l3",
  312. "voltage_l1_n", "voltage_l2_n", "voltage_l3_n",
  313. "voltage_l1_l2", "voltage_l3_l2", "voltage_l1_l3",
  314. "current_l1", "current_l2", "current_l3",
  315. "active_power_total", "active_power_l1", "active_power_l2",
  316. "active_power_l3", "reactive_power_total",
  317. "reactive_power_l1", "reactive_power_l2",
  318. "reactive_power_l3", "apparent_power_total",
  319. "apparent_power_l1", "apparent_power_l2",
  320. "apparent_power_l3", "frequency", "phase_angle_power_total",
  321. "power_factor_total", "power_factor_l1", "power_factor_l2",
  322. "power_factor_l3", "current_quadrant_total",
  323. "current_quadrant_l1", "current_quadrant_l2",
  324. "current_quadrant_l3"],
  325. "B21": ["active_import", "active_export", "active_net",
  326. "reactive_import", "reactive_export", "reactive_net",
  327. "apparent_import", "apparent_export", "apparent_net",
  328. "active_import_co2", "active_import_currency",
  329. "voltage_l1_n", "current_l1", "active_power_total",
  330. "reactive_power_total", "apparent_power_total", "frequency",
  331. "phase_angle_power_total", "power_factor_total",
  332. "current_quadrant_total"]
  333. }
  334. NULLS = [pow(2, n) - 1 for n in (64, 63, 32, 31, 16, 15)]
  335. class B21(ModbusRTUMeter):
  336. def __init__(self, port, baudrate=38400, slaveaddress=1, timeout=0.5):
  337. super().__init__(port, baudrate, slaveaddress, timeout)
  338. # Register map of the ABB A and B series energy meters.
  339. REGS = [{'name': 'active_import', 'start': 20480, 'length': 4, 'signed': True, 'decimals': 2},
  340. {'name': 'active_export', 'start': 20484, 'length': 4, 'signed': True, 'decimals': 2},
  341. {'name': 'active_net', 'start': 20488, 'length': 4, 'signed': True, 'decimals': 2},
  342. {'name': 'reactive_import', 'start': 20492, 'length': 4, 'signed': True, 'decimals': 2},
  343. {'name': 'reactive_export', 'start': 20496, 'length': 4, 'signed': True, 'decimals': 2},
  344. {'name': 'reactive_net', 'start': 20500, 'length': 4, 'signed': True, 'decimals': 2},
  345. {'name': 'apparent_import', 'start': 20504, 'length': 4, 'signed': True, 'decimals': 2},
  346. {'name': 'apparent_export', 'start': 20508, 'length': 4, 'signed': True, 'decimals': 2},
  347. {'name': 'apparent_net', 'start': 20512, 'length': 4, 'signed': True, 'decimals': 2},
  348. {'name': 'active_import_co2', 'start': 20516, 'length': 4, 'signed': True, 'decimals': 2},
  349. {'name': 'active_import_currency', 'start': 20532, 'length': 4, 'signed': True, 'decimals': 2},
  350. {'name': 'voltage_l1_n', 'start': 23296, 'length': 2, 'signed': False, 'decimals': 1},
  351. {'name': 'current_l1', 'start': 23308, 'length': 2, 'signed': False, 'decimals': 2},
  352. {'name': 'active_power_total', 'start': 23316, 'length': 2, 'signed': True, 'decimals': 2},
  353. {'name': 'reactive_power_total', 'start': 23324, 'length': 2, 'signed': True, 'decimals': 2},
  354. {'name': 'apparent_power_total', 'start': 23332, 'length': 2, 'signed': True, 'decimals': 2},
  355. {'name': 'frequency', 'start': 23340, 'length': 1, 'signed': False, 'decimals': 2},
  356. {'name': 'phase_angle_power_total', 'start': 23341, 'length': 1, 'signed': True, 'decimals': 1},
  357. {'name': 'power_factor_total', 'start': 23354, 'length': 1, 'signed': True, 'decimals': 3},
  358. {'name': 'current_quadrant_total', 'start': 23358, 'length': 1, 'signed': False, 'decimals': 0}]
  359. NULLS = [pow(2, n) - 1 for n in (64, 63, 32, 31, 16, 15)]
  360. class AsyncABBTCPMeter(AsyncModbusTCPMeter):
  361. def __init__(self, *args, **kwargs):
  362. super().__init__(*args, **kwargs)
  363. if type in ABBMeter.REGSETS:
  364. self.REGS = [register for register in ABBMeter._REGS if register['name'] in ABBMeter.REGSETS[type]]
  365. else:
  366. self.REGS = ABBMeter.REGS
  367. NULLS = ABBMeter.NULLS
  368. PROTOCOL_CODE = 0
  369. FUNCTION_CODE = 3
  370. REG_OFFSET = 0