Ejemplo n.º 1
0
        /// <summary>
        /// Creates an abstract Modbus PDU for the given function code.
        /// </summary>
        /// <param name="myModbusDevice">The Modbus device.</param>
        /// <param name="myFunctionCode">The function code.</param>
        protected AModbusPDU(IModbusDevice myModbusDevice, FunctionCode myFunctionCode)
        {
            ModbusDevice = myModbusDevice;
            FunctionCode = myFunctionCode;

            InvocationId = this.ModbusDevice.NextInvocationId;
        }
Ejemplo n.º 2
0
        public int[] ReadInputRegisters(IModbusDevice Device, int StartAddr, int Quantity)
        {
            var PDU = new ReadInputRegistersPDU(StartAddr, Quantity);
            var ADU = new RTU_ADU((Device as RTU_Device), PDU);

            Query(ADU);
            return(PDU.Value);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an abstract Modbus PDU for the given function code.
        /// </summary>
        /// <param name="myModbusDevice">The Modbus device.</param>
        /// <param name="myFunctionCode">The function code.</param>
        protected AModbusPDU(IModbusDevice myModbusDevice, FunctionCode myFunctionCode)
        {
            
            ModbusDevice = myModbusDevice;
            FunctionCode = myFunctionCode;

            InvocationId = this.ModbusDevice.NextInvocationId;

        }
Ejemplo n.º 4
0
        public bool[] ReadDiscreteInputs(IModbusDevice Device, int StartAddr, int Quantity)
        {
            if (!(Device is RTU_Device))
                throw new ArgumentException("Wrong Type", "Device");

            var PDU = new ReadDiscreteInputsPDU(StartAddr, Quantity);
            var ADU = new RTU_ADU((Device as RTU_Device), PDU);

            Query(ADU);
            return PDU.Value;
        }
Ejemplo n.º 5
0
        public void WriteMultipleRegisters(IModbusDevice Device, int StartAddr, int[] Value)
        {
            if (!(Device is RTU_Device))
            {
                throw new ArgumentException("Wrong Type", "Device");
            }

            var PDU = new WriteMultipleRegistersPDU(StartAddr, Value);
            var ADU = new RTU_ADU((Device as RTU_Device), PDU);

            Query(ADU);
        }
Ejemplo n.º 6
0
        public void WriteSingleCoil(IModbusDevice Device, int StartAddr, bool Value)
        {
            if (!(Device is RTU_Device))
            {
                throw new ArgumentException("Wrong Type", "Device");
            }

            var PDU = new WriteSingleCoilPDU(StartAddr, Value);
            var ADU = new RTU_ADU((Device as RTU_Device), PDU);

            Query(ADU);
        }
Ejemplo n.º 7
0
        public bool[] ReadDiscreteInputs(IModbusDevice Device, int StartAddr, int Quantity)
        {
            if (!(Device is RTU_Device))
            {
                throw new ArgumentException("Wrong Type", "Device");
            }

            var PDU = new ReadDiscreteInputsPDU(StartAddr, Quantity);
            var ADU = new RTU_ADU((Device as RTU_Device), PDU);

            Query(ADU);
            return(PDU.Value);
        }
Ejemplo n.º 8
0
        public int[] ReadHoldingRegisters(IModbusDevice Device, int StartAddr, int Quantity)
        {
            if (!(Device is RTU_Device))
                throw new ArgumentException("Wrong Type", "Device");

            var PDU = new ReadHoldingRegistersPDU(StartAddr, Quantity);
            var ADU = new RTU_ADU((Device as RTU_Device), PDU);
            Query(ADU);
            return PDU.Value;
        }
Ejemplo n.º 9
0
        public void WriteMultipleRegisters(IModbusDevice Device, int StartAddr, int[] Value)
        {
            if (!(Device is RTU_Device))
                throw new ArgumentException("Wrong Type", "Device");

            var PDU = new WriteMultipleRegistersPDU(StartAddr, Value);
            var ADU = new RTU_ADU((Device as RTU_Device), PDU);

            Query(ADU) ;

       
        }
Ejemplo n.º 10
0
        public void WriteSingleCoil(IModbusDevice Device, int StartAddr, bool Value)
        {
            if (!(Device is RTU_Device))
                throw new ArgumentException("Wrong Type", "Device");

            var PDU = new WriteSingleCoilPDU(StartAddr, Value);
            var ADU = new RTU_ADU((Device as RTU_Device), PDU);
            Query(ADU);
        }
Ejemplo n.º 11
0
 public int[] ReadInputRegisters(IModbusDevice Device, int StartAddr, int Quantity)
 {
     var PDU = new ReadInputRegistersPDU(StartAddr, Quantity);
     var ADU = new RTU_ADU((Device as RTU_Device), PDU);
     Query(ADU);
     return PDU.Value;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// This creates a new Modbus PDU for the Read Coils function code (0x01).
 /// It is used to read from 1 to 2000 contiguous status coils (bits)
 /// in a remote device starting at the given address and for the given
 /// number of coils (bits).
 /// </summary>
 /// <param name="myModbusDevice">The Modbus device.</param>
 /// <param name="myStartAddress">The starting address.</param>
 /// <param name="myNumberOfCoils">The number of coils to read.</param>
 public ReadCoils(IModbusDevice myModbusDevice, UInt16 myStartAddress, UInt16 myNumberOfCoils)
     : base(myModbusDevice, FunctionCode.ReadCoils)
 {
     StartAddress  = myStartAddress;
     NumberOfCoils = myNumberOfCoils;
 }