//==============================================
//获取profinet网络已组态站信息
//==============================================
//MODE:0自动辨识是获取组态信息还是错误信息
//MODE:1获取IO 设备从站已组态
//MODE:2获取IO 设备 从站故障
//MODE:3获取IO 设备 从站已禁用
//MODE:4获取IO 设备 从站存在
//MODE:5获取IO 设备 从站出现问题
//==============================================
//站点状态字节位含义
//.X0:站点已组态,MODE=1;
//.X1:站点故障,MODE=2,
//.X2:站点禁用,MODE=3,
//.X3:站点存在,MODE=4;
//.X4:站点出现问题,MODE=5;
//=============================================
//DaigID:
//1~96:PROFINET站点故障
//99:MODE大于5
//98:DrviceStates程序调用错误
//97:RD_SINFO程序调用错误
//==============================================
//设置DrviceStates的MODE,如果MODE为0采用自动判断模式类型
IF #mode = 0 THEN
//获取调用FB的组织块信息
#teSINFO_RET_VAL := RD_SINFO(TOP_SI => #stSI_Top, START_UP_SI => #stSI_Startup);
IF #teSINFO_RET_VAL <> 0 THEN
#teDiagID := 0;
GOTO ERROR;
ELSE
//如果调用块为OB100那么获取组态信息,其它情况获取故障信息
IF #stSI_Top.OB_Nr = 100 THEN
#teMode := 1;
ELSE
#teMode := 2;
END_IF;
END_IF;
ELSE
IF #mode > 5 THEN
#teDiagID := 0;
GOTO ERROR; //大于5为错误;
ELSE
#teMode := #mode;
END_IF;
END_IF;
//获取PROFINET网络设备状态
#teDeviceStatesRET_VAL := DeviceStates(LADDR := #laddr,
MODE := #teMode,
STATE := #stDeviceStates);
IF #teDeviceStatesRET_VAL <> 0 THEN
#teDiagID := 0;
GOTO ERROR;
END_IF;
//将获取的设备位状态转化为字节状态
//获取数组的下限
#teLower := LOWER_BOUND(ARR := #deviceStates, DIM := 1);
//获取数组的上限
#teUpper := UPPER_BOUND(ARR := #deviceStates, DIM := 1);
CASE #teMode OF
1: //.X0:站点已组态,MODE=1;
FOR #teN := #teLower TO #teUpper DO
#deviceStates[#teN].%X0 := #stDeviceStates[#teN];
END_FOR;
2: //.X1:站点故障,MODE=2,
#teErrDeviceNr := 0;
FOR #teN := #teLower TO #teUpper DO
//将故障位转化为字节标志
#deviceStates[#teN].%X1 := #stDeviceStates[#teN];
//如果某一个站有故障记录其站号
//0号站(主站)不进行判断 AND 相应的站点故障状态为1 AND 已经获取到第一个错误站点地址后不进行判断
IF #teN<>0 AND #stDeviceStates[#teN] AND #teErrDeviceNr = 0 THEN
#teErrDeviceNr := #teN;
END_IF;
END_FOR;
IF #teErrDeviceNr <> 0 THEN
#teDiagID := #teErrDeviceNr;
GOTO ERROR;
END_IF;
3: //.X2:站点禁用,MODE=3,
FOR #teN := #teLower TO #teUpper DO
#deviceStates[#teN].%X2 := #stDeviceStates[#teN];
END_FOR;
4: //.X3:站点存在,MODE=4;
FOR #teN := #teLower TO #teUpper DO
#deviceStates[#teN].%X3 := #stDeviceStates[#teN];
END_FOR;
5: //.X4:站点出现问题,MODE=5;
FOR #teN := #teLower TO #teUpper DO
#deviceStates[#teN].%X4 := #stDeviceStates[#teN];
END_FOR;
ELSE
#teDiagID := 0;
GOTO ERROR;
END_CASE;
#err := FALSE;
#errID := 0;
#diagID := 0;
RETURN;
ERROR:
#err := TRUE;
#errID := #progID;
#diagID := #teDiagID;
原文地址:https://blog.csdn.net/xdpcxq/article/details/134594999
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_3315.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!