点击或拖拽改变大小

ModbusTcpNetRead 方法 (String, UInt16)

从Modbus服务器批量读取寄存器的信息,需要指定起始地址,读取长度,如果富文本地址不指定,默认使用的功能码是 0x03,如果需要使用04功能码,那么地址就写成 x=4;100
To read the register information from the Modbus server in batches, you need to specify the start address and read length. If the rich text address is not specified, the default function code is 0x03. If you need to use the 04 function code, the address is written as x = 4; 100

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

参数

address
类型:SystemString
起始地址,比如"100","x=4;100","s=1;100","s=1;x=4;100"
length
类型:SystemUInt16
读取的数量

返回值

类型:OperateResultByte
带有成功标志的字节信息

实现

IReadWriteNetRead(String, UInt16)
IReadWriteNetRead(String, UInt16)
备注
富地址格式,支持携带站号信息,功能码信息,具体参照类的示例代码
示例
此处演示批量读取的示例
Read示例
ModbusTcpNet modbus = new ModbusTcpNet( "192.168.0.1" );   // 实例化

// 假设100存储了short的报警,101,102存储了float的温度,103,104存储了int的产量
OperateResult<byte[]> read = modbus.Read( "100", 5 );
if(read.IsSuccess)
{
    // 共计10个字节的结果内容
    short alarm = modbus.ByteTransform.TransInt16( read.Content, 0 );
    float temp = modbus.ByteTransform.TransSingle( read.Content, 2 );
    int product = modbus.ByteTransform.TransInt32( read.Content, 6 );
}
else
{
    // failed
}
参见