MelsecMcRNetReadRandom 方法 (String) |
命名空间: HslCommunication.Profinet.Melsec
// 随机读取的示例,所谓的随机读取,就是跨地址读取数据 // 下面我们举个例子,我们读取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 }