As one of my personal projects, I created a four channel relay card with a Modbus interface. The card uses Modbus RTU to control and monitor the relays. There is a manual override on the device so the relays can be operated by hand. Because there is only one serial port, a jumper is used to place the relay card into configuration mode. When in configuration mode, various settings can be changed. The firmware is modular and the base state machine is designed to be used for any Modbus slave device. The state machine relies on callback functions to perform specific tasks on individual devices.
Modbus Relay Card RepositoryThe source code for this project was developed using Atmel Studios and was designed to be modular for future modbus products.
Modbus Relay Card Firmware