/*--------------------------------------------------------------------------------------*/


        /* Complex send Method send and Activate Timer */
        private void complexSendMethod(ProtocolProcess.frameCode cf, string data)
        {
            try
            {
                confirmFlag   = false;
                cycleSendFlag = false;
                timer10ms.Stop();
                timer1s.Stop();
                /*Gửi frame*/
                sendBuffer = ProtocolProcess.encodeFrame(cf, data);
                sPort.Write(sendBuffer, 0, 7);
                //txb
                for (int i = 0; i < 7; i++)
                {
                    txb_SendMonitor.Text += sendBuffer[i].ToString();
                }
                txb_SendMonitor.Text += Environment.NewLine;
                //Kết thúc


                /*Kích hoạt timer*/
                timer10ms.Start();
                timer1s.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void processReceiveData(object sender, EventArgs e)
        {
            confirmFlag = true;
            byte[] processedData;
            ProtocolProcess.frameCode funcCode = ProtocolProcess.decodeFrame(receiveBuffer, out processedData);
            float mainValue = ProtocolProcess.byteToFloat(processedData);

            switch (funcCode)
            {
            case ProtocolProcess.frameCode.Datasend:
                //txb_Receiver.Text += "TEST Nhận: ";
                //txb_Receiver.Text += mainValue.ToString();
                //txb_Receiver.Text += Environment.NewLine;

                /*Test File*/
                WriteNewLineTXTFile(txtPathFile, mainValue.ToString());
                /*----------*/
                break;

            case ProtocolProcess.frameCode.ACK:
                txb_Receiver.Text += "Xác nhận ACK ";
                //txb_Receiver.Text += mainValue.ToString();
                txb_Receiver.Text += Environment.NewLine;
                break;

            case ProtocolProcess.frameCode.VeloFor:
                setpoint       = setpointdp;
                measure        = mainValue;
                realtime      += realtimestep;
                txb_Velo.Text  = mainValue.ToString();
                txb_ReFor.Text = "For";
                //txb_Receiver.Text += $"Giá trị Velo đọc về: {mainValue.ToString()} Thuận";
                //txb_Receiver.Text += Environment.NewLine;
                break;

            case ProtocolProcess.frameCode.VeloRev:
                setpoint       = setpointdp;
                measure        = mainValue;
                realtime      += realtimestep;
                txb_Velo.Text  = mainValue.ToString();
                txb_ReFor.Text = "Rev";
                //txb_Receiver.Text += $"Giá trị Velo đọc về: {mainValue.ToString()} Ngược";
                //txb_Receiver.Text += Environment.NewLine;
                break;

            case ProtocolProcess.frameCode.Pos:
                setpoint     = float.Parse(txb_SpPos.Text);
                measure      = mainValue;
                realtime    += realtimestep;
                txb_Pos.Text = mainValue.ToString();
                //txb_Receiver.Text += $"Giá trị Pos đọc về: {mainValue.ToString()}";
                //txb_Receiver.Text += Environment.NewLine;
                break;

            default:
                break;
            }

            /*Vẽ Zed graph giá trị đã nhận được*/
            Draw();
        }