点击或拖拽改变大小

MelsecMcNetReadRandomAsync 方法 (String)

随机读取PLC的数据信息,可以跨地址,跨类型组合,但是每个地址只能读取一个word,也就是2个字节的内容。收到结果后,需要自行解析数据
Randomly read PLC data information, which can be combined across addresses and types, but each address can only read one word, which is the content of 2 bytes. After receiving the results, you need to parse the data yourself

命名空间:  HslCommunication.Profinet.Melsec
程序集:  HslCommunication (在 HslCommunication.dll 中) 版本:11.8.2.0 (11.8.2.0)
语法
public Task<OperateResult<byte[]>> ReadRandomAsync(
	string[] address
)

参数

address
类型:SystemString
所有的地址的集合

返回值

类型:TaskOperateResultByte
结果
备注
访问安装有 Q 系列 C24/E71 的站 QCPU 上位站 经由 Q 系列兼容网络系统 MELSECNET/H MELSECNET/10 Ethernet 的 QCPU 其他站 时 访问点数········1≦ 字访问点数 双字访问点数 ≦192
访问 QnACPU 其他站 经由 QnA 系列兼容网络系统 MELSECNET/10 Ethernet 的 Q/QnACPU 其他站 时访问点数········1≦ 字访问点数 双字访问点数 ≦96
访问上述以外的 PLC CPU 其他站 时访问点数········1≦字访问点数≦10
示例
随机字读取示例
 // 随机读取的示例,所谓的随机读取,就是跨地址读取数据

// 下面我们举个例子,我们读取D100的值,D200的值,M32的值,W100的值,如何一次就读取出来呢?
MelsecMcNet melsec_net = new MelsecMcNet( "192.168.0.100", 6000 );

OperateResult<byte[]> read = melsec_net.ReadRandom( new string[] { "D100", "D200", "M32", "W100" } );
if (read.IsSuccess)
{
    short d100 = melsec_net.ByteTransform.TransInt16( read.Content, 0 );
    short d200 = melsec_net.ByteTransform.TransInt16( read.Content, 2 );
    short w100 = melsec_net.ByteTransform.TransInt16( read.Content, 6 );

    // M是位地址,提取稍微麻烦一点点
    bool[] array = HslCommunication.BasicFramework.SoftBasic.ByteToBoolArray( melsec_net.ByteTransform.TransByte( read.Content, 4, 2 ) );
    bool m32 = array[0];
    bool m33 = array[1];
    bool m34 = array[2];
    bool m35 = array[3];
    // 等等,按照规律操作就可以

    // do something
}
else
{
    // failed
}
参见