beckhoff TwinCAT 3 — 15.23 Sample35: Access Ethernet

C++-samples | Sample35: Access Ethernet 15.23 Sample35: Access Ethernet | Sample35: Access Ethernet This article describes the implementation of TwinCAT 3 C++ modules that communicate directly via an Ethernet card. The sample code queries a hardware address (MAC) from a communication partner by means of the cyclic transmission and reception of ARP packets. The sample illustrates the direct access to the Ethernet card. The TF6311 TCP/UDP RT function provides access to Ethernet cards on the basis of TCP and UDP, so that an implementation of a network stack is not necessary on the basis of this sample. Download Here you can access the source code for this sample:

https://github.com/Beckhoff/TC1300_Samples/tree/main/S35-AccessEthernet 1. Open the zip file that it contains in TwinCAT 3 by clicking on Open Project … . 2. Select your target system. 3. Build the sample on your local machine (e.g. Build -> Build Solution ). 4. Note the actions listed on this page under Configuration . 5. Activate the configuration by clicking . р The sample is ready for operation. Description The sample contains an instance of the TcEthernetSample module, which sends and received ARP packets for the purpose of determining the remote hardware address (MAC).

The CycleUpdate method implements a rudimentary state machine for sending ARP packets and waiting for a response with a timeout. The sample uses two Ethernet components from TwinCAT: 1. An ITcEthernetAdapter (instance name in the sample is m_spEthernetAdapter) represents an RT Ethernet adapter. It enables access to the adapter parameters such as hardware MAC address, link speed and link errors. It can be used to send Ethernet frames and enables a module instance to register itself as an ItcIoEthProtocol via the registerProtocol method. 2.

The ITcIOoEthProtocol is extended by the sampling module, which ensures that a notification takes place via the ITcEthernetAdapter in case of Ethernet events. Configuration The downloaded TwinCAT project must be configured for execution in a network environment. Please carry out the following steps: ь This sample demands the use of the TwinCAT driver by the Ethernet card. TwinCAT 3 302 Version: 1.19.1