Beckhoff / ADS

Beckhoff protocol to communicate with TwinCAT devices.
MIT License
491 stars 193 forks source link

ADS-sum command: Read or Write a list of variables with one single ADS-command #182

Closed DasSchilli closed 1 year ago

DasSchilli commented 1 year ago

Hi,

Can you share a new example of a simple implementation of ADS-sum command in C++ with the provided lib? According to this website

Best regards

pbruenn commented 1 year ago

I guess you mean: https://infosys.beckhoff.com/content/1031/tc3_adsdll2/124835083.html?

Well, it is basically still the same. You can simply use the code provided in the example and pass it to AdsDevice.ReadWriteReqEx2() https://github.com/Beckhoff/ADS/blob/master/AdsTool/main.cpp#L392-L398

The only difference is the additional bytesRead parameter. Currently, I am not able to write a proper example, to publish here. Keep the issue open and I will see if I can write one soon.

DasSchilli commented 1 year ago

Yes, sorry, I meant this topic.

I try to explain my short application. I have a TwinCAT Project with three Axes and I want to read all information of axes. Index Group: 4101 + Index Offset: 10006 of first Axis

In my case, I need only ActPos of each axis. I want to read all values in one AdsSum command, or is there a better way.

soberschmidt commented 1 year ago

The actual position of an axis is available via the AXIS_REF structure in the NCTOPLCAXIS_REF sub structure. All actual axis position could be copied to user defined PLC structure and requested via one AdsReadReq. This is best practice for ADS client application. Especially if you want to write axis data.

If you want to do it via a ADS sum request you have to follow these steps as described in the mentioned sample

  1. Prepare the index groups, index offsets and lengths of data for each sub command.

  2. Send AdsSumReadRequest

   nErr = AdsSyncReadWriteReq(pAddr,  // amsNetId and amsPort of PLC 
                        0xf080, // indexGroup which declares the request as sumReadRequest 
                        reqNum, // offset = amount of ADS request in sum command
                        readLength, // (4 bytes per ADS return code + 8 bytes per actPos data ) * reqNum
                        pReadData, 
                        writeLength, // (12 bytes for indexGroup, offset and length) * reqNum
                        pWriteData); 
  1. The response (readData) contains all ADS return codes and requested data for each subcommand. The bytestream starts with ADS return codes of all sub commands followed by the data:

AdsReturnCode(subCommand1), AdsReturnCode(subCommandN),data(subCommand1), data(subCommandN)

In the .NET ADS sum request sample you will find a more detailed explanation.