/// <summary>
        /// Initialize serialport.
        /// </summary>
        public void InitializeSerialPort()
        {
            //Read config and initialize serialport.
            config     = SerialPortConfigurer.ReadConfig();
            serialPort = new SerialPort(config.portName, config.baudRate, config.parity, config.dataBits, config.stopBits)
            {
                ReadBufferSize  = config.readBufferSize,
                ReadTimeout     = config.readTimeout,
                WriteBufferSize = config.writeBufferSize,
                WriteTimeout    = config.writeTimeout
            };

            //Initialize read and write thread.
            readThread = new Thread(ReadBytesFromBuffer)
            {
                IsBackground = true
            };
            writeThread = new Thread(WriteBytesToBuffer)
            {
                IsBackground = true
            };

            //Initialize bytes array.
            readBytes  = new byte[config.readCount];
            writeBytes = new byte[config.writeCount];
        }
        /// <summary>
        /// Initialize serialport.
        /// </summary>
        /// <param name="error">Error message.</param>
        /// <returns>Initialize base on config file.</returns>
        private bool InitializeSerialPort(out string error)
        {
            //Read config and initialize serialport.
            var isRead = SerialPortConfigurer.ReadConfig(out config, out error);

            serialPort = new SerialPort(config.portName, config.baudRate, config.parity, config.dataBits, config.stopBits)
            {
                ReadBufferSize  = config.readBufferSize,
                ReadTimeout     = config.readTimeout,
                WriteBufferSize = config.writeBufferSize,
                WriteTimeout    = config.writeTimeout
            };

            //Initialize read and write thread.
            readThread = new Thread(ReadBytesFromBuffer)
            {
                IsBackground = true
            };
            writeThread = new Thread(WriteBytesToBuffer)
            {
                IsBackground = true
            };

            //Initialize bytes array.
            readBytes  = new byte[config.readCount];
            writeBytes = new byte[config.writeCount];

            if (isRead)
            {
                Debug.Log("Initialize succeed.");
            }
            else
            {
                Debug.LogWarning("Initialize with default config. error : " + error);
            }

            //Return state.
            return(isRead);
        }
 private void Start()
 {
     config = SerialPortConfigurer.ReadConfig();
 }
        private void Start()
        {
            var error = string.Empty;

            SerialPortConfigurer.ReadConfig(out config, out error);
        }