简体   繁体   中英

Access methods and members of an Abstract class

I am developing a Windows form to function as a modbus master Simulator. I am using NModbus Library. I am trying to display the response recieved from slave after read or write operation on the screen. For example here is the read coil function code from NModbus library,

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);
       }
}

The ReadCoils Method is found in base Class ModbusMaster which is an abstract class.

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();
        }
}

i want to access the Read Discrete method to use the ReadCoilsInputResponse to display the response containing bytecount,slave id, data etc. But when i create an instance of class ModbusIPMaster and use that instance to access the Read Discrete method, i am not able to access it. Can anyone help me resolving this? or is there any other way to display the complete response received ? Following is the link to refer to NModbus library https://github.com/NModbus/NModbus

ReadDiscretes is declared internal. Are you within the same assembly? If not then maybe you should consider declaring it public?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM