EtherCAT从站重启及状态检测
(* 示例1 :检查单个从站状态 *)
VAR
nSlaveState:ETC_SLAVE_STATE;
pSlave:POINTER TO ETCSlave;
END_VAR
InoSV630N(xSetOperational:= TRUE, wState=> nSlaveState);
(* 示例2: 检查所有从站链接 *) VAR_INPUT Check_En :BOOL:=FALSE;//监测使能 Check_Delay :UINT:=30000;//监测延时,初始值30000ms END_VAR VAR_OUTPUT InitialConfigureDone :BOOL;//ETC初始配置完成 InitialConfigFail :BOOL;//ETC初始配置失败 SlaveError :BOOL;//ETC从站错误 SlaveErrorld :UINT;//ETC最小站号 END_VAR VAR i :UINT; VB_SlaveState :BOOL; TON_0 :TON; pSlave :POINTER TO ETCSlave; VB_SlaveError :ARRAY[0..31] OF BOOL; END_VAR //----------------------------上电监测---------------------------- InitialConfigureDone S=Check_En AND ethercat.xConfigFinished AND ethercat.xDistributedClockInSync AND NOT ethercat.xError; //无EtherCAT总线时会报错 InitialConfigureDone R=NOT Check_En; InitialConfigFail :=TON_0.Q ; TON_0(IN:=Check_En AND NOT InitialConfigureDone, PT:=UINT_TO_TIME(Check_Delay) , Q=> , ET=> ); //--------------------------运行监测------------------------------- IF InitialConfigureDone THEN SlaveError R=TRUE; pSlave :=ethercat.FirstSlave; i :=1; WHILE pSlave <>0 DO pSlave^(); IF pSlave^.wState =ETC_SLAVE_STATE.ETC_SLAVE_OPERATIONAL THEN VB_SlaveState:=FALSE; ELSE VB_SlaveState:=TRUE; END_IF VB_SlaveError[i]:=VB_SlaveState; SlaveError S=VB_SlaveError[i]; IF SlaveError THEN IF (SlaveErrorld>i OR SlaveErrorld=0) AND VB_SlaveError[i]=TRUE THEN SlaveErrorld:=i; END_IF ELSE SlaveErrorld:=0; END_IF pSlave:=pSlave^.NextInstance; i :=LIMIT(0,i+1,31); END_WHILE END_IF