sdm_setid.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/python3 -u
  2. # -*- coding: utf-8 -*-
  3. #
  4. import minimalmodbus
  5. import sys
  6. serialdevice = '/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AK05DZIG-if00-port0'
  7. if len(sys.argv) == 2:
  8. id = int(sys.argv[1])
  9. idnew = int(sys.argv[2])
  10. if id > 0 and id <= 247:
  11. if idnew > 0 and idnew <= 247:
  12. print("New ID out of range")
  13. exit()
  14. else:
  15. meter_id = tmpid
  16. meter_id_new = tmpidnew
  17. else:
  18. print("ID out of range")
  19. exit()
  20. elif len(sys.argv) == 1:
  21. id = 1
  22. idnew = int(sys.argv[1])
  23. if idnew <= 0 and idnew > 247:
  24. print("New ID out of range")
  25. exit()
  26. else:
  27. print("Usage: sdm_setid.py [oldID] [newID]")
  28. exit()
  29. exit()
  30. rs485 = minimalmodbus.Instrument(serialdevice, meter_id)
  31. rs485.serial.baudrate = 2400
  32. rs485.serial.bytesize = 8
  33. rs485.serial.parity = minimalmodbus.serial.PARITY_NONE
  34. rs485.serial.stopbits = 1
  35. rs485.serial.timeout = 1
  36. rs485.debug = False
  37. rs485.mode = minimalmodbus.MODE_RTU
  38. print(rs485)
  39. # Modbus Parity
  40. # Addr 0x0012
  41. # 4 byte float
  42. # 0 = 1 stop bit, no parity (default)
  43. # 1 = 1 stop bit, even parity
  44. # 2 = 1 stop bit, odd parity
  45. # 3 = 2 stop bits, no parity
  46. #rs485.write_float(0x0012, meter_id_new, number_of_registers=2)
  47. # Meter ID
  48. # Addr 0x0014
  49. # 4 byte float
  50. # 1-247, default 1
  51. rs485.write_float(0x0014, meter_id_new, number_of_registers=2)
  52. # Baud rate
  53. # Addr 0x00C1
  54. # 4 byte float
  55. # 0 = 2400 (default)
  56. # 1 = 4800
  57. # 2 = 9600
  58. # 5 = 1200
  59. #rs485.write_float(0x00C1, meter_id_new, number_of_registers=2)
  60. # Pulse 1 output mode
  61. # Addr 0x0056
  62. # 4 byte float
  63. # 1 = Import Active Energy
  64. # 2 = Import + Export Active Energy
  65. # 4 = Export Active Energy (default)
  66. # 5 = Import Reactive Energy
  67. # 8 = Export Reactive Energy
  68. #rs485.write_float(0x0056, meter_id_new, number_of_registers=2)
  69. # Time of scroll display
  70. # Addr 0xF900
  71. # 2 byte HEX
  72. # Range 0-30s
  73. # 0 = does not display in turns
  74. #rs485.write_register(0xF900, meter_id_new, number_of_registers=1)
  75. # Pulse 1 output
  76. # Addr 0xF910
  77. # 2 byte HEX
  78. # 0000 = 0.001 kWh/imp (default)
  79. # 0001 = 0.01 kWh/imp
  80. # 0002 = 0.1 kWh/imp
  81. # 0003 = 1 kWh/imp
  82. #rs485.write_register(0xF910, meter_id_new, number_of_registers=1)
  83. # Measurement mode
  84. # Addr 0xF920
  85. # 2 byte HEX
  86. # 0001 = mode 1 (total = import)
  87. # 0002 = mode 2 (total = import + export) (default)
  88. # 0003 = mode 3 (total = import - export)
  89. #rs485.write_register(0xF920, meter_id_new, number_of_registers=1)