Following the advice to the question (TwinCAT 3.0 Automation Interface without Visual Studio?) I receive 1793 error (Service is not supported by server).
I try to write program to start/restart/config Beckhoff PLC using Twincat3 (this is the same functionality like the small Beckhoff GUI application). I'm trying to follow advices from solution presented above, but it seems that I cannot set the state. Reading values from the device works:
nPort = AdsPortOpen();
nErr = AdsGetLocalAddress(pAddr);
if (nErr)
cerr << "Error: AdsGetLocalAddress: " << nErr << '\n';
// TwinCAT 3 PLC1 = 851
pAddr->port = 10000;// 10000 as advised @ stackoverflow;
cout << "(R) -> PLC Run\n";
cout << "(S) -> PLC Stop\n";
cout.flush();
ch = _getch();
ch = toupper(ch);
while ((ch == 'R') || (ch == 'S'))
{
switch (ch)
{
case 'R':
nAdsState = ADSSTATE_RUN;
break;
case 'S':
nAdsState = ADSSTATE_CONFIG;
break;
}
nErr = AdsSyncReadStateReq(pAddr, &nAdsState, &nDeviceState);// , 0, pData);
if (nErr) cerr << "Error: AdsSyncReadStateReq: " << nErr << '\n';
cout << nAdsState << " " << nDeviceState << endl;
nErr = AdsSyncWriteControlReq(pAddr, nAdsState, nDeviceState, 0, pData);
if (nErr) cerr << "Error: AdsSyncWriteControlReq: " << nErr << '\n'; //1793
ch = _getch();
ch = toupper(ch);
}