modbus_slave.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 30
  10. //#define COMMUNICATION_REG_ADDRESS 0 // 当前从机通讯地址
  11. #define POWER_REG_ADDRESS 0 // 电源地址
  12. #define WORK_MODE_REG_ADDRESS 1 // 运行模式
  13. #define FAN_SPEED_REG_ADDRESS 4 // 风扇转速
  14. #define SET_TEMP_REG_ADDRESS 14 // 设定温度
  15. #define INNER_GROUP1_REG_ADDRESS 10
  16. #define INNER_GROUP2_REG_ADDRESS 11
  17. #define TEMP_ON_FFX_ADDRESS 17
  18. #define TEMP_OFF_FFX_ADDRESS 18
  19. #define INNER_ERROR1_REG_ADDRESS 20 //40021
  20. #define INNER_ERROR2_REG_ADDRESS 21 //40022
  21. #define INNER_ERROR3_REG_ADDRESS 22
  22. #define INNER_ERROR4_REG_ADDRESS 23
  23. #define LED_ERROR_GPIO_Port GPIOB
  24. #define LED_ERROR_Pin GPIO_PIN_12
  25. /**
  26. * 开启485从机
  27. * @param address 从机地址
  28. */
  29. void start_485_slave(uint8_t address);
  30. /**
  31. * 设置故障位
  32. * @param offset 位偏移量
  33. */
  34. void set_err_code(uint8_t offset);
  35. /**
  36. * 清除故障位
  37. * @param offset 位偏移量
  38. */
  39. void clear_err_code(uint8_t offset);
  40. /**
  41. * 设置一个寄存器的值
  42. * @param regAddress
  43. */
  44. void set_reg_value(uint16_t regAddress, uint16_t value);
  45. /**
  46. * 读取一个寄存器的值
  47. * @param regAddress
  48. * @return
  49. */
  50. uint16_t get_reg_value(uint16_t regAddress);
  51. #endif //GMV_GATEWAY_BOARD_MODBUS_SLAVE_H