ModbusTcpNetWrite 方法 (String, Byte) |
将数据写入到Modbus的寄存器上去,需要指定起始地址和数据内容,如果富文本地址不指定,默认使用的功能码是 0x10
To write data to Modbus registers, you need to specify the start address and data content. If the rich text address is not specified, the default function code is 0x10
命名空间:
HslCommunication.ModBus
程序集:
HslCommunication (在 HslCommunication.dll 中) 版本:12.1.2.0 (12.1.2.0)
语法 public override OperateResult Write(
string address,
byte[] value
)
Public Overrides Function Write (
address As String,
value As Byte()
) As OperateResult
public:
virtual OperateResult^ Write(
String^ address,
array<unsigned char>^ value
) override
abstract Write :
address : string *
value : byte[] -> OperateResult
override Write :
address : string *
value : byte[] -> OperateResult
参数
- address
- 类型:SystemString
起始地址,比如"100","x=4;100","s=1;100","s=1;x=4;100" - value
- 类型:SystemByte
写入的数据,长度根据data的长度来指示
返回值
类型:
OperateResult返回写入结果
实现
IReadWriteNetWrite(String, Byte)IReadWriteNetWrite(String, Byte)备注
富地址格式,支持携带站号信息,功能码信息,具体参照类的示例代码
示例
此处演示批量写入的示例
ModbusTcpNet modbus = new ModbusTcpNet( "192.168.0.1" );
byte[] buffer = new byte[10];
modbus.ByteTransform.TransByte( (short)1 ).CopyTo( buffer, 0 );
modbus.ByteTransform.TransByte( 123.456f ).CopyTo( buffer, 2 );
modbus.ByteTransform.TransByte( 45678922 ).CopyTo( buffer, 6 );
OperateResult write = modbus.Write( "100", buffer );
if (write.IsSuccess)
{
}
else
{
}
参见