DAM3601Read 方法 (String, UInt16) |
从Modbus服务器批量读取寄存器的信息,需要指定起始地址,读取长度
命名空间:
HslCommunication.Instrument.Temperature
程序集:
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
起始地址,格式为"1234",或者是带功能码格式x=3;1234 - length
- 类型:SystemUInt16
读取的数量
返回值
类型:
OperateResultByte带有成功标志的字节信息
实现
IReadWriteNetRead(String, UInt16)IReadWriteNetRead(String, UInt16)示例
此处演示批量读取的示例
ModbusRtu modbus = new ModbusRtu( );
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
{
}
参见