emelianov / modbus-esp8266

Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.
Other
534 stars 190 forks source link

Add Modbus function to reset a Power Monitor #335

Closed dakriege closed 7 months ago

dakriege commented 9 months ago

I'm using the library with an Adafruit ESP32-3 and a Modbus Power Monitor.

The Power Monitor has a KWH Totalizer that can be reset using a custom Modbus Command 0x42.

The format of the command is SlaveID + 0x42 + CRC High Byte + CRC Low Byte

The reply length is 0 bytes. -> SlaveID + 0x42 + CRC High Byte + CRC Low Byte

Using a SAND51 processor and the Arduino Modbus library it was pretty easy to add the 0x42 function.

Can you offer any help in adding the 0x42 command or a means to send raw data to create a custom message.

dakriege commented 9 months ago

This issue was resolved using the Raw Request function. I added a 0x42 function code in the modbus.h file so that it could be used in the MasterPDU switch statement that tests the reply function code returned in the slave response.