Quickstart
These steps take one battery from off to 10 kW discharge and back to standby. For a first run, a Modbus tool is all you need. In your EMS, walk the SunSpec map instead of using these addresses: see the Register reference.
- Connect. Modbus TCP to the battery’s IP address, port 502, Unit ID 100 + its number. Registers 40000 and 40001 read
SunS. - Check it can run.
701_InvStdoes not read 6. At 6 a fault is active: see How it behaves. - Connect and start. Write
802_SetOp= 1,802_SetInvState= 3 and704_WSetEna= 1. - Set the power. Write
704_WSet= 100, both registers with function code 16. The register holds W / 100, so this is 10 kW discharge; −100 charges 10 kW. - Check.
701_Wreads about 100 within seconds: the battery acts on each write within 5 s, and the first start of the PCS adds a few seconds. - Stop. Write
704_WSet= 0. The PCS goes to standby.
| Step | Point | Address | Value |
|---|---|---|---|
| 2 | 701_InvSt |
40074 | read |
| 3 | 802_SetOp |
40457 | 1 |
| 3 | 802_SetInvState |
40458 | 3 |
| 3 | 704_WSetEna |
40299 | 1 |
| 4, 6 | 704_WSet |
40301–40302 | 100, then 0 |
| 5 | 701_W |
40080 | read |
The same in Python
Section titled “The same in Python”With pymodbus 3.10 or later:
import time
from pymodbus.client import ModbusTcpClient
UNIT = 101 # battery 1
client = ModbusTcpClient("192.0.2.100", port=502)client.connect()
def read(address, count=1): return client.read_holding_registers(address, count=count, device_id=UNIT).registers
def write(address, values): client.write_registers(address, values, device_id=UNIT) # function code 16
def int32(value): raw = value & 0xFFFFFFFF return [raw >> 16, raw & 0xFFFF] # high word first
def int16(raw): return raw - 0x10000 if raw >= 0x8000 else raw
assert read(40000, 2) == [0x5375, 0x6E53], "not a SunSpec device"assert read(40074)[0] != 6, "a fault is active" # 701_InvSt
write(40457, [1]) # 802_SetOp: connectwrite(40458, [3]) # 802_SetInvState: startwrite(40299, [1]) # 704_WSetEnawrite(40301, int32(round(10000 / 100))) # 704_WSet: 10 kW discharge
time.sleep(10) # the first start takes a few secondsinv_st = read(40074)[0] # 701_InvStwatts = int16(read(40080)[0]) * 100 # 701_W, W_SF = 2print(f"InvSt {inv_st}, {watts} W")
write(40301, int32(0)) # 704_WSet: standbyclient.close()