Closed chrisbeardy closed 3 years ago
Hey,
a working example to call a method can be found at infosys.
Example:
typedef struct
{
unsigned long a;
unsigned long b;
} MethodParameters;
// ...
long nErr, nPort;
AmsAddr Addr;
PAmsAddr pAddr = &Addr;
ULONG lHdlVar, rValue;
char szVar[] = {"MAIN.foo#DoAdd"};
MethodParameters params;
// ...
nPort = AdsPortOpen();
nErr = AdsGetLocalAddress(pAddr);
if (nErr)
{
cerr << "Error: AdsGetLocalAddress: " << nErr << '\n';
}
pAddr->port = 851;
nErr = AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar), &lHdlVar, sizeof(szVar), szVar);
if (nErr)
{
cerr << "Error: AdsSyncReadWriteReq: " << nErr << '\n';
}
params.a = 5;
params.b = 5;
nErr = AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar, sizeof(rValue), &rValue, sizeof(params), ¶ms);
if (nErr)
{
cerr << "Error: AdsSyncReadWriteReq: " << nErr << '\n';
}
cout << "rValue: " << rValue;
nErr = AdsSyncWriteReq(pAddr, ADSIGRP_SYM_RELEASEHND, 0, sizeof(lHdlVar), &lHdlVar);
if (nErr)
{
cerr << "Error: AdsSyncWriteReq: " << nErr << '\n';
}
nErr = AdsPortClose();
if (nErr)
{
cerr << "Error: AdsPortClose: " << nErr << '\n';
}
this looks great, thanks. Can you repost the link please, its linking to:
and I cant seem to find that example
Yes:
I found the example under TwinCAT ADS .NET Samples
-> Samples ADS .NET
-> PLC method call
awesome thank you
Hello, does anyone know if using the C DLL it is possible to do RPC method call of Methods from PLC FB's, like you can in the .NETimplementation?
I have had a look around the C files and can't see anything obvious, I'm not sure if it is possible to get the symbol of the method and just do a read/write to the correct memory areas.?
I ask this as I would like to be able to add this feature into the popular pyads package.