ADS批量读取变量

文章目录

官方资料

官方的这个位置提供了很多关于使用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 批量读写详细说明】
可以批量读写,但是没有批量注册,有点可惜。


参考资料
【ADS Samples: Visual C++】
【ADS Sum-Cmd 批量读写详细说明】

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值