点击或拖拽改变大小

OmronConnectedCipNetReadStructAsyncT 方法 (String)

[商业授权] 读取一个结构体的对象,需要事先根据实际的数据点位定义好结构体,然后使用本方法进行读取,当结构体定义不对时,本方法将会读取失败
[Authorization] To read a structure object, you need to define the structure in advance according to the actual data points, and then use this method to read. When the structure definition is incorrect, this method will fail to read

命名空间:  HslCommunication.Profinet.Omron
程序集:  HslCommunication (在 HslCommunication.dll 中) 版本:12.0.0.0 (12.0.0.0)
语法
public Task<OperateResult<T>> ReadStructAsync<T>(
	string address
)
where T : struct, new()

参数

address
类型:SystemString
结构体对象的地址

类型参数

T
结构体的类型

返回值

类型:TaskOperateResultT
是否读取成功的对象
备注
本方法需要商业授权支持,具体的使用方法,参考API文档的示例代码
示例
我们来看看结构体的操作,假设我们有个结构体
MyData.Code STRING(12)
MyData.Value1 INT
MyData.Value2 INT
MyData.Value3 REAL
MyData.Value4 INT
MyData.Value5 INT
MyData.Value6 INT[0..3]
因为bool比较复杂,暂时不考虑。要读取上述的结构体,我们需要定义结构一样的数据
结构体
// 注意:using System.Runtime.InteropServices;

[StructLayout( LayoutKind.Sequential )]
struct MyStruct
{
    [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 12 )]
    public string code;

    public short value1;

    public short value2;

    public float value3;

    public short value4;

    public short value5;

    [MarshalAs( UnmanagedType.ByValArray, SizeConst = 4 )]
    public short[] value6;
}
定义好后,我们再来读取就很简单了。
读写示例
OperateResult<MyStruct> read = omron.ReadStruct<MyStruct>( "MyData" );
参见