点击或拖拽改变大小

SiemensFetchWriteNetReadAsync 方法 (String, UInt16)

从PLC读取数据,地址格式为I100,Q100,DB20.100,M100,T100,C100,以字节为单位
Read data from PLC, address format I100,Q100,DB20.100,M100,T100,C100, in bytes

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

参数

address
类型:SystemString
起始地址,格式为I100,M100,Q100,DB20.100,T100,C100 -> Starting address, formatted as I100,M100,Q100,DB20.100,T100,C100
length
类型:SystemUInt16
读取的数量,以字节为单位 -> The number of reads, in bytes

返回值

类型:TaskOperateResultByte
带有成功标志的字节信息 -> Byte information with a success flag

实现

IReadWriteNetReadAsync(String, UInt16)
示例
假设起始地址为M100,M100存储了温度,100.6℃值为1006,M102存储了压力,1.23Mpa值为123,M104,M105,M106,M107存储了产量计数,读取如下:
Read示例
SiemensFetchWriteNet siemens = new SiemensFetchWriteNet( "192.168.1.110", 2000 );

OperateResult<byte[]> read = siemens.Read( "M100", 8 );
if (read.IsSuccess)
{
    float temp = siemens.ByteTransform.TransInt16( read.Content, 0 ) / 10f;
    float press = siemens.ByteTransform.TransInt16( read.Content, 2 ) / 100f;
    int count = siemens.ByteTransform.TransInt32( read.Content, 6 );

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

// 此处以M100寄存器作为示例
byte byte_M100 = siemensTcpNet.ReadByte( "M100" ).Content; // 读取M100的值
short short_M100 = siemensTcpNet.ReadInt16( "M100" ).Content; // 读取M100-M101组成的字
ushort ushort_M100 = siemensTcpNet.ReadUInt16( "M100" ).Content; // 读取M100-M101组成的无符号的值
int int_M100 = siemensTcpNet.ReadInt32( "M100" ).Content;         // 读取M100-M103组成的有符号的数据
uint uint_M100 = siemensTcpNet.ReadUInt32( "M100" ).Content;      // 读取M100-M103组成的无符号的值
float float_M100 = siemensTcpNet.ReadFloat( "M100" ).Content;   // 读取M100-M103组成的单精度值
long long_M100 = siemensTcpNet.ReadInt64( "M100" ).Content;      // 读取M100-M107组成的大数据值
ulong ulong_M100 = siemensTcpNet.ReadUInt64( "M100" ).Content;   // 读取M100-M107组成的无符号大数据
double double_M100 = siemensTcpNet.ReadDouble( "M100" ).Content; // 读取M100-M107组成的双精度值
string str_M100 = siemensTcpNet.ReadString( "M100", 10 ).Content;// 读取M100-M109组成的ASCII字符串数据

// 读取数组
short[] short_M100_array = siemensTcpNet.ReadInt16( "M100", 10 ).Content; // 读取M100-M101组成的字
ushort[] ushort_M100_array = siemensTcpNet.ReadUInt16( "M100", 10 ).Content; // 读取M100-M101组成的无符号的值
int[] int_M100_array = siemensTcpNet.ReadInt32( "M100", 10 ).Content;         // 读取M100-M103组成的有符号的数据
uint[] uint_M100_array = siemensTcpNet.ReadUInt32( "M100", 10 ).Content;      // 读取M100-M103组成的无符号的值
float[] float_M100_array = siemensTcpNet.ReadFloat( "M100", 10 ).Content;   // 读取M100-M103组成的单精度值
long[] long_M100_array = siemensTcpNet.ReadInt64( "M100", 10 ).Content;      // 读取M100-M107组成的大数据值
ulong[] ulong_M100_array = siemensTcpNet.ReadUInt64( "M100", 10 ).Content;   // 读取M100-M107组成的无符号大数据
double[] double_M100_array = siemensTcpNet.ReadDouble( "M100", 10 ).Content; // 读取M100-M107组成的双精度值
参见