Exemplo n.º 1
0
        /// <summary>
        /// Read holding registers from remote device
        /// </summary>
        /// <param name="startAddress"></param>
        /// <param name="itemCount"></param>
        /// <returns>Array of holding register values</returns>
        public short[] ReadHoldings(ushort startAddress, ushort itemCount)
        {
            MBReadHoldingRegisters hodingRegistersData = new MBReadHoldingRegisters(startAddress, itemCount);

            expectedResponseBytes = TypeManager <MBReadHoldingRegisters> .GetExpectedBytesByFunction((int)MbFunctions.ReadHoldings, itemCount);

            var holdingRegisters = Read((byte)MbFunctions.ReadHoldings, TypeManager <MBReadHoldingRegisters> .ToBytes(hodingRegistersData));

            return(TypeManager <MBReadHoldingRegisters> .ParseRegisters(holdingRegisters, itemCount));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read discrete inputs from remote device
        /// </summary>
        /// <param name="startAddress"></param>
        /// <param name="itemCount"></param>
        /// <returns>Array of discrete input values(True/False)</returns>
        public byte[] ReadDiscreteInputs(ushort startAddress, ushort itemCount)
        {
            MBReadDiscretes discretesData = new MBReadDiscretes(startAddress, itemCount);

            expectedResponseBytes = TypeManager <MBReadDiscretes> .GetExpectedBytesByFunction((int)MbFunctions.ReadDiscreteInputs, itemCount);

            var discreteInputs = Read((byte)MbFunctions.ReadDiscreteInputs, TypeManager <MBReadDiscretes> .ToBytes(discretesData));

            return(TypeManager <MBReadDiscretes> .ParseDiscretes(discreteInputs, itemCount));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Preset/write multiple holding registers
        /// </summary>
        /// <param name="address">Address of first holding register to preset/write</param>
        /// <param name="countItems">Number of holding registers to preset/write</param>
        /// <param name="nextByteCount">Number of bytes of register values to follow</param>
        /// <param name="data">New values of holding registers (16 bits per register)</param>
        /// <returns>Number of preset/written holding registers</returns>
        public int WriteHoldings(ushort address, ushort countItems, byte nextByteCount, short[] data)
        {
            var writeHoldingsData = new MBWriteHoldings(address, countItems, nextByteCount);
            var allNumbers        = TypeManager <MBWriteHoldings> .ToBytes(writeHoldingsData).Concat(TypeManager <MBWriteHoldings> .ToBytes(data)).ToArray();

            expectedResponseBytes = TypeManager <MBWriteHoldings> .GetExpectedBytesByFunction((int)MbFunctions.WriteHoldings, countItems);

            var writeCountBytes = WriteRegisters((byte)MbFunctions.WriteHoldings, allNumbers);

            return(writeCountBytes);
        }