我对EtherCAT / CANopen领域很陌生,并尝试实现自定义从站。从属设备到目前为止已经通过一致性测试,并且想要写入我的一个从属数据对象,该从属设备已连接到CX5120,该CX5120由XAE找到并且还显示了从属设备。为此,我将ESI文件复制到TwinCAT文件夹(C:\ TwinCAT \ 3.1 \ Config \ Io \ EtherCAT)。
我创建了一个小型的结构化文本PLC程序,该程序使用FB_EcCoESdoWrite将数据写入地址0x607A。但是,当我将其设置为活动状态并尝试连接时,Visual Studio告诉我该设备至少需要一个Sync Master。另外,当将bExecute设置为TRUE时,我从函数中得到一个错误。据我了解,我必须在我的ST程序和从站之间链接变量,但我看不到需要链接变量,因为afaik函数调用应该管理传输?写入ESC的SDO有哪些步骤?有人可以告诉我我所缺少的还是手头有一个小例子?
PROGRAM MAIN
VAR
heartbeat : UINT;
fbSdoWrite : FB_EcCoESdoWrite;
sNetId : T_AmsNetId := '5.76.204.148.1.1'; (* NetId of EtherCAT Master *)
nSlaveAddr : UINT := 1001; (* Port Number of EtherCAT Slave *)
nIndex : WORD := 16#607A; (* CoE Object Index *)
nSubIndex : BYTE := 0; (* Subindex of CoE Object *)
nValue : UINT := 16#AAAA; (* variable to be written to the CoE Object *)
bExecute : BOOL; (* rising edge starts writing to the CoE Object *)
bError : BOOL;
nErrId : UDINT;
END_VAR
fbSdoWrite(
sNetId := sNetId,
nSlaveAddr := nSlaveAddr,
nIndex := nIndex,
nSubIndex := nSubIndex,
pSrcBuf := ADR(nValue),
cbBufLen := SIZEOF(nValue),
bExecute := bExecute
);
IF NOT fbSdoWrite.bBusy THEN
bExecute := FALSE;
IF NOT bError THEN
(* write successful *)
bError := FALSE;
nErrId := 0;
ELSE
(* write failed *)
bError := fbSdoWrite.bError;
nErrId := fbSdoWrite.nErrId;
END_IF
fbSdoWrite(bExecute := FALSE);
END_IF
通过将变量从PLC代码链接到设备的DevState输入解决了问题。链接到普通InfoData似乎不起作用。