点击或拖拽改变大小

AllenBradleyPcccNetReadStringAsync 方法 (String, UInt16, Encoding)

使用指定的编码,读取字符串数据
Reads string data using the specified encoding

命名空间:  HslCommunication.Profinet.AllenBradley
程序集:  HslCommunication (在 HslCommunication.dll 中) 版本:12.0.0.0 (12.0.0.0)
语法
public override Task<OperateResult<string>> ReadStringAsync(
	string address,
	ushort length,
	Encoding encoding
)

参数

address
类型:SystemString
起始地址
length
类型:SystemUInt16
数据长度
encoding
类型:System.TextEncoding
指定的自定义的编码

返回值

类型:TaskOperateResultString
带有成功标识的string数据

实现

IReadWriteNetReadStringAsync(String, UInt16, Encoding)
备注
读取PLC的地址信息,如果输入了 ST 的地址,例如 ST10:2, 当长度指定为 0 的时候,这时候就是动态的读取PLC来获取实际的字符串长度。
Read the PLC address information, if the ST address is entered, such as ST10:2, when the length is specified as 0, then the PLC is dynamically read to obtain the actual string length.
示例
以下为三菱的连接对象示例,其他的设备读写情况参照下面的代码:
String类型示例
MelsecMcNet melsec_net = new MelsecMcNet( "192.168.0.100", 6000 );

// 以下是简单的读取,没有仔细校验的方式
string d100_value = melsec_net.ReadString( "D100", 5 ).Content;

// 如果需要判断是否读取成功,使用 Unicode 编码即可读取中文,如果还是乱码,就需要自己指定编码来实现
OperateResult<string> R_d100_value = melsec_net.ReadString( "D100", 5, Encoding.Unicode );
if (R_d100_value.IsSuccess)
{
    // success
    string value = R_d100_value.Content;
}
else
{
    // failed
}
参见