📄 gcontrol.c
字号:
#include "gcontrol.h"
/* ALL TAGS */
FTag TAGS[TAG_MAX_NUM];
/* OUTPUT TAGS */
FTagGroup OUTTAGS[OUTTAG_MAX_NUM];
/* ALL Groups */
FTagGroup GROUPS[GRP_MAX_NUM];
/* FIIO object for Uart IO */
FIIO* pUartIO;
/* Initialize */
Boolean gcol_Init(FUART* uartCfg)
{
UDATA uduartconf;
// 初始化串口
uduartconf.p = uartCfg;
pUartIO = UartCreate(uduartconf);
if( FioOpen(pUartIO) == False)
return False;
if( FioConfig(pUartIO, uduartconf) == False)
return False;
return True;
}
/* free resources */
VOID gcol_Dispose()
{
if(pUartIO != NULL)
{
FioClose(pUartIO);
UartDestroy(pUartIO->pObj);
}
}
/* Gather data by Tag */
INT16 gcol_Gather(FInstrument* instrument)
{
if(instrument->TagNum > 0)
{
FMBIOBUF fmbReq,rBuff;
BYTE TAG_RSW;
REGINT tagMode = RTU;
Boolean status = False;
UINT16 tindex = 0;
INT32 count = 0;
//采集一个modbus单元
FmbReqSetAdr ( fmbReq, instrument->Adr );
FmbReqSetFun ( fmbReq, instrument->Fun );
FmbReqSetR1 ( fmbReq, instrument->Reg0);
FmbReqSetRN ( fmbReq, instrument->RegNum);
FmbReqMakeBuffer( fmbReq, tagMode );
FioWrite(pUartIO, fmbReq, 8 );
usleep(1500000);
count = FioRead (pUartIO, rBuff, FMB_MAX_BUF_SIZE);
status = count>0?True:False;
//status = count<=0?False:FmbRspParseBuffer(rBuff, tagMode);
//采集正常
if( status == True )
{
//modbus cmd分解
for(tindex=0; tindex<instrument->TagNum; tindex++)
{
instrument->Tag[tindex]->wValue = FmbRspGetData(rBuff, instrument->RegNO[tindex]);
instrument->Tag[tindex]->Status = TAG_STATUS_OK;
instrument->Tag[tindex]->RSW = 0;
if(instrument->RegTYPE[tindex] == INSTRU_TYPE_20A)
instrument->Tag[tindex]->RSW = 1;
}
}
else
{
for(tindex=0; tindex<instrument->TagNum; tindex++)
{
instrument->Tag[tindex]->Status = TAG_STATUS_ERROR;
instrument->Tag[tindex]->RSW = 0;
if(instrument->RegTYPE[tindex] == INSTRU_TYPE_20A)
instrument->Tag[tindex]->RSW = 1;
}
}
return 1;
}
else
{
return 0;
}
}
/* Gather data by group */
INT16 gcol_GatherGrp(FTagGroup* group)
{
REGINT index;
INT16 count;
//foreach Instrument.
for(index=0,count=0; index<group->InstruNum; index++)
{
count += gcol_Gather( &group->Instru[index] );
sleep(2);
}
return count;
}
/* wait for inuring*/
Boolean gcol_WaitForInured()
{
//等待modbus使能信号
return True;
}
/* release bus handing*/
VOID gcol_Halt()
{
//释放modbus总线
}
/* check tag status */
Boolean gcol_ValidStatus(FTag* tag)
{
return (tag->Status < 0x02)?True:False;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -