ReadWriteNetHelperReadCustomerT 方法 (IReadWriteNet, String, T) |
命名空间: HslCommunication.Core.Net
public static OperateResult<T> ReadCustomer<T>( IReadWriteNet readWriteNet, string address, T obj ) where T : new(), IDataTransfer
[缺少 "M:HslCommunication.Core.Net.ReadWriteNetHelper.ReadCustomer``1(HslCommunication.Core.IReadWriteNet,System.String,``0)" 的 <param name="readWriteNet"/> 文档]
public class DataMy : IDataTransfer { // 根据对应的设备选择对应的实例化 // 三菱 RegularByteTransform // 西门子 ReverseBytesTransform // Modbus及欧姆龙 ReverseWordTransform private IByteTransform byteTransform = new RegularByteTransform( ); public ushort ReadCount => 5; public short temperature = 0; // 温度 public float press = 0f; // 压力 public int others = 0; // 自定义的其他信息 public void ParseSource( byte[] Content ) { temperature = byteTransform.TransInt16( Content, 0 ); press = byteTransform.TransSingle( Content, 2 ); others = byteTransform.TransInt32( Content, 6 ); } public byte[] ToSource( ) { byte[] buffer = new byte[10]; byteTransform.TransByte( temperature ).CopyTo( buffer, 0 ); byteTransform.TransByte( press ).CopyTo( buffer, 2 ); byteTransform.TransByte( others ).CopyTo( buffer, 6 ); return buffer; } }
MelsecMcNet melsec = new MelsecMcNet( "192.168.0.100", 6000 ); DataMy dataMy = new DataMy( ); OperateResult<DataMy> read = melsec.ReadCustomer<DataMy>( "M100", dataMy ); if (read.IsSuccess) { // success Console.WriteLine( dataMy.temperature.ToString( ) ); } else { // failed Console.WriteLine( "读取失败:" + read.Message ); }