AoeWriteCommand
透过 EtherCAT ADS (AoE) 写入数据。
语法
KsCommandStatus AoeWriteCommand(
int SlaveId,
int Port,
int IndexGroup,
int IndexOffset,
BYTE* Value,
int Length
);
参数
SlaveId:从站阵列的索引。当 EtherCAT 从站装置启动时,此索引具有与 SlaveId 相同的值,该值对应于从站装置在网路中的位置。请注意,在 EtherCAT 进入运行 (Op) 状态后,加入或移除网路上的任何从站装置将改变各装置在网路中的位置 (SlaveId)。尽管如此,从站的索引将保持不变。新增的装置将排列在阵列的末端。对于更改后的所有从站,索引和 SlaveId 将不再匹配。上述行为模式仅适用于实体装置;不适用于模拟装置。详细资讯请参阅 EnableHotConnect 中的使用案例。
Port:EtherCAT 从站连接埠。
IndexGroup:欲写入的物件索引组。
IndexOffset:组内物件的偏移量。
Value:欲写入包含值的缓冲区指标。
Length:欲写入值的长度(位元)。
回传值
返回 KsCommandStatus 结构。
可用的 EtherCAT 状态
ecatPreOP, ecatSafeOP, ecatOP
范例
复制
//////////////////////////////////////////////////////////////////
//
// This code snippet demonstrates how to configure CANopen devices
// connected to CANopen master and use AoeReadCommand to request
// service data stored in these CANopen devices.
// This code snippet is to be used with Beckhoff EL6751 CANopen
// master/slave terminal.
//
//////////////////////////////////////////////////////////////////
KsError nRet = errNoError;
KsCommandStatus Command = { 0 };
CanOpenSetting CanOpen = { 0 };
BYTE byteRead = 0;
BYTE byteWrite = 1;
CanOpen.RxPdoCount = 4;
CanOpen.RxPdos[0] = { TRUE, 16, 0x1800, 0xFF };
CanOpen.RxPdos[1] = { FALSE, 48, 0x1801, 0xFF };
CanOpen.RxPdos[2] = { FALSE, 48, 0x1802, 0xFF };
CanOpen.RxPdos[3] = { FALSE, 0, 0x1803, 0xFF };
CanOpen.TxPdoCount = 4;
CanOpen.TxPdos[0] = { TRUE, 16, 0x1400, 0xFF };
CanOpen.TxPdos[1] = { FALSE, 48, 0x1401, 0xFF };
CanOpen.TxPdos[2] = { FALSE, 48, 0x1402, 0xFF };
CanOpen.TxPdos[3] = { FALSE, 0, 0x1403, 0xFF };
// Send start-up SDO commands so that some settings can be done after KINGSTAR subsystem is started
CanOpen.SdoCommandCount = 1;
CanOpen.SdoCommands[0].Index = 0x6060;
CanOpen.SdoCommands[0].SubIndex = 0;
CanOpen.SdoCommands[0].Length = 1;
CanOpen.SdoCommands[0].Data[0] = 0x1;
nRet = Create(0, 0);
nRet = AddModuleConfiguration(
1, // EthercatSlaveID
0x70, // LinkedDeviceID, it is CANopen device's node ID for CANopen protocol
configCANopen, // Protocol
&CanOpen // Settings
);
Command = WaitForCommand(60, TRUE, Start());
Command = WaitForCommand(
5,
FALSE,
AoeReadCommand(
1, // SlaveID
0x1070, // Port, it is 0x1000 + LinkedDeviceID used in ConfigLinkedDevice
0x6060, // IndexGroup, enter object index here for SDO reading/writing through EL6751
0, // IndexOffset, enter object subindex here for SDO reading/writing through EL6751
&byteRead, // Value
1 // Length
)
);
Command = WaitForCommand(5, FALSE, AoeWriteCommand(1, 0x1070, 0x6060, 0, &byteWrite, 1));
Command = WaitForCommand(5, FALSE, Stop());
使用需求
RT | Win32 | |
---|---|---|
最低支援版本 | 4.0 | 4.0 |
标头档 | ksapi.h | ksapi.h |
程式库 | KsApi_Rtss.lib | KsApi.lib |
参见