[Ethercat Master]
描述
啟動EtherCAT主站,配置所有從站的SM、FMMU和DC暫存器,並將EtherCAT狀態機切換到Operational狀態。
語法
int start(uint64_t cycletime_ns = 0, EthercatMasterMode mode = ECAT_FREERUN);
參數
[in] uint64_t cycletime_ns
EtherCAT 循環時間。 EtherCAT韌體將根據該週期時間定期產生中斷,以更新流程資料並處理非循環傳輸。如果使用者使用了 Cyclic Callback,且EtherCAT主控模式未設定為ECAT_FREERUN_MANUAL
,回調將在這些週期性中斷期間被呼叫。[in] EthercatMasterMode mode
選擇的 EtherCAT 控制模式。每種模式的詳細說明請參考下面的範例。ECAT_SYNC
ECAT_FREERUN
ECAT_FREERUN_MANUAL
回傳值
Return an error code. If the returned value is zero, it indicates a successful execution of this function.
備註
該函數是阻塞型的,無法在callback functions中呼叫。
範例
我們將展示如何選擇 EtherCAT 控制模式(ECAT_SYNC
, ECAT_FREERUN
, ECAT_FREERUN_MANUAL
) 在以下範例中。
ECAT_SYNC

此模式提供最高等級的雙系統同步模式。如上圖所示,數字箭頭表示操作順序,不存在分支。在 EtherCAT 韌體向 EtherCAT 主站函式庫(步驟 2)觸發一個循環中斷後,它會等待來自 EtherCAT 主站函式庫(步驟 8)的 ACK 回應,然後才進行下一個動作。如果使用者已掛載一個cyclic callback,循環中斷將調用此 callback,如步驟 4 所示。只要使用者cyclic callback中讀取當前的input process data、處理、計算output process data並寫回,當前的cycle 就會將output process data傳送到 EtherCAT 網路,滿足實時控制系統的要求。
#include "Ethercat.h" EthercatMaster master; void CyclicCallback() { // ... } void setup() { master.begin(); master.attachCyclicCallback(CyclicCallback); master.start(1000000, ECAT_SYNC); } void loop() { // ... }
ECAT_FREERUN

This is the free-run mode without dual-system synchronization. As shown in the diagram, the numbered arrows indicate the sequence of operations. However, a branching occurs at step 3 because, after the EtherCAT firmware triggers a cyclic interrupt to the EtherCAT master library (step 2), it does not wait for the EtherCAT master library and directly continues with the next action. The two systems operate independently, with no synchronization. If the user has registered a cyclic callback, the cyclic interrupt will call it, as shown in step 4A.
#include "Ethercat.h" EthercatMaster master; void CyclicCallback() { // ... } void setup() { master.begin(); master.attachCyclicCallback(CyclicCallback); master.start(1000000, ECAT_FREERUN); } void loop() { // ... }
ECAT_FREERUN_MANUAL

This is also a free-run mode without dual-system synchronization. The primary difference from the ECAT_FREERUN
mode is that there is no cyclic interrupt to update process data and handle acyclic commands. Instead, the user must manually call EthercatMaster::update()
to update process data and handle acyclic commands. Additionally, since there is no cyclic interrupt in this mode, the cyclic callback will not be called. As indicated by the numbered arrows in the diagram, the two systems operate independently, with no synchronization.
#include "Ethercat.h" EthercatMaster master; void setup() { master.begin(); master.start(1000000, ECAT_FREERUN_MANUAL); } void loop() { // ... master.update(); }
Please see the EtherCAT Library User Manual for more QEC EtherCAT instructions and API usage.