/// <summary>
        /// Returns the formated string to pass to the speech engine
        /// </summary>
        /// <returns></returns>
        public string DisplayText()
        {
            if (Name == "PARAM")
            {
                var valuep = HandleParam();

                var answer = Convert.ToDouble(valuep);

                return
                    Text.Replace("{trigger}", TriggerValue.ToString("0.##"))
                        .Replace("{value}", answer.ToString("0.##"));
            }

            if (Item == null)
                return "";

            var value = GetValueObject;

            if (Item.PropertyType.Name == "Single" || Item.PropertyType.Name == "Double")
            {
                var answer = Convert.ToDouble(value);

                return
                    Text.Replace("{trigger}", TriggerValue.ToString("0.##"))
                        .Replace("{value}", answer.ToString("0.##"))
                        .Replace("{name}", Item.Name);
            }
            else
            {
                return Text.Replace("{trigger}", TriggerValue.ToString("0.##"))
                        .Replace("{value}", value.ToString())
                        .Replace("{name}", Item.Name);
            }
        }
Пример #2
0
        private bool ValidateVar(TriggerValue val)
        {
            if (val.Name == "")
            {
                if (mVarSearch.SearchConstants == false)
                {
                    return(false);
                }
            }
            if (mVarSearch.Name != null && mVarSearch.Name != "")
            {
                if (val.Name.Contains(mVarSearch.Name) == false)
                {
                    return(false);
                }
            }
            if (mVarSearch.Type != null && mVarSearch.Type != "")
            {
                if (val.Type != mVarSearch.Type)
                {
                    return(false);
                }
            }
            //if (mVarSearch.Group != null && mVarSearch.Group != "")
            //{
            //   if(val.

            //}
            return(true);
        }
Пример #3
0
        void CellEditorManager_ActivatingControl(object sender, Xceed.Grid.Editors.CellEditorEventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
            //gridControl1.get

            int id = (int)(e.Cell.ParentRow.Cells["ID"].Value);
            //e.Control.Tag = o;

            TriggerValue      val    = mParentTriggerNamespace.GetValues()[id];
            VarValueBinder    binder = new VarValueBinder(val, val);
            HighLevelProperty HLProp = TriggerSystemMain.mTriggerDefinitions.GetHLProperty(binder, mParentTriggerNamespace);
            string            bindName;
            Control           c = HLProp.GetEditor(out bindName);

            Form f = new Form();

            f.Controls.Add(c);
            c.Dock     = DockStyle.Fill;
            f.Location = (new Point(0, 0));
            f.Text     = binder.GetName();
            f.Show();

            //e.Cell. = c;
            //e.Control = c;
        }
Пример #4
0
        /// <summary>
        /// Returns the formated string to pass to the speech engine
        /// </summary>
        /// <returns></returns>
        public string DisplayText()
        {
            if (Item == null)
            {
                return("");
            }

            var value = GetValueObject;

            if (Item.PropertyType.Name == "Single" || Item.PropertyType.Name == "Double")
            {
                var answer = Convert.ToDouble(value);

                return
                    (Text.Replace("{trigger}", TriggerValue.ToString("0.##"))
                     .Replace("{value}", answer.ToString("0.##"))
                     .Replace("{name}", Item.Name));
            }
            else
            {
                return(Text.Replace("{trigger}", TriggerValue.ToString("0.##"))
                       .Replace("{value}", value.ToString())
                       .Replace("{name}", Item.Name));
            }
        }
Пример #5
0
        void VarSearchGridControl_SelectedRowsChanged(object sender, EventArgs e)
        {
            if (mbPaused)
            {
                return;
            }
            if (VarSearchGridControl.SelectedRows.Count > 0)
            {
                Xceed.Grid.DataRow row = VarSearchGridControl.SelectedRows[0] as Xceed.Grid.DataRow;
                if (row != null)
                {
                    TriggerVarJump jump = ((TriggerVarJump)row.SourceObject);

                    if (jump.map != null)
                    {
                        mHostArea.SnapViewToItem(jump.map);
                    }
                    else
                    {
                        mHostArea.SnapViewToItem(jump.comp);
                        TriggerValue val = mHostArea.CurrentTriggerNamespace.GetValues()[jump.var.ID];
                        mHostArea.UIUpdate(val, new BasicArgument(BasicArgument.eArgumentType.Select), eUpdateVisibilty.AnyVisiblity);
                    }
                }
            }
            //throw new Exception("The method or operation is not implemented.");
        }
Пример #6
0
        private void TextLabel_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.None;
            if (e.Data.GetDataPresent(typeof(TriggerParameterControl)))
            {
                object data = e.Data.GetData(typeof(TriggerParameterControl));
                TriggerParameterControl otherButton = data as TriggerParameterControl;
                if (otherButton != null)
                {
                    TriggerValue ctrlMove   = otherButton.mValue as TriggerValue;
                    TriggerValue ctrlTarget = this.mValue as TriggerValue;

                    if (ctrlMove.Type == ctrlTarget.Type)
                    {
                        e.Effect = DragDropEffects.Move;
                    }

                    if ((otherButton.ParameterMode == eParameterMode.Const) &&
                        (TriggerSystemMain.mTriggerDefinitions.CanConvertConst(ctrlMove.Type, ctrlTarget.Type)))
                    {
                        e.Effect = DragDropEffects.Link;
                    }
                }
            }
        }
Пример #7
0
        public void Init(TriggerParameterControl parent, TriggerVariable var, TriggerValue val, HighLevelProperty HLProp)
        {
            this.Text = var.Name + " : " + val.Type;

            mVariable = var;
            mValue    = val;
            mParent   = parent;
            mHLProp   = HLProp;

            UpdateControl();

            //save teh mouseclicks.
            if (mValue.Name.Contains((mVariable.Name + TriggerNamespace.GetDefaultVarSuffix())))
            {
                if (TriggerSystemMain.mTriggerDefinitions.IsListType(mValue.Type))
                {
                    mValue.IsNull = false;
                    ////mParent.ParameterMode = TriggerParameterControl.eParameterMode.
                    UpdateControl();
                    InitVarMode();
                }
                else if (parent.ParentTriggerNamespace.IsSharedValueVar(mValue.ID))
                {
                    //SetValueMode();
                }
                else
                {
                    //InitValueMode();
                    SetValueMode();
                }
            }
        }
Пример #8
0
 void SetValueMode()
 {
     //mParent.ParentTriggerNamespace.SwitchVarToConstant(mVariable, ref mValue);
     //mParent.ParameterMode = TriggerParameterControl.eParameterMode.Const;
     mValue = mParent.SetValueMode();
     InitValueMode();
     //UpdateControl();
 }
Пример #9
0
        void SetVariableMode(int newValueID)
        {
            mValue = mParent.SetVarMode(newValueID);
            //UpdateControl();
            InitVarMode();

            //mParent.ParameterMode = TriggerParameterControl.eParameterMode.LocalVariable;
            //UpdateControl();
        }
Пример #10
0
        public void Init(TriggerComponent comp, TriggerVariable var, TriggerValue val, TriggerNamespace trigNS)//, Trigger trigger)
        {
            mComponent = comp;
            mVariable  = var;
            mValue     = val;

            ParentTriggerNamespace = trigNS;
            //Trigger = trigger;

            InitHLProp();

            UpdateControl();
        }
Пример #11
0
        internal bool IsValid(Object currentValue)
        {
            var result = false;

            if (TriggerArrayValue == null)
            {
                switch (TriggerType)
                {
                case TriggerTypes.Status:
                    result = TriggerValue.Equals(currentValue);
                    break;

                case TriggerTypes.ChangeFrom:
                    result        = (TriggerValue.Equals(PreviousValue) && !TriggerValue.Equals(currentValue));
                    PreviousValue = currentValue;
                    break;

                case TriggerTypes.ChangeTo:
                    result        = (!TriggerValue.Equals(PreviousValue) && TriggerValue.Equals(currentValue));
                    PreviousValue = currentValue;
                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (TriggerType)
                {
                case TriggerTypes.Status:
                    result = TriggerArrayValue.SequenceEqualWithNull(currentValue);
                    break;

                case TriggerTypes.ChangeFrom:
                    result        = (TriggerArrayValue.SequenceEqualWithNull(PreviousValue) && !TriggerArrayValue.SequenceEqualWithNull(currentValue));
                    PreviousValue = currentValue;
                    break;

                case TriggerTypes.ChangeTo:
                    result        = (!TriggerArrayValue.SequenceEqualWithNull(PreviousValue) && TriggerArrayValue.SequenceEqualWithNull(currentValue));
                    PreviousValue = currentValue;
                    break;

                default:
                    break;
                }
            }
            return(result);
        }
Пример #12
0
        void cell_Click(object sender, EventArgs e)
        {
            Xceed.Grid.DataCell cell = sender as Xceed.Grid.DataCell;

            int id = (int)(cell.ParentRow.Cells["ID"].Value);

            if (mEditorforms.ContainsKey(id))
            {
                mEditorforms[id].BringToFront();
            }
            else
            {
                TriggerValue      val    = mParentTriggerNamespace.GetValues()[id];
                VarValueBinder    binder = new VarValueBinder(val, val);
                HighLevelProperty HLProp = TriggerSystemMain.mTriggerDefinitions.GetHLProperty(binder, mParentTriggerNamespace);
                string            bindName;
                Control           c = HLProp.GetEditor(out bindName);
                //this.TemplateControl = c;
                //this.TemplateControl

                Form f = new Form();


                f.Tag = id;


                f.Controls.Add(c);
                c.Dock = DockStyle.Fill;
                f.Text = binder.GetName();
                //f.TopLevelControl = true;
                f.Size = new Size(200, 55);

                Point p1 = new Point(0, 0);
                Point p2 = cell.PointToScreen(p1);
                f.StartPosition = FormStartPosition.Manual;
                p2.Y           -= 30;
                p2.X           -= 60;
                f.Location      = p2;
                //f.Init(this, mVariable, mValue, mHLProp);
                //f.FormClosed += new FormClosedEventHandler(f_FormClosed);
                //f.Show();
                f.FormClosed += new FormClosedEventHandler(f_FormClosed);

                f.TopMost = true;
                f.Show();

                mEditorforms[id] = f;
            }
        }
Пример #13
0
        internal DataPackageScope(
            Type scopeType,
            uint acquiredSamples, double acqSamplePeriod,
            int viewportSamples, Int64 viewportOffsetSamples,
            double holdoff, Int64 holdoffSamples, bool rolling, int identifier, TriggerValue triggerValue,
            double viewportExcess = 0)
        {
            this.TriggerValue       = triggerValue.Copy();
            this.LastDataUpdate     = DateTime.Now;
            this.ScopeType          = scopeType;
            this.Identifier         = identifier;
            this.AcquisitionSamples = acquiredSamples;

            this.ViewportSamples       = viewportSamples;
            this.ViewportExcess        = viewportExcess;
            this.ViewportOffsetSamples = viewportOffsetSamples;

            samplePeriod = new Dictionary <ChannelDataSource, double>()
            {
                { ChannelDataSourceScope.Acquisition, acqSamplePeriod },
                { ChannelDataSourceScope.Overview, acquiredSamples / OVERVIEW_SAMPLES * acqSamplePeriod },
            };

            offset = new Dictionary <ChannelDataSource, double>()
            {
                { ChannelDataSourceScope.Acquisition, 0 },
                { ChannelDataSourceScope.Overview, 0 },
            };

            this.Holdoff        = holdoff;
            this.Rolling        = rolling;
            this.HoldoffSamples = holdoffSamples;

            data = new Dictionary <ChannelDataSourceScope, Dictionary <Channel, ChannelData> >();
            foreach (ChannelDataSourceScope t in ChannelDataSourceScope.List)
            {
                data[t] = new Dictionary <Channel, ChannelData>();
            }

            Settings   = new Dictionary <string, double>();
            Resolution = new Dictionary <AnalogChannel, float>()
            {
                { AnalogChannel.ChA, float.PositiveInfinity },
                { AnalogChannel.ChB, float.PositiveInfinity },
            };
        }
Пример #14
0
        public TriggerValue SetVarMode(int newValueID)
        {
            //ParentTriggerNamespace.SwitchConstantToVar(mVariable, ref mValue);
            //newValueID
            //mVariable.ID = newValueID;

            //mValue = ParentTriggerNamespace.GetValues()[newValueID];

            //ParentTriggerNamespace.AssignValueToVar(mVariable, mValue);

            mValue        = ParentTriggerNamespace.AssignValueToVar(mVariable, newValueID);
            mValue.IsNull = false;

            mBinder.UpdateValue(mValue);
            //UpdateControl();
            return(mValue);
        }
Пример #15
0
    public override void Start()
    {
        foreach (Transform child in Owner.transform)
        {
            if (child.CompareTag("BulletSpawner"))
            {
                _bulletSpawners.Add(child);
                _timerBulletTrigger.Add(new TriggerValue(ParamBetweenBullet.Value));
                AddTrigger(_timerBulletTrigger.Last());
            }
        }

        // init timer between shoot
        _timerShoot = new TriggerValue(ParamBetweenShoot.Value);

        AddTrigger(_timerShoot);
        base.Start();
    }
        static StateValue GetStateValue(ParameterType type, TriggerValue triggerValue, StateValue signal)
        {
            switch (type)
            {
            case ParameterType.Signal:
                return(signal);

            case ParameterType.Bool:
                return(new StateValue(triggerValue.BoolValue));

            case ParameterType.Integer:
                return(new StateValue(triggerValue.IntegerValue));

            case ParameterType.Float:
                return(new StateValue(triggerValue.FloatValue));

            default:
                throw new NotImplementedException();
            }
        }
Пример #17
0
        GimmickValue GetGimmickValue(ParameterType type, TriggerValue triggerValue)
        {
            switch (type)
            {
            case ParameterType.Signal:
                return(new GimmickValue(DateTime.Now));

            case ParameterType.Bool:
                return(new GimmickValue(triggerValue.BoolValue));

            case ParameterType.Integer:
                return(new GimmickValue(triggerValue.IntegerValue));

            case ParameterType.Float:
                return(new GimmickValue(triggerValue.FloatValue));

            default:
                throw new NotImplementedException();
            }
        }
Пример #18
0
        public void UIUpdate(object data, object arguments, eUpdateVisibilty visiblity, ref List <Control> owners)
        {
            TriggerValue trigerValue = data as TriggerValue;

            if (trigerValue != null)
            {
                foreach (Control c in VarInHardPointsBar.GetLogicalControls())
                {
                    ITriggerUIUpdate ui = c as ITriggerUIUpdate;
                    if (ui != null)
                    {
                        ui.UIUpdate(data, arguments, visiblity, ref owners);
                    }
                }
                foreach (Control c in VarOutHardPointsBar.GetLogicalControls())
                {
                    ITriggerUIUpdate ui = c as ITriggerUIUpdate;
                    if (ui != null)
                    {
                        ui.UIUpdate(data, arguments, visiblity, ref owners);
                    }
                }
            }


            BasicArgument ba = arguments as BasicArgument;

            if (data == null)
            {
            }
            else if ((data == this.TriggerTemplateMapping) && (ba != null))
            {
                if (ba.mArgument == BasicArgument.eArgumentType.Search)
                {
                    owners.Add(this);
                }
            }

            //throw new Exception("The method or operation is not implemented.");
        }
Пример #19
0
        private void PopupEditor()
        {
            if (mbOpen == true)
            {
                return; //haha
            }
            mBackupValue = this.mValue.GetCopy();
            mBackupVar   = this.mVariable.GetCopy();

            mbOpen = true;

            TriggerPopupInputForm f = new TriggerPopupInputForm();
            Point p1 = new Point(0, 0);
            Point p2 = this.PointToScreen(p1);

            f.StartPosition = FormStartPosition.Manual;
            p2.Y           -= 30;
            p2.X           -= 60;
            f.Location      = p2;

            f.Init(this, mVariable, mValue, mHLProp);
            f.FormClosed += new FormClosedEventHandler(f_FormClosed);
            f.Show();
        }
Пример #20
0
        public static Dictionary <AnalogChannel, AnalogWaveProperties> MeasureAutoArrangeSettings(IScope scope, AnalogChannel aciveChannel, Action <float> progressReport)
        {
            float progress = 0f;

            progressReport(progress);

            //stop scope streaming
            scope.DataSourceScope.Stop();

            //Prepare scope for test
            if (scope is SmartScope)
            {
                (scope as SmartScope).SetDisableVoltageConversion(false);
            }

            //set to timerange wide enough to capture 50Hz, but slightly off so smallest chance of aliasing
            const float initialTimeRange = 0.0277f;

            scope.AcquisitionMode   = AcquisitionMode.AUTO;
            scope.AcquisitionLength = initialTimeRange;
            scope.SetViewPort(0, scope.AcquisitionLength);
            //s.AcquisitionDepth = 4096;
            scope.TriggerHoldOff     = 0;
            scope.SendOverviewBuffer = false;

            TriggerValue trigger = new TriggerValue()
            {
                mode    = TriggerMode.Edge,
                source  = TriggerSource.Channel,
                channel = AnalogChannel.ChA,
                edge    = TriggerEdge.RISING,
                level   = 5000,
            };

            scope.TriggerValue = trigger;

            foreach (AnalogChannel ch in AnalogChannel.List)
            {
                scope.SetCoupling(ch, Coupling.DC);
            }

            scope.CommitSettings();
            progress += .1f;
            progressReport(progress);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // VERTICAL == VOLTAGE

            //set to largest input range
            float maxRange = 1.2f / 1f * 36f;

            foreach (AnalogChannel ch in AnalogChannel.List)
            {
                scope.SetVerticalRange(ch, -maxRange / 2f, maxRange / 2f);
            }

            float[] minValues = new float[] { float.MaxValue, float.MaxValue };
            float[] maxValues = new float[] { float.MinValue, float.MinValue };
            //measure min and max voltage over 3 full ranges
            for (int i = -1; i < 2; i++)
            {
                progress += .1f;
                progressReport(progress);

                foreach (AnalogChannel ch in AnalogChannel.List)
                {
                    scope.SetYOffset(ch, (float)i * maxRange);
                }
                scope.CommitSettings();

                System.Threading.Thread.Sleep(100);
                scope.ForceTrigger();

                //fetch data
                DataPackageScope p = FetchLastFrame(scope);

                if (p == null)
                {
                    Logger.Error("Didn't receive data from scope, aborting");
                    return(null);
                }

                //check if min or max need to be updated (only in case this measurement was not saturated)
                float[] dataA = (float[])p.GetData(ChannelDataSourceScope.Viewport, AnalogChannel.ChA).array;
                float[] dataB = (float[])p.GetData(ChannelDataSourceScope.Viewport, AnalogChannel.ChB).array;
                float   minA  = dataA.Min();
                float   maxA  = dataA.Max();
                float   minB  = dataB.Min();
                float   maxB  = dataB.Max();

                if (minA != p.SaturationLowValue[AnalogChannel.ChA] && minA != p.SaturationHighValue[AnalogChannel.ChA] && minValues[0] > minA)
                {
                    minValues[0] = minA;
                }
                if (minB != p.SaturationLowValue[AnalogChannel.ChB] && minB != p.SaturationHighValue[AnalogChannel.ChB] && minValues[1] > minB)
                {
                    minValues[1] = minB;
                }
                if (maxA != p.SaturationLowValue[AnalogChannel.ChA] && maxA != p.SaturationHighValue[AnalogChannel.ChA] && maxValues[0] < maxA)
                {
                    maxValues[0] = maxA;
                }
                if (maxB != p.SaturationLowValue[AnalogChannel.ChB] && maxB != p.SaturationHighValue[AnalogChannel.ChB] && maxValues[1] < maxB)
                {
                    maxValues[1] = maxB;
                }
            }

            //calc ideal voltage range and offset
            float sizer = 3; //meaning 3 waves would fill entire view

            float[] coarseAmplitudes = new float[2];
            coarseAmplitudes[0] = maxValues[0] - minValues[0];
            coarseAmplitudes[1] = maxValues[1] - minValues[1];
            float[] desiredOffsets = new float[2];
            desiredOffsets[0] = (maxValues[0] + minValues[0]) / 2f;
            desiredOffsets[1] = (maxValues[1] + minValues[1]) / 2f;
            float[] desiredRanges = new float[2];
            desiredRanges[0] = coarseAmplitudes[0] * sizer;
            desiredRanges[1] = coarseAmplitudes[1] * sizer;

            //intervene in case the offset is out of range for this range
            if (desiredRanges[0] < Math.Abs(desiredOffsets[0]))
            {
                desiredRanges[0] = Math.Abs(desiredOffsets[0]);
            }
            if (desiredRanges[1] < Math.Abs(desiredOffsets[1]))
            {
                desiredRanges[1] = Math.Abs(desiredOffsets[1]);
            }

            //set fine voltage range and offset
            scope.SetVerticalRange(AnalogChannel.ChA, -desiredRanges[0] / 2f, desiredRanges[0] / 2f);
            scope.SetYOffset(AnalogChannel.ChA, -desiredOffsets[0]);
            scope.SetVerticalRange(AnalogChannel.ChB, -desiredRanges[1] / 2f, desiredRanges[1] / 2f);
            scope.SetYOffset(AnalogChannel.ChB, -desiredOffsets[1]);
            scope.CommitSettings();

            System.Threading.Thread.Sleep(100);
            scope.ForceTrigger();

            //now get data in order to find accurate lowHigh levels (as in coarse mode this was not accurate)
            DataPackageScope pFine = FetchLastFrame(scope);

            Dictionary <AnalogChannel, float[]> dataFine = new Dictionary <AnalogChannel, float[]>();

            dataFine.Add(AnalogChannel.ChA, (float[])pFine.GetData(ChannelDataSourceScope.Viewport, AnalogChannel.ChA).array);
            dataFine.Add(AnalogChannel.ChB, (float[])pFine.GetData(ChannelDataSourceScope.Viewport, AnalogChannel.ChB).array);

            Dictionary <AnalogChannel, float> minimumValues = new Dictionary <AnalogChannel, float>();
            Dictionary <AnalogChannel, float> maximumValues = new Dictionary <AnalogChannel, float>();
            Dictionary <AnalogChannel, float> amplitudes    = new Dictionary <AnalogChannel, float>();
            Dictionary <AnalogChannel, float> offsets       = new Dictionary <AnalogChannel, float>();
            Dictionary <AnalogChannel, bool>  isFlatline    = new Dictionary <AnalogChannel, bool>();

            foreach (var kvp in dataFine)
            {
                minimumValues.Add(kvp.Key, kvp.Value.Min());
                maximumValues.Add(kvp.Key, kvp.Value.Max());
                amplitudes.Add(kvp.Key, kvp.Value.Max() - kvp.Value.Min());
                offsets.Add(kvp.Key, (kvp.Value.Max() + kvp.Value.Min()) / 2f);
                isFlatline.Add(kvp.Key, amplitudes[kvp.Key] < 0.01f);
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // HORIZONTAL == FREQUENCY

            const float minTimeRange = 500f * 0.00000001f;//500 samples over full hor span
            const float maxTimeRange = 1f;

            double frequency, frequencyError, dutyCycle, dutyCycleError;
            Dictionary <AnalogChannel, double> finalFrequencies = new Dictionary <AnalogChannel, double>();

            finalFrequencies.Add(AnalogChannel.ChA, double.MaxValue);
            finalFrequencies.Add(AnalogChannel.ChB, double.MaxValue);
            int   iterationCounter = 0; //only for performance testing
            float currTimeRange    = minTimeRange;
            bool  continueLooping  = true;

            if (isFlatline.Where(x => x.Value).ToList().Count == isFlatline.Count) //no need to find frequency in case of 2 DC signals
            {
                continueLooping = false;
            }
            int remeasureCounter = 0; // in case of spikes, we try to remeasure until captured. But slow sines can cause this to go wild

            while (continueLooping)
            {
                progress += .04f;
                progressReport(progress);

                iterationCounter++;     //only for performance testing

                scope.AcquisitionLength = currTimeRange;
                scope.SetViewPort(0, scope.AcquisitionLength);
                scope.CommitSettings();

                System.Threading.Thread.Sleep(100);
                scope.ForceTrigger();

                DataPackageScope pHor = FetchLastFrame(scope);
                Dictionary <AnalogChannel, float[]> timeData = new Dictionary <AnalogChannel, float[]>();
                timeData.Add(AnalogChannel.ChA, (float[])pHor.GetData(ChannelDataSourceScope.Viewport, AnalogChannel.ChA).array);
                timeData.Add(AnalogChannel.ChB, (float[])pHor.GetData(ChannelDataSourceScope.Viewport, AnalogChannel.ChB).array);

                bool notCapturedFullAmplitude = false;
                foreach (var kvp in timeData)
                {
                    //make sure entire amplitude is in view
                    float currMinVal      = kvp.Value.Min();
                    float currMaxVal      = kvp.Value.Max();
                    float lowMarginValue  = minimumValues[kvp.Key] + amplitudes[kvp.Key] * 0.1f;
                    float highMarginValue = maximumValues[kvp.Key] - amplitudes[kvp.Key] * 0.1f;
                    if (currMinVal > lowMarginValue || currMaxVal < highMarginValue)
                    {
                        notCapturedFullAmplitude = true;
                        continue;
                    }

                    Dictionary <int, bool> risingNFallingEdges;
                    ComputeFrequencyDutyCycle(pHor.GetData(ChannelDataSourceScope.Viewport, kvp.Key), out frequency, out frequencyError, out dutyCycle, out dutyCycleError, out risingNFallingEdges, currMinVal, currMaxVal);
                    if (!double.IsNaN(frequency) && (finalFrequencies[kvp.Key] == double.MaxValue))
                    {
                        finalFrequencies[kvp.Key] = frequency;
                    }
                }

                if (notCapturedFullAmplitude && remeasureCounter++ < 5)
                {
                    //need to re-measure, so don't increment
                }
                else
                {
                    remeasureCounter = 0;
                    //update and check whether we've found what we were looking for
                    currTimeRange *= 100f;
                    bool freqFoundForAllActiveWaves = true;
                    foreach (var kvp in timeData)
                    {
                        if (!isFlatline[kvp.Key] && finalFrequencies[kvp.Key] == double.MaxValue)
                        {
                            freqFoundForAllActiveWaves = false;
                        }
                    }
                    continueLooping = !freqFoundForAllActiveWaves;
                    if (currTimeRange > maxTimeRange)
                    {
                        continueLooping = false;
                    }
                }
            }

            //in case of flatline or very low freq, initial value will not have changed
            foreach (AnalogChannel ch in finalFrequencies.Keys.ToList())
            {
                if (finalFrequencies[ch] == double.MaxValue)
                {
                    finalFrequencies[ch] = 0;
                }
            }

            Dictionary <AnalogChannel, AnalogWaveProperties> waveProperties = new Dictionary <AnalogChannel, AnalogWaveProperties>();

            foreach (var kvp in isFlatline)
            {
                waveProperties.Add(kvp.Key, new AnalogWaveProperties(minimumValues[kvp.Key], maximumValues[kvp.Key], amplitudes[kvp.Key], offsets[kvp.Key], isFlatline[kvp.Key], finalFrequencies[kvp.Key]));
            }

            return(waveProperties);
        }
        public void Post(TriggerValue v)
        {
            string file = System.Web.HttpContext.Current.Server.MapPath("~/data/data.txt");

            System.IO.File.WriteAllText(file, v.trigger);
        }
Пример #22
0
        void mTriggerOutControlPoint_ControlPointRemoved(BasicControlPoint cp, IControlPoint other)
        {
            TriggerControl otherctrl = other.TagObject as TriggerControl;

            if (otherctrl != null)
            {
                bool          onfalse  = (cp.GetName() == "Effect.False") ? true : false;
                TriggerEffect toremove = null;

                if (onfalse == false)
                {
                    foreach (TriggerEffect effect in Trigger.TriggerEffects.Effects)
                    {
                        if ((effect.Type == TriggerSystemMain.mTriggerDefinitions.GetDeactivateEffectName()) ||
                            (effect.Type == TriggerSystemMain.mTriggerDefinitions.GetActivateEffectName()))
                        {
                            TriggerValue val = ParentTriggerNamespace.GetValues()[effect.Parameter[0].ID];
                            if (val.Value == otherctrl.Trigger.ID.ToString())
                            {
                                toremove = effect;
                            }
                        }
                    }
                }
                if (onfalse == true)
                {
                    foreach (TriggerEffect effect in Trigger.TriggerEffectsFalse.Effects)
                    {
                        if ((effect.Type == TriggerSystemMain.mTriggerDefinitions.GetDeactivateEffectName()) ||
                            (effect.Type == TriggerSystemMain.mTriggerDefinitions.GetActivateEffectName()))
                        {
                            TriggerValue val = ParentTriggerNamespace.GetValues()[effect.Parameter[0].ID];
                            if (val.Value == otherctrl.Trigger.ID.ToString())
                            {
                                toremove = effect;
                            }
                        }
                    }
                }
                if (toremove != null)
                {
                    ParentTriggerNamespace.DeleteEffect(Trigger, toremove, onfalse);
                }
            }

            TemplateControl templateControl = other.TagObject as TemplateControl;

            if (templateControl != null)
            {
                string            name    = other.ToString();
                BasicControlPoint othercp = other as BasicControlPoint;
                TriggersTemplateInputActionBinder targetBinder = templateControl.mInputActionCPs[othercp];
                TriggerBindInfo toremove = null;
                string          linkName = cp.Name;
                int             linkID   = this.Trigger.ID;

                foreach (TriggerBindInfo b in targetBinder.TargetIDs)
                {
                    if ((b.LinkName == linkName) && (b.ID == linkID))
                    {
                        toremove = b;
                    }
                }
                if (toremove != null)
                {
                    targetBinder.TargetIDs.Remove(toremove);
                }
                else
                {
                    CoreGlobals.getErrorManager().LogErrorToNetwork("mTriggerOutControlPoint_ControlPointRemoved: error deleting template link");
                }
            }
        }
Пример #23
0
 void SetNullMode()
 {
     mValue = mParent.SetNullMode();
     InitNullMode();
 }
Пример #24
0
        public Control BuildUIFromConditionVariable(TriggerComponent comp, TriggerVariable var, TriggerValue val, bool watchForChange)
        {
            TriggerParameterControl c = new TriggerParameterControl();

            c.Init(comp, var, val, ParentTriggerNamespace);//, Trigger);

            c.HotSelect    += new EventHandler(c_HotSelect);
            c.HotSelectEnd += new EventHandler(c_HotSelectEnd);

            if (watchForChange)
            {
                c.LabelChanged += new EventHandler(c_LabelChanged);
            }

            return(c);
        }
Пример #25
0
        internal void RuleTrigger(string tVal, bool bForce = false)
        {
            MyBaseThing.Value = tVal;
            switch (TriggerCondition)
            {
            case eRuleTrigger.Not:
                if (!TriggerValue.Equals(tVal, StringComparison.OrdinalIgnoreCase))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.Larger:
                if (TheCommonUtils.CDbl(TriggerValue) < TheCommonUtils.CDbl(tVal) && TheCommonUtils.CDbl(TriggerValue) >= TheCommonUtils.CDbl(TriggerOldValue))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.Smaller:
                if (TheCommonUtils.CDbl(TriggerValue) > TheCommonUtils.CDbl(tVal) && TheCommonUtils.CDbl(TriggerValue) <= TheCommonUtils.CDbl(TriggerOldValue))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.Contains:
                if (tVal.ToLower().Contains(TriggerValue.ToLower()))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.StartsWith:
                if (tVal.StartsWith(TriggerValue, StringComparison.OrdinalIgnoreCase))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.EndsWith:
                if (tVal.EndsWith(TriggerValue, StringComparison.OrdinalIgnoreCase))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.Set:
                if (!string.IsNullOrEmpty(TriggerValue))
                {
                    string expression = tVal + TriggerValue;
                    ActionValue = Evaluate(expression).ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    ActionValue = tVal;
                }
                FireAction(bForce);
                break;

            case eRuleTrigger.Equals:
                if (TriggerValue.Equals(tVal, StringComparison.OrdinalIgnoreCase))
                {
                    FireAction(bForce);
                }
                break;

            case eRuleTrigger.Fire:
                FireAction(bForce);
                break;

            case eRuleTrigger.Flank:
                if (TheCommonUtils.IsNullOrWhiteSpace(TriggerValue))
                {
                    if (!TriggerOldValue.Equals(tVal, StringComparison.OrdinalIgnoreCase))
                    {
                        FireAction(bForce);
                    }
                    break;
                }
                string[] tTrigs = TriggerValue.Split(',');
                if (tTrigs.Length == 1)
                {
                    if (Math.Abs(TheCommonUtils.CDbl(TriggerValue) - TheCommonUtils.CDbl(tVal)) < double.Epsilon && Math.Abs(TheCommonUtils.CDbl(TriggerOldValue) - TheCommonUtils.CDbl(tVal)) > double.Epsilon)
                    {
                        FireAction(false);
                    }
                }
                else
                {
                    if (Math.Abs(TheCommonUtils.CDbl(tVal) - TheCommonUtils.CDbl(TriggerOldValue)) > Double.Epsilon &&
                        Math.Abs(TheCommonUtils.CDbl(TriggerOldValue) - TheCommonUtils.CDbl(tTrigs[0])) < double.Epsilon &&
                        Math.Abs(TheCommonUtils.CDbl(tVal) - TheCommonUtils.CDbl(tTrigs[1])) < Double.Epsilon)
                    {
                        FireAction(bForce);
                    }
                }
                break;

            case eRuleTrigger.State:
                if (TriggerOldValue.Equals(tVal, StringComparison.OrdinalIgnoreCase))
                {
                    FireAction(bForce);
                }
                break;
            }
            TriggerOldValue = tVal;
        }
Пример #26
0
        //Loads ui.  Creates values for the mappings if they do not exist
        private void LoadMappingUI(TriggerTemplateMapping mapping)
        {
            TriggerNameText.Text = Path.GetFileNameWithoutExtension(mapping.Name);

            foreach (TriggersTemplateInputVariable v in mapping.InputMappings)
            {
                TriggerParameterControl c   = new TriggerParameterControl();
                TriggerValue            val = new TriggerValue();

                if (mbDemoMode || (ParentTriggerNamespace.GetValues().ContainsKey(v.ID) == false) || (v.ID == -1))
                {
                    val.Name = v.Name;
                    val.Type = v.Type;
                    int newID = -1;
                    ParentTriggerNamespace.InsertValue(val, out newID);
                    v.ID = newID;

                    //this line set optional parmas to default off for newly placed templates
                    if (v.Optional == true)
                    {
                        val.IsNull = true;
                    }
                }
                else
                {
                    val = ParentTriggerNamespace.GetValues()[v.ID];
                }


                c.Init(null, v, val, ParentTriggerNamespace);

                VarInHardPointsBar.AddControl(c);
            }
            foreach (TriggersTemplateOutputVariable v in mapping.OutputMappings)
            {
                TriggerParameterControl c   = new TriggerParameterControl();
                TriggerValue            val = new TriggerValue();
                if (ParentTriggerNamespace.GetValues().ContainsKey(v.ID) == false)
                {
                    val.Name = v.Name;
                    val.Type = v.Type;
                    int newID = -1;
                    ParentTriggerNamespace.InsertValue(val, out newID);
                    v.ID = newID;
                }
                else
                {
                    val = ParentTriggerNamespace.GetValues()[v.ID];
                }
                c.Init(null, v, val, ParentTriggerNamespace);

                VarOutHardPointsBar.AddControl(c);
            }
            foreach (TriggersTemplateInputActionBinder b in mapping.TriggerInputs)
            {
                BasicControlPoint cp = new BasicControlPoint(mHost);

                INHardPointsBar.AddControl(cp);
                cp.TargetKey = "none";//"Trigger.Link.Back";
                cp.TypeKey   = "Trigger.Link.Forward";
                cp.BackColor = b.GetColor();
                cp.SetToolTipText(b.Name);
                cp.Name = b.Name;
                cp.SetDirection(new Point(-250, 0));
                cp.Tag        = this;
                cp.TagObject  = this;
                cp.RenderText = cp.Name;
                cp.ControlPointDescription = this.mTriggerTemplateMapping.Name + "." + b.Name;

                mControlPoints.Add(cp);

                mInputActionCPs[cp] = b;
            }
            //flowLayoutPanel1.Controls.Add(MakeLabel("OutputTriggers:"));
            foreach (TriggersTemplateOutputActionBinder b in mapping.TriggerOutputs)
            {
                BasicControlPoint cp = new BasicControlPoint(mHost);
                OutHardPointsBar.AddControl(cp);
                cp.TargetKey = "Trigger.Link.Forward";
                cp.TypeKey   = "none";//"Trigger.Link.Back";
                cp.BackColor = b.GetColor();
                cp.SetToolTipText(b.Name);
                cp.Name = b.Name;
                cp.SetDirection(new Point(250, 0));
                cp.Tag                     = this;
                cp.TagObject               = this;
                cp.RenderText              = b.Name;
                cp.ControlPointConnected  += new BasicControlPoint.ControlPointEvent(output_ControlPointConnected);
                cp.ControlPointRemoved    += new BasicControlPoint.ControlPointEvent(output_ControlPointRemoved);
                cp.ControlPointDescription = this.mTriggerTemplateMapping.Name + "." + b.Name;

                mControlPoints.Add(cp);

                mOutputActionCPs[cp] = b;
            }
        }