public frmMVCTestMulti(MvcTestMode TestMode)
        {
            InitializeComponent();
            this.Dock = DockStyle.Fill;
            this.Width = Screen.PrimaryScreen.Bounds.Width;
            this.Height = Screen.PrimaryScreen.Bounds.Height;

            testMode = TestMode;
            DataSample = new Classes.MvcDS(GlobalVariables.leftSerialPort);
            AssignCallbackMethods();
            dSet = new MvcDataSet();

            dSetArray[0] = new MvcDataSetMulti("LLQC");
            dSetArray[1] = new MvcDataSetMulti("LLQE");
            dSetArray[2] = new MvcDataSetMulti("LLHC");
            dSetArray[3] = new MvcDataSetMulti("LLHE");
            dSetArray[4] = new MvcDataSetMulti("RLQC");
            dSetArray[5] = new MvcDataSetMulti("RLQE");
            dSetArray[6] = new MvcDataSetMulti("RLHC");
            dSetArray[7] = new MvcDataSetMulti("RLHE");

            // Set the control style to double buffer.
            //this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
            //this.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
            //this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }
        //Done
        #region Left Leg Quads Conc
        private void TestLeftLegQuadConc()
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
            //DisableButtons();

            dSetArray[0] = new MvcDataSetMulti("LLQC");
            foreach (DataTable dTable in dSetArray[0].Tables)
            {
                dTable.Rows.Clear();
            }

            DataSample.SelectedTorque = 300;
            DataSample.SelectedSpeed = Convert.ToInt32(Math.Ceiling((15.0/360.0)*60.0))*3;
            DataSample.MaxTorqueLeftQuadConc = 0;                                                         //Reset Max Left Torque

            if (GlobalVariables.ServoController.InitiateMotor(DataSample.SelectedSpeed, DataSample.SelectedTorque, Enumerators.Direction.Forward, GlobalVariables.leftSerialPort).IsSuccess == false)
                return;
            else
            {
                GlobalVariables.leftSerialPort.DiscardInBuffer();
                GlobalVariables.leftSerialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort_DataReceived_TestLeftLegQuadsConc);
            }
        }
        public void PopulateXmlfile(MvcDataSetMulti[] MvcData)
        {
            DataSet DataTables = new DataSet();

            string UserId;
            if (GlobalVariables.LoggedInUser != null)
            {
                UserId = GlobalVariables.LoggedInUser.id.ToString();
            }
            else
            {
                UserId = "0";
            }

            string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\XmlData\\" +UserId;
            if (!System.IO.Directory.Exists(directory))
                System.IO.Directory.CreateDirectory(directory);

            string FileName = directory + "\\DataSet.xml";
            if (!System.IO.File.Exists(FileName))
            {
                System.IO.FileStream fs = System.IO.File.Create(FileName);
                fs.Close();
            }
            else
            {
                System.IO.File.Delete(FileName);
                System.IO.FileStream fs = System.IO.File.Create(FileName);
                fs.Close();
            }

            for (int ii = 0; ii <= 7; ii++)
            {
                //Copy DataTables to Main DataSet
                for (int jj = 0;jj<4;jj++)
                {
                    if (MvcData[ii].Tables[jj].Rows.Count == 0)
                    {
                        for (int kk = 0; kk < 50; kk++)
                        {
                            MvcData[ii].AddNewRow(jj, 0, 0);
                        }
                    }
                    DataTable dtCopy = MvcData[ii].Tables[jj].Copy();
                    DataTables.Tables.Add(dtCopy);
                }
                //DataTable[] dTableArray = new DataTable[4];
                //MvcData[ii].Tables.CopyTo(dTableArray, 0);
                //DataTables.Tables.AddRange(dTableArray);
                //string FileName = directory + "\\DataSet_" + ii.ToString() + ".xml";
                //if (!System.IO.File.Exists(FileName))
                //{
                //    System.IO.FileStream fs = System.IO.File.Create(FileName);
                //    fs.Close();
                //}
                //else
                //{
                //    System.IO.File.Delete(FileName);
                //    System.IO.FileStream fs = System.IO.File.Create(FileName);
                //    fs.Close();
                //}

                try
                {
                    DataTables.WriteXml(FileName);
                } 
                catch (Exception ex)
                {
                    MessageBox.Show("Exception caught in WriteXML: {0}", ex.ToString());
                }
            }
        }