modbus_slave.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // Created by DELL on 2024/10/18.
  3. //
  4. #ifndef GMV_GATEWAY_BOARD_MODBUS_SLAVE_H
  5. #define GMV_GATEWAY_BOARD_MODBUS_SLAVE_H
  6. #include "main.h"
  7. // 定义从机寄存器开始地址和长度
  8. #define S_REG_HOLDING_START 0
  9. #define S_REG_HOLDING_NREGS 20
  10. #define COMMUNICATION_REG_ADDRESS 0 // 当前从机通讯地址
  11. #define POWER_REG_ADDRESS 1 // 电源地址
  12. #define WORK_MODE_REG_ADDRESS 2
  13. #define FAN_SPEED_REG_ADDRESS 3
  14. #define SET_TEMP_REG_ADDRESS 4
  15. /**
  16. * 开启485从机
  17. * @param address 从机地址
  18. */
  19. void start_485_slave(uint8_t address);
  20. /**
  21. * 设置故障位
  22. * @param offset 位偏移量
  23. */
  24. void set_err_code(uint8_t offset);
  25. /**
  26. * 清除故障位
  27. * @param offset 位偏移量
  28. */
  29. void clear_err_code(uint8_t offset);
  30. /**
  31. * 设置一个寄存器的值
  32. * @param regAddress
  33. */
  34. void set_reg_value(uint16_t regAddress, uint16_t value);
  35. /**
  36. * 读取一个寄存器的值
  37. * @param regAddress
  38. * @return
  39. */
  40. uint16_t get_reg_value(uint16_t regAddress);
  41. #endif //GMV_GATEWAY_BOARD_MODBUS_SLAVE_H