点击或拖拽改变大小

OmronFinsUdpRead 方法 (String, UInt16)

从欧姆龙PLC中读取想要的数据,返回读取结果,读取长度的单位为字,地址格式为"D100","C100","W100","H100","A100"
Read the desired data from the Omron PLC and return the read result. The unit of the read length is word. The address format is "D100", "C100", "W100", "H100", "A100"

命名空间:  HslCommunication.Profinet.Omron
程序集:  HslCommunication (在 HslCommunication.dll 中) 版本:12.1.2.0 (12.1.2.0)
语法
public override OperateResult<byte[]> Read(
	string address,
	ushort length
)

参数

address
类型:SystemString
读取地址,格式为"D100","C100","W100","H100","A100"
length
类型:SystemUInt16
读取的数据长度

返回值

类型:OperateResultByte
带成功标志的结果数据对象

实现

IReadWriteNetRead(String, UInt16)
IReadWriteNetRead(String, UInt16)
示例
假设起始地址为D100,D100存储了温度,100.6℃值为1006,D101存储了压力,1.23Mpa值为123,D102,D103存储了产量计数,读取如下:
Read示例
OmronFinsNet omronFinsNet = new OmronFinsNet( "192.168.1.110", 9600 );

// 读取连续的byte[],然后自定义解析的示例
OperateResult<byte[]> read = omronFinsNet.Read( "D100", 4 );
if (read.IsSuccess)
{
    float temp  = omronFinsNet.ByteTransform.TransInt16( read.Content, 0 ) / 10f;
    float press = omronFinsNet.ByteTransform.TransInt16( read.Content, 2 ) / 100f;
    int count   = omronFinsNet.ByteTransform.TransInt32( read.Content, 4 );

    // do something
}
else
{
    // failed
}
以下是读取不同类型数据的示例
Read示例
OmronFinsNet omronFinsNet = new OmronFinsNet( "192.168.1.110", 9600 );

// 此处以D寄存器作为示例
bool D100_7        = omronFinsNet.ReadBool( "D100.7" ).Content;      // 读取D100.7是否通断,注意D100.0等同于D100
short short_D100   = omronFinsNet.ReadInt16( "D100" ).Content;       // 读取D100组成的字
ushort ushort_D100 = omronFinsNet.ReadUInt16( "D100" ).Content;      // 读取D100组成的无符号的值
int int_D100       = omronFinsNet.ReadInt32( "D100" ).Content;       // 读取D100-D101组成的有符号的数据
uint uint_D100     = omronFinsNet.ReadUInt32( "D100" ).Content;      // 读取D100-D101组成的无符号的值
float float_D100   = omronFinsNet.ReadFloat( "D100" ).Content;       // 读取D100-D101组成的单精度值
long long_D100     = omronFinsNet.ReadInt64( "D100" ).Content;       // 读取D100-D103组成的大数据值
ulong ulong_D100   = omronFinsNet.ReadUInt64( "D100" ).Content;      // 读取D100-D103组成的无符号大数据
double double_D100 = omronFinsNet.ReadDouble( "D100" ).Content;      // 读取D100-D103组成的双精度值
string str_D100    = omronFinsNet.ReadString( "D100", 5 ).Content;   // 读取D100-D104组成的ASCII字符串数据

// 读取数组
short[] short_D1000_array   = omronFinsNet.ReadInt16( "D1000", 10 ).Content;       // 读取D1000的short值 
ushort[] ushort_D1000_array = omronFinsNet.ReadUInt16( "D1000", 10 ).Content;      // 读取D1000的ushort值
int[] int_D1000_array       = omronFinsNet.ReadInt32( "D1000", 10 ).Content;       // 读取D1000-D1001组成的int数据
uint[] uint_D1000_array     = omronFinsNet.ReadUInt32( "D1000", 10 ).Content;      // 读取D1000-D1001组成的uint数据
float[] float_D1000_array   = omronFinsNet.ReadFloat( "D1000", 10 ).Content;       // 读取D1000-D1001组成的float数据
long[] long_D1000_array     = omronFinsNet.ReadInt64( "D1000", 10 ).Content;       // 读取D1000-D1003组成的long数据
ulong[] ulong_D1000_array   = omronFinsNet.ReadUInt64( "D1000", 10 ).Content;      // 读取D1000-D1003组成的long数据
double[] double_D1000_array = omronFinsNet.ReadDouble( "D1000", 10 ).Content;      // 读取D1000-D1003组成的double数据
参见