beckhoff TwinCAT 3 — 15.3.1 Sample03: TC3 ADS Server written in C++

C++-samples | Sample03: C++ as ADS server Description This sample contains a C++ module that acts as an ADS server. The server grants access to a counter that can be started, stopped and read. The header file of the module defines the counter variable m_bCount, and the corresponding .cpp file initializes the value in the constructor and implements the logic in the CycleUpdate method. The AdsReadWriteInd method in the .cpp file analyzes the incoming messages and returns the return values. A define in the header file is added for a further added message type.

Details such as the definition of the ADS message types are described in the following cookbook, where you can compile the sample manually. Cookbook This is a step by step description about the creation of the C++ module. 1. Create a new TwinCAT 3 project solution Follow the steps for creating a new TwinCAT 3 project [ } 58] . 2. Create a C++ project with ADS port Follow the steps for the creation of a new TwinCAT 3 C++ project [ } 59] . Select TwinCAT Module Class with ADS port in the Class templates dialog. 3. Add the sample logic to the project 1. Open the header file .h (in this sample Module1.h) and add the counter m_bCount to the protected area as a new member variable:

class CModule1 : public ITComObject , public ITcCyclic ,... { public: DECLARE_IUNKNOWN() .... protected: DECLARE_ITCOMOBJECT_SETSTATE(); /// ITcCyclicCallerInfoPtr m_spCyclicCaller; ..... /// ULONG m_ReadByOidAndPid; BOOL m_bCount; }; 2. Open the class file .cpp (in this sample Module1.cpp) and initialize the new values in the constructor: CModule1::CModule1() ..... { memset(&m_Counter, 0, sizeof(m_Counter)); memset(&m_Inputs, 0, sizeof(m_Inputs)); memset(&m_Outputs, 0, sizeof(m_Outputs)); m_bCount = FALSE; // by default the counter should not increment m_Counter = 0; // we also initialize this existing counter } р The sample code has been added. TwinCAT 3 239 Version: 1.19.1