Ejemplo n.º 1
0
 public bool ValidateExpression()
 {
     return(TestExpression.Validate(txtExpression.Text, settings));
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                int    linesStart = int.Parse(txtLinesStart.Text), linesEnd = int.Parse(txtLinesEnd.Text);
                double offlineStart = double.Parse(txtOfflineStart.Text), offlineEnd = double.Parse(txtOfflineEnd.Text);
                double offlineStart2 = double.Parse(txtOfflineStart2.Text), offlineEnd2 = double.Parse(txtOfflineEnd2.Text);
                var    poff = int.Parse(txtPowerOffPin.Text);
                double
                    zerol = double.Parse(txtZeroToleranceLow.Text),
                    zeroh = double.Parse(txtZeroToleranceHigh.Text);
                double
                    h_from = chkHumidity.Checked ? double.Parse(txtHumidityFrom.Text) : 0,
                    h_to   = chkHumidity.Checked ? double.Parse(txtHumidityTo.Text) : 0,
                    t_from = chkTemp.Checked ? double.Parse(txtTempFrom.Text) : 0,
                    t_to   = chkTemp.Checked ? double.Parse(txtTempTo.Text) : 0;
                int h_pin  = chkHumidity.Checked ? int.Parse(txtHumidityPin.Text) : 0,
                    t_pin  = chkTemp.Checked ? int.Parse(txtTempPin.Text) : 0;
                double
                    ai1_from   = chkAI1.Checked ? double.Parse(txtAI1From.Text) : 0,
                    ai2_from   = chkAI2.Checked ? double.Parse(txtAI2From.Text) : 0,
                    ai3_from   = chkAI3.Checked ? double.Parse(txtAI3From.Text) : 0,
                    ai4_from   = chkAI4.Checked ? double.Parse(txtAI4From.Text) : 0,
                    ai1_to     = chkAI1.Checked ? double.Parse(txtAI1To.Text) : 0,
                    ai2_to     = chkAI2.Checked ? double.Parse(txtAI2To.Text) : 0,
                    ai3_to     = chkAI3.Checked ? double.Parse(txtAI3To.Text) : 0,
                    ai4_to     = chkAI4.Checked ? double.Parse(txtAI4To.Text) : 0;
                int ai1_pin    = chkAI1.Checked ? int.Parse(txtAI1Pin.Text) : 0,
                    ai2_pin    = chkAI2.Checked ? int.Parse(txtAI2Pin.Text) : 0,
                    ai3_pin    = chkAI3.Checked ? int.Parse(txtAI3Pin.Text) : 0,
                    ai4_pin    = chkAI4.Checked ? int.Parse(txtAI4Pin.Text) : 0;
                var countercap = double.Parse(txtCounterChangeCap.Text);

                if (linesEnd < linesStart || offlineEnd < offlineStart || offlineEnd2 < offlineStart2 ||
                    !LJ.ValidPin(poff) || (chkHumidity.Checked && !LJ.ValidPinAny(h_pin)) ||
                    (chkTemp.Checked && !LJ.ValidPinAny(t_pin)))
                {
                    throw new Exception();
                }

                settings.Payload.OfflineRange         = new Pair <int, int>((int)(offlineStart * 1000.0), (int)(offlineEnd * 1000.0));
                settings.Payload.OfflineLineProcRange = new Pair <int, int>(linesStart, linesEnd);
                settings.Payload.OfflineRange2        = new Pair <int, int>((int)(offlineStart2 * 1000.0), (int)(offlineEnd2 * 1000.0));
                settings.Payload.PowerOffPin          = poff;
                settings.Payload.ZeroToleranceLow     = zerol;
                settings.Payload.ZeroToleranceHigh    = zeroh;
                settings.Payload.ReverseDirection     = chkReverseDirection.Checked;

                settings.Payload.LastCounterChangeMovementCap = countercap * 1000.0;

                settings.Payload.Priorities = new List <Settings.PayloadClass.Priority>(
                    lstPriorities.Items.Cast <Settings.PayloadClass.Priority>());
                settings.Payload.TestSets = new List <Settings.PayloadClass.TestSet>(
                    lstTestSets.Items.Cast <Settings.PayloadClass.TestSet>());

                settings.Payload.StopOnErrors = chkStopOnErrors.Checked;

                if (chkUseCycles.Checked && !TestExpression.Validate(txtCycleCondition.Text, settings))
                {
                    throw new Exception();
                }

                settings.Payload.UseCycles      = chkUseCycles.Checked;
                settings.Payload.CycleCondition = new TestExpression(txtCycleCondition.Text);
                settings.Payload.StopAtCycles   = chkStopAtCycles.Checked ?
                                                  (int?)int.Parse(txtStopAtCycles.Text) : null;
                settings.Payload.ClockOutputChannel = chkOutputTick.Checked ?
                                                      (int?)int.Parse((cmbOutputTickChannel.SelectedItem as string).Substring(1)) - 1 : null;
                settings.Payload.TestPilotLightPin = chkTestPilotPin.Checked ?
                                                     (int?)int.Parse((cmbTestPilotPin.SelectedItem as string).Substring(1)) - 1 : null;
                settings.Payload.WaitBeforeAnalogChanges = chkWaitBetweenAnalogChanges.Checked ?
                                                           (int?)((int)(double.Parse(txtWaitBetweenAnalogChanges.Text) * 1000.0f)) : null;

                settings.Payload.Links = new SerializableDictionary <int, int>();
                foreach (string s in lstLinks.Items)
                {
                    var vals = s.Split(new string[] { " -> " }, StringSplitOptions.None);
                    settings.Payload.Links.Add(int.Parse(vals[0].Substring(1)) - 1,
                                               int.Parse(vals[1].Substring(1)) - 1);
                }

                settings.Payload.Hysteresis = new SerializableDictionary <Settings.PayloadClass.HysteresisKind, Settings.PayloadClass.HysteresisPayload>();
                if (chkTemp.Checked)
                {
                    settings.Payload.Hysteresis.Add(Settings.PayloadClass.HysteresisKind.Temperature,
                                                    new Settings.PayloadClass.HysteresisPayload()
                    {
                        From  = t_from,
                        To    = t_to,
                        PinID = t_pin
                    });
                }
                if (chkHumidity.Checked)
                {
                    settings.Payload.Hysteresis.Add(Settings.PayloadClass.HysteresisKind.Humidity,
                                                    new Settings.PayloadClass.HysteresisPayload()
                    {
                        From  = h_from,
                        To    = h_to,
                        PinID = h_pin
                    });
                }
                settings.Payload.HysteresisAI = new SerializableDictionary <int, Settings.PayloadClass.HysteresisPayload>();
                if (chkAI1.Checked)
                {
                    settings.Payload.HysteresisAI.Add(1, new Settings.PayloadClass.HysteresisPayload()
                    {
                        From  = ai1_from,
                        To    = ai1_to,
                        PinID = ai1_pin
                    });
                }
                if (chkAI2.Checked)
                {
                    settings.Payload.HysteresisAI.Add(2, new Settings.PayloadClass.HysteresisPayload()
                    {
                        From  = ai2_from,
                        To    = ai2_to,
                        PinID = ai2_pin
                    });
                }
                if (chkAI3.Checked)
                {
                    settings.Payload.HysteresisAI.Add(3, new Settings.PayloadClass.HysteresisPayload()
                    {
                        From  = ai3_from,
                        To    = ai3_to,
                        PinID = ai3_pin
                    });
                }
                if (chkAI4.Checked)
                {
                    settings.Payload.HysteresisAI.Add(4, new Settings.PayloadClass.HysteresisPayload()
                    {
                        From  = ai4_from,
                        To    = ai4_to,
                        PinID = ai4_pin
                    });
                }

                settings.Payload.DriveMotor = chkDriveMotor.Checked;

                DialogResult = DialogResult.OK;
                Close();
            }
            catch
            {
                MessageBox.Show("Invalid input. Please check that the ranges are actual numbers " +
                                "and that the starts are happening before the ends.", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
 public TestSet()
 {
     Condition = new TestExpression();
     Result    = new TestExpression();
 }
Ejemplo n.º 4
0
 public Priority()
 {
     Condition     = new TestExpression();
     ExitCondition = new TestExpression();
     PriorityOrder = new List <Pair <int, PriorityState> >();
 }
Ejemplo n.º 5
0
 public ActionWaitForCondition()
 {
     Condition = new TestExpression();
 }
Ejemplo n.º 6
0
 public TestSet()
 {
     Condition = new TestExpression();
 }
Ejemplo n.º 7
0
 public Priority()
 {
     Condition = new TestExpression();
     ExitCondition = new TestExpression();
     PriorityOrder = new List<Pair<int, PriorityState>>();
 }