ModbusTcpServerRead 方法 (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 中) 版本: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
起始地址,比如"100","x=4;100","s=1;100","s=1;x=4;100" - length
- 类型:SystemUInt16
读取的数量
返回值
类型:
OperateResultByte带有成功标志的字节信息
实现
IReadWriteNetRead(String, UInt16)备注
富地址格式,支持携带站号信息,功能码信息,具体参照类的示例代码
示例
此处演示批量读取的示例
ModbusTcpNet modbus = new ModbusTcpNet( "192.168.0.1" );
OperateResult<byte[]> read = modbus.Read( "100", 5 );
if(read.IsSuccess)
{
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
{
}
参见