// ------------------------------------------------------------------------
        /// <summary>Write single register in slave synchronous.</summary>
        /// <param name="id">Unique id that marks the transaction. In asynchonous mode this id is given to the callback function.</param>
        /// <param name="startAddress">Address to where the data is written.</param>
        /// <param name="values">Contains the register information.</param>
        /// <param name="result">Contains the result of the synchronous write.</param>
        public void WriteSingleRegister(UInt16 myInvocationId, UInt16 startAddress, Byte[] values, ref Byte[] result)
        {
            var _ModbusPDU = ModbusProtocol.CreateWriteHeader(myInvocationId, startAddress, 1, 1, FunctionCode.WriteSingleRegister);

            _ModbusPDU.Write(values, 10, 2);

            result = WriteSyncData(_ModbusPDU, myInvocationId);
        }
        // ------------------------------------------------------------------------
        /// <summary>Write multiple coils in slave synchronous.</summary>
        /// <param name="id">Unique id that marks the transaction. In asynchonous mode this id is given to the callback function.</param>
        /// <param name="startAddress">Address from where the data read begins.</param>
        /// <param name="numBits">Specifys number of bits.</param>
        /// <param name="values">Contains the bit information in byte format.</param>
        /// <param name="result">Contains the result of the synchronous write.</param>
        public void WriteMultipleCoils(UInt16 myInvocationId, UInt16 startAddress, UInt16 numBits, Byte[] values, ref Byte[] result)
        {
            var _NumBytes  = Convert.ToByte(values.Length);
            var _ModbusPDU = ModbusProtocol.CreateWriteHeader(myInvocationId, startAddress, numBits, (byte)(_NumBytes + 2), FunctionCode.WriteMultipleCoils);

            _ModbusPDU.Write(values, 13, _NumBytes);

            result = WriteSyncData(_ModbusPDU, myInvocationId);
        }
        // ------------------------------------------------------------------------
        /// <summary>Write single coil in slave synchronous.</summary>
        /// <param name="id">Unique id that marks the transaction. In asynchonous mode this id is given to the callback function.</param>
        /// <param name="startAddress">Address from where the data read begins.</param>
        /// <param name="OnOff">Specifys if the coil should be switched on or off.</param>
        /// <param name="result">Contains the result of the synchronous write.</param>
        public void WriteSingleCoils(UInt16 myInvocationId, UInt16 startAddress, bool OnOff, ref Byte[] result)
        {
            var _ModbusPDU = ModbusProtocol.CreateWriteHeader(myInvocationId, startAddress, 1, 1, FunctionCode.WriteSingleCoil);

            if (OnOff == true)
            {
                _ModbusPDU.Seek(10, SeekOrigin.Begin);
                _ModbusPDU.WriteByte(255);
            }

            result = WriteSyncData(_ModbusPDU, myInvocationId);
        }
        // ------------------------------------------------------------------------
        /// <summary>Write multiple registers in slave synchronous.</summary>
        /// <param name="id">Unique id that marks the transaction. In asynchonous mode this id is given to the callback function.</param>
        /// <param name="startAddress">Address to where the data is written.</param>
        /// <param name="values">Contains the register information.</param>
        /// <param name="result">Contains the result of the synchronous write.</param>
        public void WriteMultipleRegister(UInt16 myInvocationId, UInt16 startAddress, Byte[] values, ref Byte[] result)
        {
            UInt16 numBytes = Convert.ToUInt16(values.Length);

            if (numBytes % 2 > 0)
            {
                numBytes++;
            }

            var _ModbusPDU = ModbusProtocol.CreateWriteHeader(myInvocationId, startAddress, Convert.ToUInt16(numBytes / 2), Convert.ToByte(numBytes + 2), FunctionCode.WriteMultipleRegister);

            _ModbusPDU.Write(values, 13);

            result = WriteSyncData(_ModbusPDU, myInvocationId);
        }