Exemple #1
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);
        }
Exemple #2
0
        /// <summary>
        /// Preset/write single holding register to remote device
        /// </summary>
        /// <param name="address">Address of holding register to preset/write</param>
        /// <param name="value"></param>
        /// <returns>Recording result (true/ false)</returns>
        public bool WriteSingleHolding(ushort address, ushort value)
        {
            var writeHoldingData = new MBWriteSingleHolding(address, value);
            var writeResult      = WriteRegister((byte)MbFunctions.WriteSingleHolding, TypeManager <MBWriteSingleHolding> .ToBytes(writeHoldingData));

            return(writeResult);
        }