private void saveSettings()
        {
            FileStream fs = null;
            string settingFilename = @"Settings.ini";
            string pathString = Directory.GetCurrentDirectory () + settingFilename;

            SerialPortInfo spi = new SerialPortInfo ();
            spi = readSetting ();

            if (File.Exists (pathString))
            {
                File.Delete (pathString);
            }
            try
            {
                using (fs = new FileStream (pathString, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    using (var fw = new StreamWriter (fs))
                    {
                        fw.WriteLine ("[Main Settings]");
                        fw.WriteLine ("COM = " + spi.strCom);
                        fw.WriteLine ("SPEED = " + spi.nSpeed);
                        fw.WriteLine ("DATABIT = " + spi.nDatabit);
                        fw.WriteLine ("STOPBIT = " + spi.fStopbit);
                        fw.WriteLine ("PARITY = " + spi.strParity);
                        fw.WriteLine ("FLOWCONTROL = " + spi.strFlowcontrol);
                        fw.Flush (); // Added
                    }
                }
            }
            catch (IOException)
            {
                MessageBox.Show ("ERROR THROWN");
            }
        }
        private SerialPortInfo readSetting()
        {
            SerialPortInfo spc = new SerialPortInfo ();
            if (comSpeed.Text != "" && comDatabit.Text != "" && comStopbit.Text != "")
            {
                string strCom = comList.Text;
                int nSpeed = int.Parse (comSpeed.Text);
                int nDatabit = int.Parse (comDatabit.Text);
                float fStopbit = float.Parse (comStopbit.Text);
                string strParity = comParity.Text;
                string strFlowcontrol = comFlowControl.Text;

                spc.strCom = strCom;
                spc.nSpeed = nSpeed;
                spc.nDatabit = nDatabit;
                spc.fStopbit = fStopbit;
                spc.strParity = strParity;
                spc.strFlowcontrol = strFlowcontrol;
            }
            return spc;
        }
        private SerialPortInfo readSettingFile()
        {
            FileStream fs = null;
            string settingFilename = @"Settings.ini";
            string pathString = Directory.GetCurrentDirectory () + settingFilename;

            SerialPortInfo spi = new SerialPortInfo ();

            try
            {
                using (fs = new FileStream (pathString, FileMode.Open, FileAccess.ReadWrite))
                {
                    using (var fr = new StreamReader (fs))
                    {
                        while (fr.Peek () >= 0)
                        {
                            string strSetting = fr.ReadLine ();
                            string [] settingArray = strSetting.Trim ().Split ('=');
                            switch (settingArray[0].Trim().ToUpper())
                            {
                                case "COM":
                                    spi.strCom = settingArray [1].Trim();
                                    break;
                                case "SPEED":
                                    spi.nSpeed = Int16.Parse(settingArray [1].Trim ());
                                    break;
                                case "DATABIT":
                                    spi.nDatabit = Int16.Parse (settingArray [1].Trim ());
                                    break;
                                case "STOPBIT":
                                    spi.fStopbit = float.Parse (settingArray [1].Trim ());
                                    break;
                                case "PARITY":
                                    spi.strParity = settingArray [1].Trim ();
                                    break;
                                case "FLOWCONTROL":
                                    spi.strFlowcontrol = settingArray [1].Trim ();
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }
            }
            catch (IOException)
            {
                MessageBox.Show ("ERROR THROWN");
            }

            return spi;
        }