118 lines
2.7 KiB
C
118 lines
2.7 KiB
C
|
|
/*
|
|||
|
|
*********************************************************************************************************
|
|||
|
|
*
|
|||
|
|
* ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : MODEBUS ͨ<EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD> (<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
* <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : modbus_host.h
|
|||
|
|
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : V1.4
|
|||
|
|
* ˵ <EFBFBD><EFBFBD> : ͷ<EFBFBD>ļ<EFBFBD>
|
|||
|
|
*
|
|||
|
|
* Copyright (C), 2020-2030, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> www.armfly.com
|
|||
|
|
*
|
|||
|
|
*********************************************************************************************************
|
|||
|
|
*/
|
|||
|
|
#ifndef __MOSBUS_HOST_H
|
|||
|
|
#define __MOSBUS_HOST_H
|
|||
|
|
|
|||
|
|
#define SlaveAddr 0x01 /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊʱ<CEAA><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD> */
|
|||
|
|
#define HBAUD485 UART3_BAUD
|
|||
|
|
|
|||
|
|
/* 01H <20><>ǿ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>Ȧ */
|
|||
|
|
/* 05H дǿ<D0B4>Ƶ<EFBFBD><C6B5><EFBFBD>Ȧ */
|
|||
|
|
#define REG_D01 0x0101
|
|||
|
|
#define REG_D02 0x0102
|
|||
|
|
#define REG_D03 0x0103
|
|||
|
|
#define REG_D04 0x0104
|
|||
|
|
#define REG_DXX REG_D04
|
|||
|
|
|
|||
|
|
/* 02H <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>״̬ */
|
|||
|
|
#define REG_T01 0x0201
|
|||
|
|
#define REG_T02 0x0202
|
|||
|
|
#define REG_T03 0x0203
|
|||
|
|
#define REG_TXX REG_T03
|
|||
|
|
|
|||
|
|
/* 03H <20><><EFBFBD><EFBFBD><EFBFBD>ּĴ<D6BC><C4B4><EFBFBD> */
|
|||
|
|
/* 06H д<><D0B4><EFBFBD>ּĴ<D6BC><C4B4><EFBFBD> */
|
|||
|
|
/* 10H д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD> */
|
|||
|
|
#define REG_P01 0x0301
|
|||
|
|
#define REG_P02 0x0302
|
|||
|
|
|
|||
|
|
/* 04H <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>(ģ<><C4A3><EFBFBD>ź<EFBFBD>) */
|
|||
|
|
#define REG_A01 0x0401
|
|||
|
|
#define REG_AXX REG_A01
|
|||
|
|
|
|||
|
|
/* RTU Ӧ<><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
#define RSP_OK 0 /* <20>ɹ<EFBFBD> */
|
|||
|
|
#define RSP_ERR_CMD 0x01 /* <20><>֧<EFBFBD>ֵĹ<D6B5><C4B9><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
#define RSP_ERR_REG_ADDR 0x02 /* <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD> */
|
|||
|
|
#define RSP_ERR_VALUE 0x03 /* <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
#define RSP_ERR_WRITE 0x04 /* д<><D0B4>ʧ<EFBFBD><CAA7> */
|
|||
|
|
|
|||
|
|
#define H_RX_BUF_SIZE 64
|
|||
|
|
#define H_TX_BUF_SIZE 128
|
|||
|
|
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
uint8_t RxBuf[H_RX_BUF_SIZE];
|
|||
|
|
uint8_t RxCount;
|
|||
|
|
uint8_t RxStatus;
|
|||
|
|
uint8_t RxNewFlag;
|
|||
|
|
|
|||
|
|
uint8_t RspCode;
|
|||
|
|
|
|||
|
|
uint8_t TxBuf[H_TX_BUF_SIZE];
|
|||
|
|
uint8_t TxCount;
|
|||
|
|
|
|||
|
|
uint16_t Reg01H; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ļĴ<C4BC><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ */
|
|||
|
|
uint16_t Reg02H;
|
|||
|
|
uint16_t Reg03H;
|
|||
|
|
uint16_t Reg04H;
|
|||
|
|
|
|||
|
|
uint8_t RegNum; /* <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
|
|||
|
|
uint8_t fAck01H; /* Ӧ<><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ 0 <20><>ʾִ<CABE><D6B4>ʧ<EFBFBD><CAA7> 1<><31>ʾִ<CABE>гɹ<D0B3> */
|
|||
|
|
uint8_t fAck02H;
|
|||
|
|
uint8_t fAck03H;
|
|||
|
|
uint8_t fAck04H;
|
|||
|
|
uint8_t fAck05H;
|
|||
|
|
uint8_t fAck06H;
|
|||
|
|
uint8_t fAck10H;
|
|||
|
|
|
|||
|
|
}MODH_T;
|
|||
|
|
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
/* 03H 06H <20><>д<EFBFBD><D0B4><EFBFBD>ּĴ<D6BC><C4B4><EFBFBD> */
|
|||
|
|
uint16_t P01;
|
|||
|
|
uint16_t P02;
|
|||
|
|
|
|||
|
|
/* 02H <20><>д<EFBFBD><D0B4>ɢ<EFBFBD><C9A2><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD> */
|
|||
|
|
uint16_t T01;
|
|||
|
|
uint16_t T02;
|
|||
|
|
uint16_t T03;
|
|||
|
|
|
|||
|
|
/* 04H <20><>ȡģ<C8A1><C4A3><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD> */
|
|||
|
|
uint16_t A01;
|
|||
|
|
|
|||
|
|
/* 01H 05H <20><>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF><EFBFBD><EFBFBD>Ȧ */
|
|||
|
|
uint16_t D01;
|
|||
|
|
uint16_t D02;
|
|||
|
|
uint16_t D03;
|
|||
|
|
uint16_t D04;
|
|||
|
|
|
|||
|
|
}VAR_T;
|
|||
|
|
|
|||
|
|
void MODH_Poll(void);
|
|||
|
|
uint8_t MODH_ReadParam_01H(uint16_t _reg, uint16_t _num);
|
|||
|
|
uint8_t MODH_ReadParam_02H(uint16_t _reg, uint16_t _num);
|
|||
|
|
uint8_t MODH_ReadParam_03H(uint16_t _reg, uint16_t _num);
|
|||
|
|
uint8_t MODH_ReadParam_04H(uint16_t _reg, uint16_t _num);
|
|||
|
|
uint8_t MODH_WriteParam_05H(uint16_t _reg, uint16_t _value);
|
|||
|
|
uint8_t MODH_WriteParam_06H(uint16_t _reg, uint16_t _value);
|
|||
|
|
uint8_t MODH_WriteParam_10H(uint16_t _reg, uint8_t _num, uint8_t *_buf);
|
|||
|
|
|
|||
|
|
extern MODH_T g_tModH;
|
|||
|
|
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
/***************************** <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> www.armfly.com (END OF FILE) *********************************/
|