我正在开发Windows窗体以用作Modbus主模拟器。 我正在使用NModbus库。 我试图在屏幕上进行读取或写入操作后显示从设备收到的响应。 例如,这是从NModbus库读取线圈功能代码,
public class ModbusIpMaster : ModbusMaster
{
private ModbusIpMaster(ModbusTransport transport)
: base(transport)
{
}
/// Read from 1 to 2000 contiguous coils status.
/// </summary>
/// <param name="startAddress">Address to begin reading.</param>
/// <param name="numberOfPoints">Number of coils to read.</param>
/// <returns>Coils status</returns>
public bool[] ReadCoils(ushort startAddress, ushort numberOfPoints)
{
return base.ReadCoils(Modbus.DefaultIpSlaveUnitId, startAddress,
numberOfPoints);
}
}
ReadCoils方法位于抽象类ModbusMaster的基类中。
public abstract class ModbusMaster : ModbusDevice, IModbusMaster
{
internal ModbusMaster(ModbusTransport transport)
: base(transport)
{
}
public bool[] ReadCoils(byte slaveAddress, ushort startAddress, ushort
numberOfPoints)
{
ValidateNumberOfPoints("numberOfPoints", numberOfPoints, 2000);
return ReadDiscretes(Modbus.ReadCoils, slaveAddress, startAddress,
numberOfPoints);
}
internal bool[] ReadDiscretes(byte functionCode, byte slaveAddress,
ushort startAddress, ushort numberOfPoints)
{
ReadCoilsInputsRequest request = new
ReadCoilsInputsRequest(functionCode, slaveAddress,
startAddress, numberOfPoints);
ReadCoilsInputsResponse response =
Transport.UnicastMessage<ReadCoilsInputsResponse>(request);
return response.Data.Slice(0, request.NumberOfPoints).ToArray();
}
}
我想访问Read Discrete方法以使用ReadCoilsInputResponse来显示包含字节数,从属ID,数据等的响应。 但是,当我创建类ModbusIPMaster的实例并使用该实例访问Read Discrete方法时,我无法访问它。 谁能帮我解决这个问题?还是有其他方法可以显示收到的完整回复? 以下是引用NModbus库的链接 https://github.com/NModbus/NModbus
答案 0 :(得分:0)
ReadDiscretes声明为内部。您在同一集合中吗?如果不是,那么也许您应该考虑宣布为公开?