AoeReadCommand
透過 EtherCAT ADS (AoE) 讀取數據。
語法
KsCommandStatus AoeReadCommand(
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 |
參見