modbus.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef __MODBUSRTU_H
  2. #define __MODBUSRTU_H
  3. #include "project_var.h"
  4. #define ADDR_CONV_COUNT 7
  5. #define AIR_FRAME_COUNT 8
  6. typedef void (*FuncSend_TypeDef)(const u8 *data, u16 count);
  7. typedef void (*FuncCommand_TypeDef)(void);
  8. #pragma pack(1)
  9. // ModbusRtu 03请求帧
  10. typedef struct
  11. {
  12. u8 addr;
  13. u8 function; //
  14. u16 register_addr;
  15. u16 register_count;
  16. u16 crc;
  17. } ModbusRtu_03Frame_Tx_TypeDef;
  18. union ModbusRtu_03Frame_Tx_Union_TypeDef
  19. {
  20. ModbusRtu_03Frame_Tx_TypeDef Frame03; //
  21. u8 send_buff[16];
  22. };
  23. #pragma pack() // 取消自定义字节对齐方式
  24. //
  25. typedef struct
  26. {
  27. u16 register_addr; //
  28. u16 register_count; //
  29. u16 frame_style;
  30. } Modbus_Frame_TypeDef;
  31. extern void (*func_modbus_send_frame[7])(u16 register_addr, u16 count, void (*Func_Send)(const u8 *data, u16 count));
  32. void mosbus_send_frame01(u16 register_addr, u16 count, FuncSend_TypeDef FuncSend);
  33. void mosbus_send_frame02(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send);
  34. void mosbus_send_frame03(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send);
  35. void mosbus_send_frame04(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send);
  36. void mosbus_send_frame05(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send);
  37. void mosbus_send_frame06(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send);
  38. unsigned short count_crc(const u8 *addr, int num);
  39. #endif