Non-QEC Example – Digital Input

Non-QEC Example – Digital Input

[QEC教程]

完整教學請參見 範例:採用EtherCAT程式碼在非QEC上進行數位輸入/輸出.

數位輸入

Using the EtherCAT digital input module, the external digital signal is received and printed out via Serial Port.

硬體說明

  • QEC-M-01
  • QEC-R11D0F: EtherCAT 16數位輸出通道從站模組
  • 其他: 開關

電路

請參考 QEC Example – Digital Input’s circuit part 用於電路架構。

代碼

請參考 QEC Example – Digital Input’s code part 先。

Note that the EtherCAT slave device is a non-QEC device, so the EthercatDevice_QECR11DF0D must be changed to EthercatDevice_Generic when setting the slave object names.

EthercatMaster master;
EthercatDevice_Generic slave1;

In the main loop, the 1-byte data will be read from the PDO memory address using pdoRead8.
Since we are reading pin8 data in this example, we need to offset a 1-byte bit as follows.

slave1.pdoRead8(1)

其中, pdoRead8(offset) has one parameter, which is described as follows.

  • offset:ProcessData 記憶體位址。

The value read in pdoRead8 is 8-bit data. If you need to view this data, you need to set the format of the data in Serial.println(val, format).

Serial.println(slave1.pdoRead8(1), HEX);

範例

#include "Ethercat.h"

EthercatMaster master;
EthercatDevice_Generic slave1;
bool din=0,dinOld=0;
void setup() {
    Serial.begin(115200); while (!Serial);
    master.begin();
    slave.attach(0, master);
    master.start();
}
void loop() {
    din = slave.pdoRead8(1);
    if (din != dinOld) {
        Serial.println(din);
        dinOld = din;
    }
}

學習更多

您可以在EtherCAT 應用找到更多QEC的基礎應用介紹。

您還可以探索程式語法參考函式庫參考,有更多86Duino IDE程式編程的詳細集合。

發表評論

上部へスクロール