#ifndef __MODBUSRTU_H #define __MODBUSRTU_H #include "project_var.h" #define ADDR_CONV_COUNT 7 #define AIR_FRAME_COUNT 8 typedef void (*FuncSend_TypeDef)(const u8 *data, u16 count); typedef void (*FuncCommand_TypeDef)(void); #pragma pack(1) // ModbusRtu 03请求帧 typedef struct { u8 addr; u8 function; // u16 register_addr; u16 register_count; u16 crc; } ModbusRtu_03Frame_Tx_TypeDef; union ModbusRtu_03Frame_Tx_Union_TypeDef { ModbusRtu_03Frame_Tx_TypeDef Frame03; // u8 send_buff[16]; }; #pragma pack() // 取消自定义字节对齐方式 // typedef struct { u16 register_addr; // u16 register_count; // u16 frame_style; } Modbus_Frame_TypeDef; extern void (*func_modbus_send_frame[7])(u16 register_addr, u16 count, void (*Func_Send)(const u8 *data, u16 count)); void mosbus_send_frame01(u16 register_addr, u16 count, FuncSend_TypeDef FuncSend); void mosbus_send_frame02(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send); void mosbus_send_frame03(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send); void mosbus_send_frame04(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send); void mosbus_send_frame05(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send); void mosbus_send_frame06(u16 register_addr, u16 count, FuncSend_TypeDef Func_Send); unsigned short count_crc(const u8 *addr, int num); #endif