Ejemplo n.º 1
0
        private void btnLoadGeneralCalib_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.DefaultExt = "txt";
            ofd.Filter     = "Calibration Text File (*.json)|*.json|All files (*.*)|*.*";
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                log.Error("a file must be selected!");
                return;
            }


            try
            {
                gridGeneralCalib.Rows.Clear();
                GeneralCalibrationTable tbl = JsonConvert.DeserializeObject <GeneralCalibrationTable>(File.ReadAllText(ofd.FileName));

                FieldInfo[] fields = typeof(GeneralCalibrationTable).GetFields();
                foreach (FieldInfo f in fields)
                {
                    gridGeneralCalib.Rows.Add(f.Name, f.GetValue(tbl));
                }
            }
            catch (Exception ex)
            {
                log.Error("Could not open the selected file!", ex);
            }
        }
Ejemplo n.º 2
0
        private void btnSetGeneralCalib_Click(object sender, EventArgs e)
        {
            GeneralCalibrationTable tbl = new GeneralCalibrationTable();

            foreach (DataGridViewRow row in gridGeneralCalib.Rows)
            {
                FieldInfo valueField = typeof(GeneralCalibrationTable).GetField(row.Cells["Key"].Value.ToString(), BindingFlags.Public | BindingFlags.Instance);
                valueField.SetValue(tbl, Convert.ToUInt16(row.Cells["Value"].Value));
            }

            Scenario.ScenarioResult r = new SingleMessageSingleDeviceScenario("Set General Calibration Data", new SetCalibrationTableMessage(tbl, CalibrationTable.TableType.General), true, false, device).run();
            if (r != null && r.result == Scenario.ScenarioResult.RunResult.Pass)
            {
                AckResponse resp = (AckResponse)r.resultObj;
                log.Info("got an ack response opcode: " + resp.opcode.ToString());
            }
        }
Ejemplo n.º 3
0
        private void btnGetGeneralCalibData_Click(object sender, EventArgs e)
        {
            Scenario.ScenarioResult r = new SingleMessageSingleDeviceScenario("Get General Calibration Data", new GetCalibrationTableMessage(CalibrationTable.TableType.General), true, false, device).run();
            if (r != null && r.result == Scenario.ScenarioResult.RunResult.Pass)
            {
                GetCalibrationTableResponse resp = (GetCalibrationTableResponse)r.resultObj;
                GeneralCalibrationTable     tbl  = (GeneralCalibrationTable)resp.table;

                try
                {
                    gridGeneralCalib.Rows.Clear();

                    FieldInfo[] fields = typeof(GeneralCalibrationTable).GetFields();
                    foreach (FieldInfo f in fields)
                    {
                        gridGeneralCalib.Rows.Add(f.Name, f.GetValue(tbl));
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Could not load calibration data!", ex);
                }
            }
        }
Ejemplo n.º 4
0
        private void btnSaveGeneralCalib_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.DefaultExt = "txt";
            sfd.Filter     = "Calibration Text File (*.json)|*.json|All files (*.*)|*.*";
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                log.Error("a file must be selected!");
                return;
            }

            GeneralCalibrationTable tbl = new GeneralCalibrationTable();

            foreach (DataGridViewRow r in gridGeneralCalib.Rows)
            {
                FieldInfo valueField = typeof(GeneralCalibrationTable).GetField(r.Cells["Key"].Value.ToString(), BindingFlags.Public | BindingFlags.Instance);
                valueField.SetValue(tbl, Convert.ToUInt16(r.Cells["Value"].Value));
            }

            String jsonString = JsonConvert.SerializeObject(tbl);

            File.WriteAllText(sfd.FileName, jsonString);
        }