文章目录
官方资料
官方的这个位置提供了很多关于使用ads的例子
【ADS Samples: Visual C++】
其中就有批量读取变量的例子【ADS-sum command: Read or Write a list of variables with one single ADS command】。
主要是利用了ADSIGRP_SUMUP_READ(0xF080)
,ADSIGRP_SUMUP_WRITE(0xF081)
这两个指令配合函数AdsSyncReadWriteReq实现的。
批量读
// This code snippet uses ADSIGRP_SUMUP_READ with IndexGroup 0xF080 and IndexOffset as number of ADS-sub-commands
// Demonstrates how to read a list of variables, see full demo-code
// Use ADS-ReadWrite request : "Write" the requested data down to ADS device and "Read" the received answer
nErr = AdsSyncReadWriteReq( pAddr,
0xF080, // Sum-Command, response will contain ADS-error code for each ADS-Sub-command
reqNum, // number of ADS-Sub-Commands
4*reqNum+reqSize, // number requested bytes in the sample two variables each 4 bytes. NOTE : we request additional "error"-flag(long) for each ADS-sub commands
(void*)(mAdsSumBufferRes), // provide buffer for response
12*reqNum, // send 12 bytes for each variable (each ads-Sub command consist of 3 * ULONG : IG, IO, Len)
&parReq);
批量写
// This code snippet uses ADSIGRP_SUMUP_WRITE with IndexGroup 0xF081 and IndexOffset as number of ADS-sub-commands
// Demonstrates how to write a list of variables, see full demo-code
// Use ADS-ReadWrite request : "Write" the send a list of data to list of variables down to ADS device and "Read" the received return codes
nErr = AdsSyncReadWriteReq( pAddr,
0xF081, // ADS list-write command
reqNum, // number of ADS-Sub commands
4*reqNum, // we expect an ADS-error-return-code (long) for each ADS-Sub command
(void*)(mAdsSumBufferRes), // provide space for the response containing the return codes
16*reqNum, // cbyteLen : in THIS sample we send two variables each 4 byte
// --> send 16 bytes (IG1, IO1, Len1, IG2, IO2, Len2, Data1, Data2)
&parReq); // buffer with data
这里还有个官方文档对指令进行了详细的解释
【ADS Sum-Cmd 批量读写详细说明】
可以批量读写,但是没有批量注册,有点可惜。