//--------------------------------------------//
        #endregion

        #region DataReceived
        //--------------------------------------------//

        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort currentPort = (SerialPort)sender;

            Thread.Sleep(200);
            try
            {
                String sign = currentPort.ReadLine();
                switch (sign)
                {
                case "a":                          //port parmeters changed
                    currentPort.DiscardInBuffer(); // discard current data, if exsist
                    TopMessageBox.AppendText("Controller Parameters changed !");
                    closePort();                   //close the port
                    ChangePara.Enabled   = true;   // enabled change in pc parametrs
                    SendPara.Enabled     = false;
                    ControllerParaChange = true;   // the controller has change his parameters
                    break;

                case "l":     //recieve list of files
                    FileListBox.BeginInvoke(new EventHandler(delegate { FileListBox.Items.Clear(); }));
                    string list = currentPort.ReadLine();
                    if (list == " ")
                    {
                        FileListBox.Items.Add("No files");
                    }
                    else
                    {
                        while (list != ">")     // ='>'.
                        {
                            FileListBox.BeginInvoke(new EventHandler(delegate { FileListBox.Items.Add(list.ToString()); }));
                            Thread.Sleep(150);
                            list = currentPort.ReadLine();
                        }
                    }
                    break;

                case "U":     // Recieve controler port parameters - optional
                    string parameters = "Baud rate : " + currentPort.ReadLine() + " BPS, "
                                        + currentPort.ReadLine() + " Data bits,";
                    parameters += " 1 Start," + StopBit.ToString() + " Stop bit,";
                    currentPort.ReadLine();
                    parameters += currentPort.ReadLine() + " Parity";
                    sign        = currentPort.ReadLine(); // for the final signal '>'
                    TopMessageBox.AppendText(parameters);
                    break;

                case "S":                                               // Recieve file
                    string current = currentPort.ReadExisting();
                    current = current.Substring(0, current.Length - 3); // dont save the last char '>' and 0x1A
                    string path      = PathBox.Text;
                    string namefile  = FileName.Text + ".txt";
                    int    Duplicate = 0;
                    try
                    {
                        while (File.Exists(Path.Combine(path, namefile)))
                        {
                            Duplicate++;
                            namefile = FileName.Text + Duplicate.ToString() + ".txt";
                        }

                        using (FileStream fileToSave = File.Create(Path.Combine(path, namefile)))
                        {
                            Byte[] data = new UTF8Encoding(true).GetBytes(current);
                            fileToSave.Write(data, 0, data.Length);
                        }
                        TopMessageBox.AppendText("File saved !");
                    }
                    catch { TopMessageBox.AppendText("Error oucerd !"); }
                    break;

                case "D":
                    TopMessageBox.AppendText("File saved in the controller ! \n");
                    currentPort.ReadLine();
                    break;

                default:      // discard current data, if exsist
                    currentPort.ReadExisting();
                    break;
                }
            }
            catch { port.DiscardInBuffer(); }
        }