Samples Silverlight 5. Creating an AdsHelper Class Most of the Ads communication can be outsourced to a separate class, here called AdsHelper. AdsHelper.h The TcAds headers are included in the AdsHelper header. Care must be taken to specify the correct path. In addition, the headers depend on the processor type. In the sample code the X86 headers are attached. #include"..\_AdditionalFiles\TcpAdsApiCe\include\TcAdsDef.h"#include".. \_AdditionalFiles\TcpAdsApiCe\include\TcAdsAPI.h" Furthermore, the declarations are made in the header.
typedef enum E_NOTIFICATION_IDENT { engine = 0, deviceUp = 1, deviceDown = 2, steps, count, switchSpeed }; long AdsGetVarHandle(AmsAddr* pServerAddr, const char* szVarname, long* pHandle); long AdsFreeVarHandle(AmsAddr* pServerAddr, long handle); long AdsGerVarHandleEx(long port, AmsAddr* pServerAddr, const char* szVarname, long* pHandle); long AdsFreeVarHandleEx(long port, AmsAddr* pServerAddr, long handle); long SpeedSlowEx(long port, AmsAddr* pServerAddr); long SpeedFastEx(long port, AmsAddr* pServerAddr); long connect(long port, AmsAddr* pServerAddr); long disconnect(long port, AmsAddr* pServerAddr); AdsHelper.cpp The headers StdAfx.h and AdsHelper.h must be integrated in the AdsHelper.cpp, #include"StdAfx.h"#include"AdsHelper.h" and afterwards the global variables defined.
long hEngine, hDeviceUp, hDeviceDown, hSteps, hCount, hSwitch; unsigned long hEngineNotification, hDeviceUpNotification, hDeviceDownNotification, hStepsNotification, hCountNotification, hSwitchNotification; The methods AdsGetVarHandle and AdsGetVarHandleEx serve to create handles for PLC variables long AdsGetVarHandle(AmsAddr* pServerAddr, const char* szVarname, long* pHandle) { if (pHandle == NULL || pServerAddr == NULL) return E_POINTER; unsigned long read = 0; long nErr = AdsSyncReadWriteReqEx(pServerAddrm, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(long), pHandle,strlen(szVarname), (char*)szVarname, &read); TX1000 14 Version: 1.2