SiemensS7ServerRead 方法 (String, UInt16) |
从PLC读取原始的字节数据,地址格式为I100,Q100,DB20.100,M100,长度参数以字节为单位
Read the original byte data from the PLC, the address format is I100, Q100, DB20.100, M100, length parameters in bytes
命名空间:
HslCommunication.Profinet.Siemens
程序集:
HslCommunication (在 HslCommunication.dll 中) 版本:12.1.2.0 (12.1.2.0)
语法 public override OperateResult<byte[]> Read(
string address,
ushort length
)
Public Overrides Function Read (
address As String,
length As UShort
) As OperateResult(Of Byte())
public:
virtual OperateResult<array<unsigned char>^>^ Read(
String^ address,
unsigned short length
) override
abstract Read :
address : string *
length : uint16 -> OperateResult<byte[]>
override Read :
address : string *
length : uint16 -> OperateResult<byte[]>
参数
- address
- 类型:SystemString
起始地址,格式为I100,M100,Q100,DB20.100
Starting address, formatted as I100,M100,Q100,DB20.100 - length
- 类型:SystemUInt16
读取的数量,以字节为单位
The number of reads, in bytes
返回值
类型:
OperateResultByte
是否读取成功的结果对象
Whether to read the successful result object
实现
IReadWriteNetRead(String, UInt16)备注
暂时不支持bool[]的批量写入操作,请使用 Write(string, byte[]) 替换。
重要事项 |
---|
对于200smartPLC的V区,就是DB1.X,例如,V100=DB1.100,当然了你也可以输入V100 |
如果读取PLC的字符串string数据,可以使用
ReadString(String)示例
假设起始地址为M100,M100存储了温度,100.6℃值为1006,M102存储了压力,1.23Mpa值为123,M104,M105,M106,M107存储了产量计数,读取如下:
SiemensS7Net siemens = new SiemensS7Net( SiemensPLCS.S1200, " 192.168.1.110" );
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, 2 );
}
else
{
}
以下是读取不同类型数据的示例
SiemensS7Net siemensTcpNet = new SiemensS7Net( SiemensPLCS.S1200, " 192.168.1.110" );
byte byte_M100 = siemensTcpNet.ReadByte( "M100" ).Content;
short short_M100 = siemensTcpNet.ReadInt16( "M100" ).Content;
ushort ushort_M100 = siemensTcpNet.ReadUInt16( "M100" ).Content;
int int_M100 = siemensTcpNet.ReadInt32( "M100" ).Content;
uint uint_M100 = siemensTcpNet.ReadUInt32( "M100" ).Content;
float float_M100 = siemensTcpNet.ReadFloat( "M100" ).Content;
long long_M100 = siemensTcpNet.ReadInt64( "M100" ).Content;
ulong ulong_M100 = siemensTcpNet.ReadUInt64( "M100" ).Content;
double double_M100 = siemensTcpNet.ReadDouble( "M100" ).Content;
string str_M100 = siemensTcpNet.ReadString( "M100", 10 ).Content;
short[] short_M100_array = siemensTcpNet.ReadInt16( "M100" ,10).Content;
ushort[] ushort_M100_array = siemensTcpNet.ReadUInt16( "M100", 10 ).Content;
int[] int_M100_array = siemensTcpNet.ReadInt32( "M100", 10 ).Content;
uint[] uint_M100_array = siemensTcpNet.ReadUInt32( "M100", 10 ).Content;
float[] float_M100_array = siemensTcpNet.ReadFloat( "M100", 10 ).Content;
long[] long_M100_array = siemensTcpNet.ReadInt64( "M100", 10 ).Content;
ulong[] ulong_M100_array = siemensTcpNet.ReadUInt64( "M100", 10 ).Content;
double[] double_M100_array = siemensTcpNet.ReadDouble( "M100", 10 ).Content;
参见