[英]How to start/restart PLC using Twincat3 (error 1793)
Following the advice to the question ( TwinCAT 3.0 Automation Interface without Visual Studio? ) I receive 1793 error (Service is not supported by server). 遵循问题的建议( 没有Visual Studio的TwinCAT 3.0自动化接口? ),我收到1793错误(服务器不支持该服务)。
I try to write program to start/restart/config Beckhoff PLC using Twincat3 (this is the same functionality like the small Beckhoff GUI application). 我尝试使用Twincat3编写程序来启动/重新启动/配置Beckhoff PLC(这与小型Beckhoff GUI应用程序具有相同的功能)。 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);
}
Ok, I have found the solution, maybe someone will find it useful. 好的,我已经找到了解决方案,也许有人会觉得有用。 There is no error in the code above, but required AdsState is wrong.
上面的代码中没有错误,但必需的AdsState错误。 It seems that ADSSTATE_RUN and ADSSTATE_CONFIG (and some others in this enum) are used only to return the state.
似乎ADSSTATE_RUN和ADSSTATE_CONFIG(以及此枚举中的其他一些)仅用于返回状态。
To actually change the state of device you should use ADSSTATE_RESET and ADSSTATE_RECONFIG (those two values reflect the functionality of start/restart in run mode and config mode). 要实际更改设备状态,您应该使用ADSSTATE_RESET和ADSSTATE_RECONFIG (这两个值反映了在运行模式和配置模式下启动/重新启动的功能)。 Also with ADSSTATE_STOP you can completely stop PLC, while ADSSTATE_SHUTDOWN allows for rebooting or turning off the PC (depending on DeviceState value 0/1).
同样,通过ADSSTATE_STOP,您可以完全停止PLC,而ADSSTATE_SHUTDOWN允许重新启动或关闭PC(取决于DeviceState值0/1)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.