Skip to content

Creating a DER driver

jayatsandia edited this page Feb 13, 2019 · 7 revisions

Here are the step-by-step instructions for creating a DER driver:

  1. Connect a computer to the DER equipment via TCP/IP, serial, or other connection.
  2. Verify that you have communications with the device using ping, a modbus reader, or the vendor's software. Note the settings required to communicate with the equipment, e.g., IP address, port, slave ID, baudrate, parity, comm interface, etc.
  3. Determine if the device is SunSpec-compliant using the SunSpec Dashboard. If it is, you can simply use the der_sunspec.py driver and there's no additional work required.
  4. If the device is not sunspec compliant, you will need to build a new driver that includes this device's Modbus register map.
  5. Please copy the SMA example and rename it: https://github.com/sunspec/svp_energy_lab/blob/dev/Lib/svpelab/der_sma.py
  6. If you have a TCP/IP-connected device, this example will work well and all that needs to happen is to replace the registers in the file.
  7. If you have a RTU connected device, the following code should be used to connect to the equipment:

import sunspec.core.modbus.client as client

inv = client.ModbusClientDeviceRTU(slave_id=2, name='com5', baudrate=19200, parity=None, timeout=2)

Note the client parameters are documented here: https://github.com/sunspec/pysunspec/blob/master/sunspec/core/modbus/client.py

Once you have created the inv object, you can read data from the device using commands like:

power = util.data_to_s32(inv.read(30775, 2))​ # which reads two holding registers starting at 30775

And write to the device using commands like:

reg_value = int(abs(round(pf, 4) * 10000))

inv.write(40024, util.u16_to_data(int(reg_value))) # which writes a 16 bit unsigned integer to register 40024

The one thing that we've seen a problem with is that the register numbers in documentation do not always align perfectly with the Modbus read tools because they start the index in a different place. If you can use some simple tools to verify the registers, this should work for you. Just be aware that you may need to shift the registers one or two numbers from the DER reported values. Hopefully not.