-
大小: 5.17MB文件類型: .zip金幣: 2下載: 0 次發(fā)布日期: 2023-08-17
- 語言: 其他
- 標簽: FreeModbus??Slave??
資源簡介
移植Freemodbus V1.5.0基于TI DK-TM4C129X 開發(fā)板。開發(fā)環(huán)境Keil MDK5.10

代碼片段和文件信息
/*?-----------------------?Modbus?includes?----------------------------------*/
#include?“mb.h“
#include?“mbport.h“
#include?“HAL_Interface.h“
#include?“mbutils.h“
/*?-----------------------?Defines?------------------------------------------*/
#define?REG_INPUT_START?0
#define?REG_INPUT_NREGS?4
/*?-----------------------?Static?variables?---------------------------------*/
static?USHORT???usRegInputStart?=?REG_INPUT_START;
static?USHORT???usRegInputBuf[REG_INPUT_NREGS]?=?{0x10x20x30x4};
//
#define?REG_HOLDING_START? 0
#define?REG_HOLDING_NREGS 10
static?USHORT???usRegHoldingStart?=?REG_HOLDING_START;
static?USHORT???usRegHoldingBuf[REG_HOLDING_NREGS]?=?{0x90x80x70x60x50x40x30x20x10x0};
//Coils
#define?REG_COILS_START?????0
#define?REG_COILS_SIZE??????16
static?unsigned?char?ucRegCoilsBuf[REG_COILS_SIZE?/?8]?=?{0xA50x5A};
//Read?Discrete?Inputs
#define?DISCRETE_INPUT_START 100
#define?DISCRETE_INPUT_SIZE 24
static?unsigned?char?ucDiscreteInputBuf[DISCRETE_INPUT_SIZE?/?8]?=?{0xA50x5A0xAA};
/*?-----------------------?Start?implementation?-----------------------------*/
int
main(?void?)
{
????const?UCHAR?????ucSlaveID[]?=?{?0xAA?0xBB?0xCC?};
????eMBErrorCode????eStatus;
Drv_SysClock_Init();
????eStatus?=?eMBInit(?MB_RTU?0x0A?0?115200?MB_PAR_EVEN?); //0x0A?is?slave?address
????eStatus?=?eMBSetSlaveID(?0x34?TRUE?ucSlaveID?3?);
????/*?Enable?the?Modbus?Protocol?Stack.?*/
????eStatus?=?eMBEnable(??);
????for(?;;?)
????{
????????(?void?)eMBPoll(??);
????????/*?Here?we?simply?count?the?number?of?poll?cycles.?*/
????????//usRegInputBuf[0]++;
????}
}
eMBErrorCode
eMBRegInputCB(?UCHAR?*?pucRegBuffer?USHORT?usAddress?USHORT?usNRegs?) //usAddress?has?add?1.
{
????eMBErrorCode????eStatus?=?MB_ENOERR;
????int?????????????iRegIndex;
usAddress?=?usAddress?-1;
????if(?(?usAddress?>=?REG_INPUT_START?)
????????&&?(?usAddress?+?usNRegs?<=?REG_INPUT_START?+?REG_INPUT_NREGS?)?)
????{
????????iRegIndex?=?(?int?)(?usAddress?-?usRegInputStart?);
????????while(?usNRegs?>?0?)
????????{
????????????*pucRegBuffer++?=
????????????????(?unsigned?char?)(?usRegInputBuf[iRegIndex]?>>?8?);
????????????*pucRegBuffer++?=
????????????????(?unsigned?char?)(?usRegInputBuf[iRegIndex]?&?0xFF?);
????????????iRegIndex++;
????????????usNRegs--;
????????}
????}
????else
????{
????????eStatus?=?MB_ENOREG;
????}
????return?eStatus;
}
eMBErrorCode
eMBRegHoldingCB(?UCHAR?*?pucRegBuffer?USHORT?usAddress?USHORT?usNRegs
?????????????????eMBRegisterMode?eMode?)
{
eMBErrorCode????eStatus?=?MB_ENOERR;
????int?????????????iRegIndex;
usAddress?=?usAddress?-?1;
????if(?(?usAddress?>=?REG_HOLDING_START?)?&&
????????(?usAddress?+?usNRegs?<=?REG_HOLDING_START?+?REG_HOLDING_NREGS?)?)
????{
????????iRegIndex?=?(?int?)(?usAddress?-?usRegHoldingStart?);
????????switch?(?eMode?)
????????{
????????????/*?Pass?current?register?values?to?the?protoc
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-06-26?15:45??TM4C129X\
?????文件??????????27??2014-06-07?15:45??TM4C129X\clear.bat
?????目錄???????????0??2014-06-26?15:45??TM4C129X\debug\
?????文件??????127187??2014-06-21?16:04??TM4C129X\debug\adc.crf
?????文件?????????509??2014-06-21?16:04??TM4C129X\debug\adc.d
?????文件??????126288??2014-06-21?16:04??TM4C129X\debug\adc.o
?????文件???????68936??2014-06-21?16:04??TM4C129X\debug\aes.crf
?????文件?????????548??2014-06-21?16:04??TM4C129X\debug\aes.d
?????文件???????75740??2014-06-21?16:04??TM4C129X\debug\aes.o
?????文件??????132243??2014-06-21?16:04??TM4C129X\debug\can.crf
?????文件?????????551??2014-06-21?16:04??TM4C129X\debug\can.d
?????文件??????128668??2014-06-21?16:04??TM4C129X\debug\can.o
?????文件???????29595??2014-06-21?16:04??TM4C129X\debug\comp.crf
?????文件?????????478??2014-06-21?16:04??TM4C129X\debug\comp.d
?????文件???????41676??2014-06-21?16:04??TM4C129X\debug\comp.o
?????文件????????3699??2014-06-21?16:04??TM4C129X\debug\cpu.crf
?????文件?????????137??2014-06-21?16:04??TM4C129X\debug\cpu.d
?????文件???????11856??2014-06-21?16:04??TM4C129X\debug\cpu.o
?????文件???????10804??2014-06-21?16:04??TM4C129X\debug\crc.crf
?????文件?????????373??2014-06-21?16:04??TM4C129X\debug\crc.d
?????文件???????22756??2014-06-21?16:04??TM4C129X\debug\crc.o
?????文件???????30510??2014-06-21?16:04??TM4C129X\debug\des.crf
?????文件?????????465??2014-06-21?16:04??TM4C129X\debug\des.d
?????文件???????43364??2014-06-21?16:04??TM4C129X\debug\des.o
?????文件??????122063??2014-06-21?16:04??TM4C129X\debug\eeprom.crf
?????文件?????????649??2014-06-21?16:04??TM4C129X\debug\eeprom.d
?????文件??????117892??2014-06-21?16:04??TM4C129X\debug\eeprom.o
?????文件??????119555??2014-06-21?16:04??TM4C129X\debug\emac.crf
?????文件?????????574??2014-06-21?16:04??TM4C129X\debug\emac.d
?????文件??????123100??2014-06-21?16:04??TM4C129X\debug\emac.o
?????文件??????122083??2014-06-08?16:15??TM4C129X\debug\epi.crf
............此處省略315個文件信息
- 上一篇:os課程設計 操作系統(tǒng)課程設計
- 下一篇:異常檢測與機器學習
評論
共有 條評論