Пример #1
0
        private void cal_panel_button_browse_Click(object sender, EventArgs e)
        {
            try
              {
                  //check the path selected in the textbox
                  //this.folderBrowserDialog1.ShowNewFolderButton = false;
                  this.openFileDialog1.Multiselect = false;
                  this.openFileDialog1.FileName = "*.xml";

                  if (cal_panel_entry_path.Text.Trim().CompareTo("") != 0)
                  {
                      if (Directory.Exists(cal_panel_entry_path.Text))
                      { //this.folderBrowserDialog1.SelectedPath = cal_panel_entry_path.Text.ToString();
                          this.openFileDialog1.InitialDirectory = cal_panel_entry_path.Text.ToString();
                      }

                  }

                  //check the path selected in the dialog
                 // DialogResult result = this.folderBrowserDialog1.ShowDialog();
                  DialogResult result = this.openFileDialog1.ShowDialog();

                  if (result == DialogResult.OK)
                  {
                      //string fullPath = this.folderBrowserDialog1.SelectedPath;
                      string fullPath = this.openFileDialog1.FileName;

                      cal_panel_entry_path.Text = fullPath;

                      if (cal_panel_entry_path.Text.Trim().CompareTo("") == 0)
                      {
                          cal_panel_label_status.Text = "Please provide a valid path";
                      }
                      else
                      {

                          WocketsController wc_xml = new WocketsController("", "", "");
                          wc_xml.FromXML(fullPath);
                          Accelerometer acc_sensor = (Accelerometer)wc_xml._Sensors[0];

                          //if it is a valid sensordata file with calibration values
                          //open the sensordata file and get the calibration values
                          //fullPath = fullPath + "\\SensorData.xml";
                          if (File.Exists(fullPath))
                          {

                              if (current_command.CompareTo("calibration") == 0)
                              {
                                  //update the calibration fields
                                  cal_panel_x1g.Text = acc_sensor._Calibration._X1G.ToString();
                                  cal_panel_xn1g.Text = acc_sensor._Calibration._XN1G.ToString();
                                  cal_panel_xstd.Text = acc_sensor._XStd.ToString();

                                  cal_panel_y1g.Text = acc_sensor._Calibration._Y1G.ToString();
                                  cal_panel_yn1g.Text = acc_sensor._Calibration._YN1G.ToString();
                                  cal_panel_ystd.Text = acc_sensor._YStd.ToString();

                                  cal_panel_z1g.Text = acc_sensor._Calibration._Z1G.ToString();
                                  cal_panel_zn1g.Text = acc_sensor._Calibration._ZN1G.ToString();
                                  cal_panel_zstd.Text = acc_sensor._ZStd.ToString();

                                  //load the fields
                                  xyzP[0] = acc_sensor._Calibration._X1G;
                                  xyzP[1] = acc_sensor._Calibration._Y1G;
                                  xyzP[2] = acc_sensor._Calibration._Z1G;

                                  xyzN[0] = acc_sensor._Calibration._XN1G;
                                  xyzN[1] = acc_sensor._Calibration._YN1G;
                                  xyzN[2] = acc_sensor._Calibration._ZN1G;

                                  xyzSTD[0] = acc_sensor._XStd;
                                  xyzSTD[1] = acc_sensor._YStd;
                                  xyzSTD[2] = acc_sensor._ZStd;

                                  //write the status to screen
                                  cal_panel_label_status.Text = "The sensordata file is valid. You can set the CAL values.";
                                  is_sensordata_valid = true;

                              }
                              else if (current_command.CompareTo("battery_calibration") == 0)
                              {
                                  // it is a valid sensordata file with calibration values
                                  //open the battery calibration file and get the cal values
                                  cal_panel_label_status.Text = "The battery calibration file is valid. You can set the CAL values.";
                                  is_sensordata_valid = true;
                              }
                          }
                          else
                          {
                              cal_panel_label_status.Text = "The sensordata file is NOT valid. Please try again or click CANCEL to exit the calibration.";
                          }

                          //dispose xml wockets controller
                          acc_sensor.Dispose();
                          wc_xml.Dispose();

                      }
                  }

              } // end try
              catch (Exception err)
              {
                  Console.WriteLine(err.Message);
              }
        }