/// <summary>
        /// Command code 48:  Mixed read the random discrete status or register data.
        /// </summary>
        /// <param name="slaveStationNo">Slave Station No</param>
        /// <param name="numberOfPoints">Number Of Points.</param>
        /// <param name="components">List<RandomRegister></param>
        /// <returns>string</returns>
        public RandomRegister[] ReadRadomDiscreteOrRegisters(int slaveStationNo, ushort numberOfPoints, List <RandomRegister> components)
        {
            List <RandomRegister> result = new List <RandomRegister>();

            try
            {
                string frame = this.GetMessageReadRadomDiscreteOrRegisters(slaveStationNo, CommandCode.MIXED_READ_THE_RADOM_DISCRETE_STATUS_OF_REGISTER_DATA, numberOfPoints, components);
                objSerialPort.WriteLine(frame);


                // Read SerialPort
                int CONST = 0;
                foreach (RandomRegister item in components)
                {
                    switch (item.DataType)
                    {
                    case DataType.BOOL:
                        CONST += 1;
                        break;

                    case DataType.INT:
                    case DataType.WORD:
                        CONST += 4;
                        break;

                    case DataType.DINT:
                    case DataType.DWORD:
                    case DataType.REAL:
                        CONST += 8;
                        break;

                    default:
                        throw new InvalidOperationException("Data type is invalid");
                    }
                }

                int      sizeOfMessageReceiver = CONST + 9;
                string   buffReceiver          = string.Empty;
                DateTime startDateTime         = DateTime.Now;
                do
                {
                    this.CheckBufferReceiver(buffReceiver);
                    buffReceiver = objSerialPort.ReadExisting();
                    System.Threading.Thread.Sleep(100);
                } while (buffReceiver.Length < sizeOfMessageReceiver && (DateTime.Now.Subtract(startDateTime).TotalMilliseconds < objSerialPort.ReadTimeout));
                //Console.WriteLine("ReadTimeout: {0}", DateTime.Now.Subtract(startDateTime).TotalMilliseconds);
                string errorMsg = this.GetException(buffReceiver);
                if (!string.IsNullOrEmpty(errorMsg) || !string.IsNullOrWhiteSpace(errorMsg))
                {
                    throw new Exception(errorMsg);
                }

                int    index        = 0;
                string dataReceiver = string.Empty;
                string valueString  = string.Empty;

                dataReceiver = buffReceiver.Substring(6, CONST); // data.

                foreach (RandomRegister item in components)
                {
                    switch (item.DataType)
                    {
                    case DataType.BOOL:
                        valueString = dataReceiver.Substring(index, 1);
                        item.Value  = !"0".Equals(valueString) ? true : false;
                        index      += 1;
                        break;

                    case DataType.INT:
                        valueString = dataReceiver.Substring(index, 4);
                        item.Value  = Conversion.HEXToINT(valueString);
                        index      += 4;
                        break;

                    case DataType.WORD:
                        valueString = dataReceiver.Substring(index, 4);
                        item.Value  = Conversion.HEXToWORD(valueString);
                        index      += 4;
                        break;

                    case DataType.DINT:
                        valueString = dataReceiver.Substring(index, 8);
                        item.Value  = Conversion.HEXToDINT(valueString);
                        index      += 8;
                        break;

                    case DataType.DWORD:
                        valueString = dataReceiver.Substring(index, 8);
                        item.Value  = Conversion.HEXToDWORD(valueString);
                        index      += 8;
                        break;

                    case DataType.REAL:
                        valueString = dataReceiver.Substring(index, 8);
                        item.Value  = Conversion.HEXToREAL(valueString);
                        index      += 8;
                        break;

                    default:
                        throw new InvalidOperationException("Data type is invalid");
                    }
                    result.Add(item);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result.ToArray());
        }
        /// <summary>
        /// Command code 46:  Read the data from continuous registers.
        /// </summary>
        /// <param name="slaveStationNo">Slave Station No</param>
        /// <param name="numberOfPoints">Number Of Points.</param>
        /// <param name="mType">Memory Type.</param>
        /// <param name="startRegister">Start register No(6 or 7 words)</param>
        /// <param name="dType">Data Type.</param>
        /// <returns>object[]</returns>
        public object[] ReadRegisters(int slaveStationNo, ushort numberOfPoints, MemoryType mType, ushort startRegister, DataType dType)
        {
            List <object> result = new List <object>();

            try
            {
                string frame = this.GetMessageReadRegisters(slaveStationNo, CommandCode.READ_THE_DATA_FROM_CONTINUOUS_REGISTERS, numberOfPoints, mType, startRegister, dType);
                objSerialPort.WriteLine(frame);

                // Read SerialPort
                int CONST = 4;
                switch (dType)
                {
                case DataType.INT:
                case DataType.WORD:
                    CONST = 4;
                    break;

                case DataType.DINT:
                case DataType.DWORD:
                case DataType.REAL:
                    CONST = 8;
                    break;

                default:
                    throw new InvalidOperationException("Data type is invalid");
                }
                int      sizeOfMessageReceiver = numberOfPoints * CONST + 9;
                string   buffReceiver          = string.Empty;
                DateTime startDateTime         = DateTime.Now;
                do
                {
                    this.CheckBufferReceiver(buffReceiver);
                    buffReceiver = objSerialPort.ReadExisting();
                    System.Threading.Thread.Sleep(100);
                } while (buffReceiver.Length < sizeOfMessageReceiver && (DateTime.Now.Subtract(startDateTime).TotalMilliseconds < objSerialPort.ReadTimeout));
                //Console.WriteLine("ReadTimeout: {0}", DateTime.Now.Subtract(startDateTime).TotalMilliseconds);
                string errorMsg = this.GetException(buffReceiver);
                if (!string.IsNullOrEmpty(errorMsg) || !string.IsNullOrWhiteSpace(errorMsg))
                {
                    throw new Exception(errorMsg);
                }

                int    index        = 0;
                string dataReceiver = string.Empty;
                string valueString  = string.Empty;

                dataReceiver = buffReceiver.Substring(6, numberOfPoints * CONST); // data.
                switch (dType)
                {
                case DataType.INT:
                    do
                    {
                        valueString = dataReceiver.Substring(CONST * index, CONST);
                        short value = Conversion.HEXToINT(valueString);
                        result.Add(value);
                    } while (++index < numberOfPoints);
                    break;

                case DataType.WORD:
                    do
                    {
                        valueString = dataReceiver.Substring(CONST * index, CONST);
                        ushort value = Conversion.HEXToWORD(valueString);
                        result.Add(value);
                    } while (++index < numberOfPoints);
                    break;

                case DataType.DINT:
                    do
                    {
                        valueString = dataReceiver.Substring(CONST * index, CONST);
                        int value = Conversion.HEXToDINT(valueString);
                        result.Add(value);
                    } while (++index < numberOfPoints);
                    break;

                case DataType.DWORD:
                    do
                    {
                        valueString = dataReceiver.Substring(CONST * index, CONST);
                        uint value = Conversion.HEXToDWORD(valueString);
                        result.Add(value);
                    } while (++index < numberOfPoints);
                    break;

                case DataType.REAL:
                    do
                    {
                        valueString = dataReceiver.Substring(CONST * index, CONST);
                        float value = Conversion.HEXToREAL(valueString);
                        result.Add(value);
                    } while (++index < numberOfPoints);
                    break;

                default:
                    throw new InvalidOperationException("Data type is invalid");
                }
                //Console.WriteLine("buffReceiver: {0}", buffReceiver);
                //Console.WriteLine("dataReceiver: {0}", dataReceiver);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result.ToArray());
        }