Read ADS information
Each ADS device contains a version number and an identification. The sample program reads this information from the PLC and displays it on the screen.
Download: sample05-c-ads-dll-readdeviceinfo.zip
#include <iostream.h>
#include <windows.h>
#include <conio.h>
// ADS headers
#include "C:\TwinCAT\AdsApi\TcAdsDll\Include\TcAdsDef.h"
#include "C:\TwinCAT\AdsApi\TcAdsDll\Include\TcAdsApi.h"
void main()
{
LONG nErr, nPort;
AdsVersion Version;
AdsVersion *pVersion = &Version;
char pDevName[50];
AmsAddr Addr;
PAmsAddr pAddr = &Addr;
// Kommunikationsport auf dem ADS Router öffnen
nPort = AdsPortOpen();
nErr = AdsGetLocalAddress(pAddr);
if (nErr) cerr << "Error: AdsGetLocalAddress: " << nErr << '\n';
// TwinCAT2 RTS1 Port = 801
pAddr->port = 801;
nErr = AdsSyncReadDeviceInfoReq(pAddr, pDevName, pVersion);
if (nErr)
cerr << "Error: AdsSyncReadDeviceInfoReq: " << nErr << '\n';
else
{
cout << "Name: " << pDevName << '\n';
cout << "Version: " << (int)pVersion->version << '\n';
cout << "Revision: " << (int)pVersion->revision << '\n';
cout << "Build: " << pVersion->build << '\n';
}
cout.flush();
_getch();
// Kommunikationsport schließen
nErr = AdsPortClose();
if (nErr) cerr << "Error: AdsPortClose: " << nErr << '\n';
}