modbus_master.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @Author: 李建
  3. * @Date: 2025/4/27 15:35
  4. * Description: 485主站
  5. * Copyright: Copyright (©) 2025 永续绿建. All rights reserved.
  6. */
  7. #ifndef WIRE_CONTROLLER_MODBUS_MASTER_H
  8. #define WIRE_CONTROLLER_MODBUS_MASTER_H
  9. #include "esp_err.h"
  10. #include "esp_modbus_master.h"
  11. #define MB_PORT_NUM 2 // Number of UART port used for Modbus connection
  12. #define MB_DEV_SPEED 9600 // The communication speed of the UART
  13. #define MB_GPIO_RX 2 // uart rx gpio port
  14. #define MB_GPIO_TX 1 // uart tx gpio port
  15. #define HP_SET_MODE_REG_ADDRESS 0x01 // 热泵设置模式
  16. #define HP_COOL_SET_TEMP_REG_ADDRESS 0x02 // 制冷水温设定
  17. #define HP_HEAT_SET_TEMP_REG_ADDRESS 0x03 // 制热水温设定
  18. #define HP_OUTDOOR_TEMP_REG_ADDRESS 46
  19. #define HP_OUT_WATER_TEMP_REG_ADDRESS 67
  20. #define HP_IN_WATER_TEMP_REG_ADDRESS 68
  21. #define RELAY_1_STATUS_REG_ADDRESS 0x01 // 第一路继电器状态
  22. #define RELAY_2_STATUS_REG_ADDRESS 0x02 // 第二路继电器状态
  23. #define RELAY_3_STATUS_REG_ADDRESS 0x03 // 第三路继电器状态
  24. #define RELAY_4_STATUS_REG_ADDRESS 0x04 // 第四路继电器状态
  25. #define RELAY_5_STATUS_REG_ADDRESS 0x05 // 第五路继电器状态
  26. #define RELAY_6_STATUS_REG_ADDRESS 0x06 // 第六路继电器状态
  27. #define RELAY_7_STATUS_REG_ADDRESS 0x07 // 第七路继电器状态
  28. #define RELAY_8_STATUS_REG_ADDRESS 0x08 // 第八路继电器状态
  29. #define MODIFY_COMMUNICATION_ADDRESS_REGISTER 0x09 // 修改通讯地址码
  30. // 定义协议 CID 表
  31. enum {
  32. CID_HP_SET_MODE,
  33. CID_HP_COOL_SET_TEMP,
  34. CID_HP_HEAT_SET_TEMP,
  35. CID_HP_OUTDOOR_TEMP,
  36. CID_HP_OUT_WATER_TEMP,
  37. CID_HP_IN_WATER_TEMP,
  38. CID_HP_POWER,
  39. CID_HP_ERROR,
  40. CID_RELAY_1_STATUS,
  41. CID_RELAY_2_STATUS,
  42. CID_RELAY_3_STATUS,
  43. CID_RELAY_4_STATUS,
  44. CID_RELAY_5_STATUS,
  45. CID_RELAY_6_STATUS,
  46. CID_RELAY_7_STATUS,
  47. CID_RELAY_8_STATUS,
  48. CID_MODIFY_COMMUNICATION_ADDRESS,
  49. };
  50. void modbus_master_init();
  51. esp_err_t mm_set_param(uint16_t cid, uint8_t *value);
  52. /**
  53. * 发送 modbus 请求
  54. * @param request
  55. * @param data_prt
  56. * @return
  57. */
  58. esp_err_t send_request(mb_param_request_t *request, void *data_prt);
  59. void modbus_master_destroy();
  60. #endif //WIRE_CONTROLLER_MODBUS_MASTER_H