12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- //
- // Created by DELL on 2024/10/18.
- //
- #ifndef GMV_GATEWAY_BOARD_MODBUS_SLAVE_H
- #define GMV_GATEWAY_BOARD_MODBUS_SLAVE_H
- #include "main.h"
- // 定义从机寄存器开始地址和长度
- #define S_REG_HOLDING_START 0
- #define S_REG_HOLDING_NREGS 20
- #define COMMUNICATION_REG_ADDRESS 0 // 当前从机通讯地址
- #define POWER_REG_ADDRESS 1 // 电源地址
- #define WORK_MODE_REG_ADDRESS 2
- #define FAN_SPEED_REG_ADDRESS 3
- #define SET_TEMP_REG_ADDRESS 4
- /**
- * 开启485从机
- * @param address 从机地址
- */
- void start_485_slave(uint8_t address);
- /**
- * 设置故障位
- * @param offset 位偏移量
- */
- void set_err_code(uint8_t offset);
- /**
- * 清除故障位
- * @param offset 位偏移量
- */
- void clear_err_code(uint8_t offset);
- /**
- * 设置一个寄存器的值
- * @param regAddress
- */
- void set_reg_value(uint16_t regAddress, uint16_t value);
- /**
- * 读取一个寄存器的值
- * @param regAddress
- * @return
- */
- uint16_t get_reg_value(uint16_t regAddress);
- #endif //GMV_GATEWAY_BOARD_MODBUS_SLAVE_H
|