GetSlaveById

使用 ID 從指定的從站取得詳細訊息。

語法

KsError GetSlaveById(
     int SlaveId,
     SlaveStatus* Details
);

參數

SlaveId:從站陣列的索引。當 EtherCAT 從站裝置啟動時,此索引具有與 SlaveId 相同的值,該值對應於從站裝置在網路中的位置。請注意,在 EtherCAT 進入運行 (Op) 狀態後,加入或移除網路上的任何從站裝置將改變各裝置在網路中的位置 (SlaveId)。儘管如此,從站的索引將保持不變。新增的裝置將排列在陣列的末端。對於更改後的所有從站,索引和 SlaveId 將不再匹配。上述行為模式僅適用於實體裝置;不適用於模擬裝置。詳細資訊請參閱 EnableHotConnect 中的使用案例。

DetailsSlaveStatus 結構指標,用以接收從暫狀態的詳細資訊。

回傳值

若此函式執行成功,會回傳 errNoError,否則會傳回錯誤碼。更多關於錯誤碼的資訊,請參閱 KsError 清單。

備註

使用 EtherCAT 迴路中的從站位置檢索指定從站的詳細資訊,由於使用的是從站 ID,因此不使用別名資訊。此僅適用於不區分軸或 I/O 的實際從站模組,請在 KINGSTAR 子系統啟動後使用

可用的 EtherCAT 狀態

ecatInit, ecatBoot, ecatPreOP, ecatSafeOP, ecatOP

範例

複製
SlaveStatus slaveStatus = { 0 };
nRet = GetSlaveById(0, &slaveStatus);
if (nRet == errNoError)
{
    // Check the slave information in the SlaveStatus structure.
    RtPrintf("Device 0 %s: Vendor 0x%x, Product 0x%x, Revision 0x%x, Serial 0x%x\n",
             slaveStatus.Name, slaveStatus.VendorId, slaveStatus.ProductCode,
             slaveStatus.RevisionNumber, slaveStatus.SerialNumber);
    RtPrintf("Address: Auto %d, Fixed %d, Alias %d\n",
             slaveStatus.SlaveId, slaveStatus.PhysAddress, slaveStatus.AliasAddress);
    RtPrintf("PDO: Input len %d, Output len %d, Index offset 0x%x\n",
             slaveStatus.InputLength, slaveStatus.OutputLength, slaveStatus.VariableIndexOffset);
    RtPrintf("State %d, Cycle time %d\n", slaveStatus.State, slaveStatus.CycleTime);
}

使用需求

  RT Win32
最低支援版本 4.0 4.0
標頭檔 ksapi.h ksapi.h
程式庫 KsApi_Rtss.lib KsApi.lib

參見

GetIOByIndex

GetStatus

RequestSlaveState