SiemensS7NetReadAsync 方法 (String, UInt16) |
一次性从PLC获取所有的数据,按照先后顺序返回一个统一的Buffer,需要按照顺序处理,两个数组长度必须一致,数组长度无限制
One-time from the PLC to obtain all the data, in order to return a unified buffer, need to be processed sequentially, two array length must be consistent
命名空间:
HslCommunication.Profinet.Siemens
程序集:
HslCommunication (在 HslCommunication.dll 中) 版本:12.1.2.0 (12.1.2.0)
语法 public Task<OperateResult<byte[]>> ReadAsync(
string[] address,
ushort[] length
)
Public Function ReadAsync (
address As String(),
length As UShort()
) As Task(Of OperateResult(Of Byte()))
public:
Task<OperateResult<array<unsigned char>^>^>^ ReadAsync(
array<String^>^ address,
array<unsigned short>^ length
)
member ReadAsync :
address : string[] *
length : uint16[] -> Task<OperateResult<byte[]>>
参数
- address
- 类型:SystemString
起始地址,格式为I100,M100,Q100,DB20.100
Starting address, formatted as I100,M100,Q100,DB20.100 - length
- 类型:SystemUInt16
数据长度数组
Array of data Lengths
返回值
类型:
TaskOperateResultByte是否读取成功的结果对象 -> Whether to read the successful result object
异常 异常 | 条件 |
---|
NullReferenceException | |
备注 警告: |
---|
原先的批量的长度为19,现在已经内部自动处理整合,目前的长度为任意和长度。 |
示例
以下是一个高级的读取示例
SiemensS7Net siemens = new SiemensS7Net( SiemensPLCS.S1200, " 192.168.1.110" );
OperateResult<byte[]> read = siemens.Read( new string[] { "M100", "I0", "Q0" }, new ushort[] { 20, 10, 15 } );
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 );
bool i_1_2 = (read.Content[21] & 0x04) == 0x04;
bool q_0_0 = (read.Content[30] & 0x01) == 0x01;
bool[] inputArray = HslCommunication.BasicFramework.SoftBasic.ByteToBoolArray( siemens.ByteTransform.TransByte( read.Content, 20, 10 ) );
}
else
{
}
siemens.ConnectClose( );
参见