MelsecFxSerialRead 方法 (String, UInt16) |
命名空间: HslCommunication.Profinet.Melsec
MelsecFxSerial melsecFx = new MelsecFxSerial( ); melsecFx.SerialPortInni( sp => { sp.PortName = "COM1"; sp.BaudRate = 9600; sp.DataBits = 7; sp.StopBits = System.IO.Ports.StopBits.One; sp.Parity = System.IO.Ports.Parity.Even; } ); melsecFx.Open( ); OperateResult<byte[]> read = melsecFx.Read( "D100", 4 ); if (read.IsSuccess) { float temp = melsecFx.ByteTransform.TransInt16( read.Content, 0 ) / 10f; float press = melsecFx.ByteTransform.TransInt16( read.Content, 2 ) / 100f; int count = melsecFx.ByteTransform.TransInt32( read.Content, 2 ); // do something } else { // failed }
MelsecFxSerial melsecFx = new MelsecFxSerial( ); melsecFx.SerialPortInni( sp => { sp.PortName = "COM1"; sp.BaudRate = 9600; sp.DataBits = 7; sp.StopBits = System.IO.Ports.StopBits.One; sp.Parity = System.IO.Ports.Parity.Even; } ); melsecFx.Open( ); // 此处以D寄存器作为示例 short short_D1000 = melsecFx.ReadInt16( "D100" ).Content; // 读取D1000的short值 ushort ushort_D1000 = melsecFx.ReadUInt16( "D100" ).Content; // 读取D1000的ushort值 int int_D1000 = melsecFx.ReadInt32( "D100" ).Content; // 读取D1000-D1001组成的int数据 uint uint_D1000 = melsecFx.ReadUInt32( "D100" ).Content; // 读取D1000-D1001组成的uint数据 float float_D1000 = melsecFx.ReadFloat( "D100" ).Content; // 读取D1000-D1001组成的float数据 long long_D1000 = melsecFx.ReadInt64( "D100" ).Content; // 读取D1000-D1003组成的long数据 ulong ulong_D1000 = melsecFx.ReadUInt64( "D100" ).Content; // 读取D1000-D1003组成的long数据 double double_D1000 = melsecFx.ReadDouble( "D100" ).Content; // 读取D1000-D1003组成的double数据 string str_D1000 = melsecFx.ReadString( "D100", 10 ).Content; // 读取D1000-D1009组成的条码数据 // 读取数组 short[] short_D1000_array = melsecFx.ReadInt16( "D100", 10 ).Content; // 读取D1000的short值 ushort[] ushort_D1000_array = melsecFx.ReadUInt16( "D100", 10 ).Content; // 读取D1000的ushort值 int[] int_D1000_array = melsecFx.ReadInt32( "D100", 10 ).Content; // 读取D1000-D1001组成的int数据 uint[] uint_D1000_array = melsecFx.ReadUInt32( "D100", 10 ).Content; // 读取D1000-D1001组成的uint数据 float[] float_D1000_array = melsecFx.ReadFloat( "D100", 10 ).Content; // 读取D1000-D1001组成的float数据 long[] long_D1000_array = melsecFx.ReadInt64( "D100", 10 ).Content; // 读取D1000-D1003组成的long数据 ulong[] ulong_D1000_array = melsecFx.ReadUInt64( "D100", 10 ).Content; // 读取D1000-D1003组成的long数据 double[] double_D1000_array = melsecFx.ReadDouble( "D100", 10 ).Content; // 读取D1000-D1003组成的double数据