如何通过ST语言实现SIMOTION的DP从站地址修改?

通过执行_setdpslaveaddress程序可以实现simotion的dp从站地址修改。
实现方法:
(1)首先打开hw config 硬件组态,配置接口为dp从站:
图01. 设置dp 接口为从站
(2)配置dp从站通信的io地址如下图:
图02. 配置dp从站通信的io地址
(3)查询dp 诊断地址用于后续编程时填写参数使用:
图03. 查询该接口的诊断地址
(4)编写如下程序
var_global
locdpslaveaddress : sint := 8; // 需要使用的profibus地址
retdpslaveaddress : structretdpslaveaddress; // 返回值变量
locretval : dint;
neededsetdpaddress : dint := 0;
startchange :bool;
end_var
end_interface
implementation
program bkgchangdpaddress
if startchange then
// 读取当前的dp从站地址
retdpslaveaddress := _getactivedpslaveaddress (
logicaladdresscommunicationadapter := 16382 // 步骤3查询的接口诊断地址
);
if (0 = retdpslaveaddress.functionresult) then
// 检查是否需要更新dp地址,如果当前地址与地址locdpslaveaddress 不相同,则执行更新
if (retdpslaveaddress.dpslaveaddress <> locdpslaveaddress) then
neededsetdpaddress := 1;
else
;
end_if;
end_if;
if (1 = neededsetdpaddress) then
// 设置新的dp地址
locretval := _setdpslaveaddress (
logicaladdresscommunicationadapter := 16382, // 步骤3查询的接口诊断地址
dpslaveaddress := locdpslaveaddress
// profibus address of the local slot
);
if (0 = locretval) then
locretval := _activatedpslaveaddress (
logicaladdresscommunicationadapter := 16382 // 步骤3查询的接口诊断地址
);
else
;
end_if;
end_if;
end_if;
(5)修改startchange为1,程序执行成功会导致simotion重新启动,随后新的dp地址生效。