1. FB_EcCoESdoReadEx功能块
功能块位置
实验结果
2. FB_EcCoESdoWriteEx
功能块位置
实验结果
3. C++调用PLC功能块
相关代码(仅供参考)
PLC:TcQueryInterface
变量定义区:
{attribute 'c++_compatible'}
{attribute 'minimal_input_size' := '4'}
{attribute 'pack_mode' := '4'}
//{error '添加方法实现或删除属性以使用基本实现'}
METHOD TcQueryInterface : HRESULT
VAR_INPUT
iid : REFERENCE TO IID;
pipItf : POINTER TO PVOID;
ipCalc: I_Calculation;
END_VAR
程序区:
IF GuidsEqual(pGuidA:= ADR(iid),
pGuidB:= ADR(TC_GLOBAL_IID_LIST.IID_I_Calculation)) THEN
ipCalc := THIS^;
pipItf^ := ITCUNKNOWN_TO_PVOID(ipCalc);
TcAddRef();
TcQueryInterface := S_OK;
ELSE
TcQueryInterface := SUPER^.TcQueryInterface(iid,pipItf);
END_IF
C++: cycleUpdate()
if ((m_spCalculation == NULL) && m_Inputs.oidProvider != 0) {
m_spCalculation.SetOID(m_Inputs.oidProvider);
m_spSrv->TcQuerySmartObjectInterface(m_spCalculation);
}
if (m_spCalculation != NULL) {
m_spCalculation->Addition(m_Inputs.nln1,m_Inputs.nln2,m_Outputs.m_resAdd);
m_spCalculation->Subtraction(m_Inputs.nln1, m_Inputs.nln2, m_Outputs.m_resSub);
}
4. PLC资源库综合调试
变量声明区
PROGRAM MAIN
VAR
netId:T_AmsNetId;
SlaveAddrArray : ARRAY[1..2] OF UINT;
getAllSlaveAddrExe,getAllSlaveStateExe,getMasterStateExe,getSlaveStateExe,reqMasterStateExe,setMasterStateExe,getAllSlaveAbnormalStateExe,getAllSyncUnitSalveAddrExe : BOOL;
timeOut:TIME;
slavStateArray: ARRAY[1..2] OF ST_EcSlaveState;
slaveAbnormalStateArray : ARRAY [1..2] OF UDINT;
allSyncUnitSlaveAddrArray : ARRAY [1..2] OF UINT;
getAllSlaveAddr: FB_EcGetAllSlaveAddr;
getAllSlaveStates: FB_EcGetAllSlaveStates;
getMasterState: FB_EcGetMasterState;
getSlaveState: FB_EcGetSlaveState;
reqMasterState: FB_EcReqMasterState;
setMasterState: FB_EcSetMasterState;
getAllSlaveAbnormalState: FB_EcGetAllSlaveAbnormalStateChanges;
getAllSyncUnitSalveAddr: FB_EcGetAllSyncUnitSlaveAddr;
objID: OTCID;
END_VAR
程序区
netId := '192.168.5.221.3.1';
timeOut := T#5S;
objID := 16#03040020;
getAllSlaveAddr(
sNetId:= netId,
pAddrBuf:= ADR(SlaveAddrArray),
cbBufLen:= SIZEOF(SlaveAddrArray),
bExecute:= getAllSlaveAddrExe,
tTimeout:= timeOut,
bBusy=> ,
bError=> ,
nErrId=> ,
nSlaves=> );
getAllSlaveStates(
sNetId:= netId,
pStateBuf:= ADR(slavStateArray),
cbBufLen:= SIZEOF(slavStateArray),
bExecute:= getAllSlaveStateExe,
tTimeout:= timeOut,
bBusy=> ,
bError=> ,
nErrId=> ,
nSlaves=> );
getMasterState(
sNetId:= netId,
bExecute:= getMasterStateExe,
tTimeout:= timeOut,
bBusy=> ,
bError=> ,
nErrId=> ,
state=> );
getSlaveState(
sNetId:= netId,
nSlaveAddr:= SlaveAddrArray[1],
bExecute:= getSlaveStateExe,
tTimeout:= timeOut,
bBusy=> ,
bError=> ,
nErrId=> ,
state=> );
reqMasterState(
sNetId:= netId,
bExecute:= reqMasterStateExe,
tTimeout:= timeOut,
state:= EC_DEVICE_STATE_SAFEOP,
bBusy=> ,
bError=> ,
nErrId=> );
setMasterState(
sNetId:= netId,
bExecute:= setMasterStateExe,
tTimeout:= timeOut,
reqState:= EC_DEVICE_STATE_OP,
bBusy=> ,
bError=> ,
nErrId=> ,
currState=> );
getAllSlaveAbnormalState(
sNetId:=netId ,
pAddrBuf:= ADR(slaveAbnormalStateArray),
cbBufLen:= SIZEOF(slaveAbnormalStateArray),
bExecute:= getAllSlaveAbnormalStateExe,
tTimeout:= timeOut,
bBusy=> ,
bError=> ,
nErrId=> ,
nSlaves=> );
getAllSyncUnitSalveAddr(
sNetId:= netId,
nObjectId:= objID,
pAddrBuf:= ADR(allSyncUnitSlaveAddrArray),
cbBufLen:= SIZEOF(allSyncUnitSlaveAddrArray),
bExecute:= getAllSyncUnitSalveAddrExe,
tTimeout:= timeOut,
bBusy=> ,
bError=> ,
nErrId=> ,
nSlaves=> );