@ -112,15 +112,66 @@ public class ModbusTcpMaster
return null ;
}
public byte [ ] ? BatchRead ( int registerNo , int length )
public byte [ ] ? BatchRead HolderRegister ( int registerNo , int length )
{
OperateResult < byte [ ] > result = ModbusTcpNet . Read ( "x=3;" + registerNo , ( ushort ) length ) ;
if ( result . IsSuccess ) return result . Content ;
return null ;
}
public byte [ ] ? BatchReadInputRegister ( int registerNo , int length )
{
OperateResult < byte [ ] > result = ModbusTcpNet . Read ( "x=4;" + registerNo , ( ushort ) length ) ;
if ( result . IsSuccess ) return result . Content ;
return null ;
}
/// <summary>
/// 读取线圈,需要指定起始地址,如果富文本地址不指定,默认使用的功能码是 0x01<br />
/// To read the coil, you need to specify the start address. If the rich text address is not specified, the default function code is 0x01.
/// </summary>
/// <param name="address">起始地址,格式为"1234"</param>
/// <returns>带有成功标志的bool对象</returns>
public OperateResult < bool > ReadCoil ( string address ) = > ModbusTcpNet . ReadBool ( address ) ;
/// <summary>
/// 批量的读取线圈,需要指定起始地址,读取长度,如果富文本地址不指定,默认使用的功能码是 0x01<br />
/// For batch reading coils, you need to specify the start address and read length. If the rich text address is not specified, the default function code is 0x01.
/// </summary>
/// <param name="address">起始地址,格式为"1234"</param>
/// <param name="length">读取长度</param>
/// <returns>带有成功标志的bool数组对象</returns>
public OperateResult < bool [ ] > ReadCoil ( string address , ushort length )
{
return ModbusTcpNet . ReadBool ( address , length ) ;
}
/// <summary>
/// 读取输入线圈,需要指定起始地址,如果富文本地址不指定,默认使用的功能码是 0x02<br />
/// To read the input coil, you need to specify the start address. If the rich text address is not specified, the default function code is 0x02.
/// </summary>
/// <param name="address">起始地址,格式为"1234"</param>
/// <returns>带有成功标志的bool对象</returns>
public OperateResult < bool > ReadDiscrete ( string address )
{
return ModbusTcpNet . ReadDiscrete ( address ) ;
}
/// <summary>
/// 批量的读取输入点,需要指定起始地址,读取长度,如果富文本地址不指定,默认使用的功能码是 0x02<br />
/// To read input points 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 0x02
/// </summary>
/// <param name="address">起始地址,格式为"1234"</param>
/// <param name="length">读取长度</param>
/// <returns>带有成功标志的bool数组对象</returns>
public OperateResult < bool [ ] > ReadDiscrete ( string address , ushort length )
{
return ModbusTcpNet . ReadDiscrete ( address , length ) ;
}
public bool WriteValue < T > ( ModbusProperty < T > property )
{
var value = property . Value ;