private InstructionLDContactNC(IEditorItem parent, NodeInstruction instruction)
     : base(parent, m_InstructionType, instruction)
 {
     // Build the context menu
     if (extensionService != null)
     {
         ContextMenu        = extensionService.SortAndJoin(ldInstructionContextMenu, m_staticMenuItemSeparator, contextMenu);
         ContextMenuEnabled = true;
     }
 }
        public InstructionGroupExecutorContextLD  ScanInstruction(
            NodeRuntimeApplication rta, NodeInstruction instruction,
            InstructionGroupExecutorContextLD context)
        {
            bool enable = context.RungCondition;

            string stringToSearch         = string.Empty;
            var    stringToSearchSignalIn = instruction.NodeSignalInChildren[0]; // stringToSearch
            var    stringToSearchValue    = stringToSearchSignalIn.GetValue(rta);

            if (stringToSearchValue != null)
            {
                stringToSearch = Convert.ToString(stringToSearchValue.Value);
            }

            string stringToFind         = string.Empty;
            var    stringToFindSignalIn = instruction.NodeSignalInChildren[1]; // stringToFind
            var    stringToFindValue    = stringToFindSignalIn.GetValue(rta);

            if (stringToFindValue != null)
            {
                stringToFind = Convert.ToString(stringToFindValue.Value);
            }

            bool caseSensitive         = false;
            var  caseSensitiveSignalIn = instruction.NodeSignalInChildren[2]; // caseSensitive
            var  caseSensitiveValue    = caseSensitiveSignalIn.GetValue(rta);

            if (caseSensitiveValue != null)
            {
                caseSensitive = Convert.ToBoolean(caseSensitiveValue.Value);
            }

            bool oldRungOutCondition = Convert.ToBoolean(instruction.NodeSignalChildren[0].Value);
            bool newRungOutCondition;

            if (!enable)
            {
                newRungOutCondition = false;
            }
            else
            {
                if (caseSensitive)
                {
                    newRungOutCondition = stringToSearch.Contains(stringToFind);
                }
                else
                {
                    newRungOutCondition = stringToSearch.ToLower().Contains(stringToFind.ToLower());
                }
            }

            instruction.NodeSignalChildren[0].Value = newRungOutCondition;
            return(new InstructionGroupExecutorContextLD(newRungOutCondition));
        }
 public InstructionGroupExecutorContextLD ScanInstruction(
     NodeRuntimeApplication rta, NodeInstruction instruction,
     InstructionGroupExecutorContextLD context)
 {
     var contextIterator = context;
     foreach (var childInstruction in instruction.NodeInstructionChildren)
     {
         contextIterator = groupExecutorLD.ScanInstruction(rta, childInstruction, contextIterator);
     }
     return contextIterator;
 }
예제 #4
0
        private IEnumerable <CompiledInstruction> compileSeries(NodeInstruction seriesInstruction, SignalTable signalTable)
        {
            var result = new List <CompiledInstruction>();

            foreach (var instruction in seriesInstruction.NodeInstructionChildren)
            {
                result.AddRange(compileInstruction(instruction, signalTable));
            }
            result.Add(new CompiledInstruction(0x03, 3));
            return(result);
        }
예제 #5
0
        /// <summary>
        /// You can use this to change the Instruction property including doing all
        /// the legwork for the Undo/Redo framework, but only if the change *doesn't*
        /// involve editing the NodeInstructionChildren (child instructions)
        /// </summary>
        /// <param name="newInstruction"></param>
        protected void SimpleUndoableInstructionEdit(NodeInstruction newInstruction, string undoDescription)
        {
            var undoActions        = new Collection <Action>();
            var doActions          = new Collection <Action>();
            var saveNewInstruction = newInstruction;
            var origInstruction    = Instruction;

            doActions.Add(() => Instruction   = saveNewInstruction);
            undoActions.Add(() => Instruction = origInstruction);
            Do(new UndoMemento(this, ActionType.EDIT, undoDescription, undoActions, doActions));
        }
예제 #6
0
        private CompiledInstruction compileSetReset(NodeInstruction instruction, SignalTable signalTable)
        {
            var resetSignalIn       = instruction.NodeSignalInChildren[0];
            var compiledResetSignal = booleanSignal(resetSignalIn, signalTable);
            var stateSignal         = instruction.NodeSignalChildren[0];
            var compiledStateSignal = booleanSignal(stateSignal, signalTable);

            return(new CompiledInstruction(
                       0x12,
                       5,
                       compiledResetSignal, compiledStateSignal));
        }
예제 #7
0
        private CompiledInstruction compileComparison(NodeInstruction instruction, SignalTable signalTable, Byte opCode)
        {
            var operand1SignalIn       = instruction.NodeSignalInChildren[0];
            var compiledOperand1Signal = numericSignal(operand1SignalIn, signalTable);
            var operand2SignalIn       = instruction.NodeSignalInChildren[1];
            var compiledOperand2Signal = numericSignal(operand2SignalIn, signalTable);

            return(new CompiledInstruction(
                       opCode,
                       5,
                       compiledOperand1Signal, compiledOperand2Signal));
        }
        public InstructionGroupExecutorContextLD  ScanInstruction(
            NodeRuntimeApplication rta, NodeInstruction instruction,
            InstructionGroupExecutorContextLD context)
        {
            bool oldRungOutCondition = Convert.ToBoolean(instruction.NodeSignalChildren[0].Value);
            bool newRungOutCondition;

            newRungOutCondition = oldRungOutCondition && !context.RungCondition;

            instruction.NodeSignalChildren[0].Value = context.RungCondition;
            return(new InstructionGroupExecutorContextLD(newRungOutCondition));
        }
예제 #9
0
        private IEnumerable <CompiledInstruction> compileParallel(NodeInstruction parallelInstruction, SignalTable signalTable)
        {
            var result = new List <CompiledInstruction>();

            result.Add(new CompiledInstruction(0x15, 5)); // Parallel Start
            foreach (var instruction in parallelInstruction.NodeInstructionChildren)
            {
                result.AddRange(compileInstruction(instruction, signalTable));
            }
            result.Add(new CompiledInstruction(0x16, 5)); // Parallel End
            return(result);
        }
예제 #10
0
        protected InstructionLDMathBase(IEditorItem parent, FieldInstructionType instructionType, NodeInstruction instruction,
                                        string defaultName, bool factory, string instructionName, string firstSignalName, string secondSignalName)
            : base(parent, instructionType)
        {
            if (factory)
            {
                return;
            }

            this.InstructionName  = instructionName;
            this.FirstSignalName  = firstSignalName;
            this.SecondSignalName = secondSignalName;

            if (instruction == null)
            {
                var newInstruction = NodeInstruction.BuildWith(InstructionType);
                // Output signal: Named number - result
                newInstruction = newInstruction.NodeSignalChildren.Append(
                    NodeSignal.BuildWith(
                        new FieldSignalName(defaultName),
                        new FieldDataType(FieldDataType.DataTypeEnum.NUMBER),
                        new FieldBool(false), // not forced
                        FieldConstant.Constants.NUMBER.ZERO)
                    );
                // Input signal: First
                newInstruction = newInstruction.NodeSignalInChildren.Append(
                    NodeSignalIn.BuildWith(
                        new FieldDataType(FieldDataType.DataTypeEnum.NUMBER),
                        new FieldConstant(FieldDataType.DataTypeEnum.NUMBER, 0)));
                // Input signal: Second
                newInstruction = newInstruction.NodeSignalInChildren.Append(
                    NodeSignalIn.BuildWith(
                        new FieldDataType(FieldDataType.DataTypeEnum.NUMBER),
                        new FieldConstant(FieldDataType.DataTypeEnum.NUMBER, 0)));
                Instruction = newInstruction;
            }
            else
            {
                if (instruction.InstructionType != InstructionType)
                {
                    throw new InvalidOperationException("Tried to instantiate a different instruction type.");
                }
                Instruction = instruction;
            }

            // Build the context menu
            if (extensionService != null)
            {
                ContextMenu        = extensionService.SortAndJoin(ldInstructionContextMenu, m_staticMenuItemSeparator, contextMenu);
                ContextMenuEnabled = true;
            }
        }
예제 #11
0
        private CompiledInstruction compileTimer(NodeInstruction instruction, SignalTable signalTable, Byte opCode)
        {
            var setpointSignalIn       = instruction.NodeSignalInChildren[0];
            var compiledSetpointSignal = numericSignal(setpointSignalIn, signalTable);
            var doneSignal             = instruction.NodeSignalChildren[0];
            var compiledDoneSignal     = booleanSignal(doneSignal, signalTable);
            var elapsedSignal          = instruction.NodeSignalChildren[1];
            var compiledElapsedSignal  = numericSignal(elapsedSignal, signalTable);

            return(new CompiledInstruction(
                       opCode,
                       5,
                       compiledSetpointSignal, compiledDoneSignal, compiledElapsedSignal));
        }
예제 #12
0
 protected InstructionLDSeries(IEditorItem parent, NodeInstruction instruction)
     : base(parent, m_InstructionType)
 {
     if (instruction == null)
     {
         Instruction = EmptyRung();
     }
     else
     {
         if (instruction.InstructionType != InstructionType)
         {
             throw new InvalidOperationException("Tried to instantiate InstructionLDSeries but passed a different instruction type.");
         }
         Instruction = instruction;
     }
 }
예제 #13
0
        protected InstructionLDStringContains(IEditorItem parent, NodeInstruction instruction)
            : base(parent, m_InstructionType)
        {
            if (instruction == null)
            {
                var newInstruction = NodeInstruction.BuildWith(InstructionType);
                // Output signal: Named boolean - result of the comparison
                newInstruction = newInstruction.NodeSignalChildren.Append(
                    NodeSignal.BuildWith(
                        new FieldSignalName(Resources.Strings.LD_Snap_StringContains_DefaultName),
                        new FieldDataType(FieldDataType.DataTypeEnum.BOOL),
                        new FieldBool(false), // not forced
                        FieldConstant.Constants.BOOL.LOW)
                    );
                // Input signal: string to search
                newInstruction = newInstruction.NodeSignalInChildren.Append(
                    NodeSignalIn.BuildWith(
                        new FieldDataType(FieldDataType.DataTypeEnum.STRING),
                        new FieldConstant(FieldDataType.DataTypeEnum.STRING, string.Empty)));
                // Input signal: string to find
                newInstruction = newInstruction.NodeSignalInChildren.Append(
                    NodeSignalIn.BuildWith(
                        new FieldDataType(FieldDataType.DataTypeEnum.STRING),
                        new FieldConstant(FieldDataType.DataTypeEnum.STRING, string.Empty)));
                // Input signal: case sensitive
                newInstruction = newInstruction.NodeSignalInChildren.Append(
                    NodeSignalIn.BuildWith(
                        new FieldDataType(FieldDataType.DataTypeEnum.BOOL),
                        new FieldConstant(FieldDataType.DataTypeEnum.BOOL, false)));
                Instruction = newInstruction;
            }
            else
            {
                if (instruction.InstructionType != InstructionType)
                {
                    throw new InvalidOperationException("Tried to instantiate a StringContains but passed a different instruction type.");
                }
                Instruction = instruction;
            }

            // Build the context menu
            if (extensionService != null)
            {
                ContextMenu        = extensionService.SortAndJoin(ldInstructionContextMenu, m_staticMenuItemSeparator, contextMenu);
                ContextMenuEnabled = true;
            }
        }
예제 #14
0
        public InstructionGroupExecutorContextLD ScanInstruction(
            NodeRuntimeApplication rta, NodeInstruction instruction,
            InstructionGroupExecutorContextLD context)
        {
            bool mutableRungCondition = false; // OR's together the results

            foreach (var childInstruction in instruction.NodeInstructionChildren)
            {
                var contextResult = groupExecutorLD.ScanInstruction(rta, childInstruction, context);
                mutableRungCondition = contextResult.RungCondition || mutableRungCondition;
            }
            // Removed this because in some cases the rung-in condition doesn't have to be true for the output
            // of a branch to be true.  Seems odd, but the best example of this is a FallingEdge instruction,
            // which is true on the scan that the rung-in condition goes false.
            //mutableRungCondition = context.RungCondition && mutableRungCondition;
            return(new InstructionGroupExecutorContextLD(mutableRungCondition));
        }
        public InstructionGroupExecutorContextLD ScanInstruction(
            NodeRuntimeApplication rta, NodeInstruction instruction,
            InstructionGroupExecutorContextLD context)
        {
            var signalIn = instruction.NodeSignalInChildren[0];
            var value    = signalIn.GetValue(rta);

            if (value != null)
            {
                return(new InstructionGroupExecutorContextLD(
                           context.RungCondition && (bool)(value.Value)));
            }
            else
            {
                return(new InstructionGroupExecutorContextLD(false));
            }
        }
        public InstructionGroupExecutorContextLD  ScanInstruction(
            NodeRuntimeApplication rta, NodeInstruction instruction,
            InstructionGroupExecutorContextLD context)
        {
            bool newRungOutCondition;

            if (context.RungCondition)
            {
                newRungOutCondition = true;
                instruction.NodeSignalChildren[1].Value = (Decimal)0;
            }
            else
            {
                bool    oldRungOut = Convert.ToBoolean(instruction.NodeSignalChildren[0].Value);
                Decimal oldElapsed = Convert.ToDecimal(instruction.NodeSignalChildren[1].Value);

                Decimal setPoint = Decimal.MaxValue;                    // default to not turning on (for a long time - 50 days?)
                var     signalIn = instruction.NodeSignalInChildren[0]; // setpoint
                var     value    = signalIn.GetValue(rta);
                if (value != null)
                {
                    setPoint = Convert.ToDecimal(value.Value);
                }

                Decimal newElapsed = 0;
                if (setPoint < Decimal.MaxValue)
                {
                    // don't want to run the timer if we didn't find a valid setpoint
                    newElapsed = Convert.ToDecimal(Math.Min(oldElapsed + Convert.ToDecimal(engine.LastScanTime), setPoint));
                }

                if (newElapsed < setPoint)
                {
                    newRungOutCondition = oldRungOut;
                }
                else
                {
                    newRungOutCondition = false;
                }
                instruction.NodeSignalChildren[1].Value = newElapsed;
            }
            instruction.NodeSignalChildren[0].Value = newRungOutCondition;
            return(new InstructionGroupExecutorContextLD(newRungOutCondition));
        }
        protected InstructionLDAbstractTimer(IEditorItem parent, NodeInstruction instruction, FieldInstructionType instructionType)
            : base(parent, instructionType)
        {
            if (instruction == null)
            {
                var newInstruction = NodeInstruction.BuildWith(InstructionType);
                // Output signal: Named boolean - the timer done signal
                newInstruction = newInstruction.NodeSignalChildren.Append(
                    NodeSignal.BuildWith(
                        new FieldSignalName(Resources.Strings.LD_Snap_Tmr_DefaultName),
                        new FieldDataType(FieldDataType.DataTypeEnum.BOOL),
                        new FieldBool(false), // not forced
                        FieldConstant.Constants.BOOL.LOW)
                    );
                newInstruction = newInstruction.NodeSignalChildren.Append(
                    NodeSignal.BuildWith(
                        new FieldSignalName(Resources.Strings.LD_Snap_Tmr_DefaultName + SEPARATOR + Resources.Strings.LD_Snap_Tmr_ElapsedName),
                        new FieldDataType(FieldDataType.DataTypeEnum.NUMBER),
                        new FieldBool(false), // not forced
                        FieldConstant.Constants.NUMBER.ZERO)
                    );
                // Input signal: setpoint
                newInstruction = newInstruction.NodeSignalInChildren.Append(
                    NodeSignalIn.BuildWith(
                        new FieldDataType(FieldDataType.DataTypeEnum.NUMBER),
                        new FieldConstant(FieldDataType.DataTypeEnum.NUMBER, 0)));
                Instruction = newInstruction;
            }
            else
            {
                if (instruction.InstructionType != InstructionType)
                {
                    throw new InvalidOperationException("Tried to instantiate a Timer but passed a different instruction type.");
                }
                Instruction = instruction;
            }

            // Build the context menu
            if (extensionService != null)
            {
                ContextMenu        = extensionService.SortAndJoin(ldInstructionContextMenu, m_staticMenuItemSeparator, contextMenu);
                ContextMenuEnabled = true;
            }
        }
예제 #18
0
        private CompiledInstruction compileCounter(NodeInstruction instruction, SignalTable signalTable, Byte opCode)
        {
            var setpointSignalIn       = instruction.NodeSignalInChildren[0];
            var compiledSetpointSignal = numericSignal(setpointSignalIn, signalTable);
            var resetSignalIn          = instruction.NodeSignalInChildren[1];
            var compiledResetSignal    = booleanSignal(resetSignalIn, signalTable);

            var doneSignal          = instruction.NodeSignalChildren[0];
            var compiledDoneSignal  = booleanSignal(doneSignal, signalTable);
            var countSignal         = instruction.NodeSignalChildren[1];
            var compiledCountSignal = numericSignal(countSignal, signalTable);
            var stateSignal         = instruction.NodeSignalChildren[2];
            var compiledStateSignal = booleanSignal(stateSignal, signalTable);

            return(new CompiledInstruction(
                       opCode,
                       6,
                       compiledSetpointSignal, compiledResetSignal,
                       compiledDoneSignal, compiledCountSignal, compiledStateSignal));
        }
예제 #19
0
        private CompiledInstruction compileCntUD(NodeInstruction instruction, SignalTable signalTable)
        {
            var countDownSignalIn       = instruction.NodeSignalInChildren[0];
            var compiledCountDownSignal = booleanSignal(countDownSignalIn, signalTable);
            var resetSignalIn           = instruction.NodeSignalInChildren[1];
            var compiledResetSignal     = booleanSignal(resetSignalIn, signalTable);

            var zeroSignal                   = instruction.NodeSignalChildren[0];
            var compiledZeroSignal           = booleanSignal(zeroSignal, signalTable);
            var countSignal                  = instruction.NodeSignalChildren[1];
            var compiledCountSignal          = numericSignal(countSignal, signalTable);
            var countUpStateSignal           = instruction.NodeSignalChildren[2];
            var compiledCountUpStateSignal   = booleanSignal(countUpStateSignal, signalTable);
            var countDownStateSignal         = instruction.NodeSignalChildren[3];
            var compiledCountDownStateSignal = booleanSignal(countDownStateSignal, signalTable);

            return(new CompiledInstruction(
                       0x7D,
                       7,
                       compiledCountDownSignal, compiledResetSignal,
                       compiledZeroSignal, compiledCountSignal, compiledCountUpStateSignal, compiledCountDownStateSignal));
        }
예제 #20
0
 protected InstructionLDAbstractContact(IEditorItem parent, FieldInstructionType instructionType, NodeInstruction instruction)
     : base(parent, instructionType)
 {
     if (instruction == null)
     {
         var newInstruction = NodeInstruction.BuildWith(InstructionType);
         // Input signal: (coil that we're a contact off) default to always false
         newInstruction = newInstruction.NodeSignalInChildren.Append(
             NodeSignalIn.BuildWith(
                 new FieldDataType(FieldDataType.DataTypeEnum.BOOL),
                 new FieldConstant(FieldDataType.DataTypeEnum.BOOL, false)));
         Instruction = newInstruction;
     }
     else
     {
         if (instructionType != instruction.InstructionType)
         {
             throw new ArgumentOutOfRangeException("Tried to instantiate a contact of type " +
                                                   instructionType.ToString() + " with an instruction of a different type.");
         }
         Instruction = instruction;
     }
 }
예제 #21
0
 public override IInstructionItem Create(IEditorItem parent, NodeInstruction instruction)
 {
     return(new InstructionLDChooseNumber(parent, instruction));
 }
예제 #22
0
 protected InstructionLDChooseNumber(IEditorItem parent, NodeInstruction instruction)
     : base(parent, m_InstructionType, instruction, Resources.Strings.LD_Snap_ChooseNumber_DefaultName, false,
            Resources.Strings.LD_Snap_ChooseNumber_InstructionName,
            Resources.Strings.LD_Snap_ChooseNumber_FirstSignalName, Resources.Strings.LD_Snap_ChooseNumber_SecondSignalName)
 {
 }
 private InstructionLDTmrON(IEditorItem parent, NodeInstruction instruction)
     : base(parent, instruction, m_InstructionType)
 {
 }
 public override IInstructionItem Create(IEditorItem parent, NodeInstruction instruction)
 {
     return(new InstructionLDTmrON(parent, instruction));
 }
예제 #25
0
 private CompiledInstruction compileChooseNumber(NodeInstruction instruction, SignalTable signalTable)
 {
     return(compileMath(instruction, signalTable, 0x7C));
 }
예제 #26
0
 private CompiledInstruction compileDivide(NodeInstruction instruction, SignalTable signalTable)
 {
     return(compileMath(instruction, signalTable, 0x7B));
 }
예제 #27
0
 private CompiledInstruction compileMultiply(NodeInstruction instruction, SignalTable signalTable)
 {
     return(compileMath(instruction, signalTable, 0x7A));
 }
예제 #28
0
 private CompiledInstruction compileSubtract(NodeInstruction instruction, SignalTable signalTable)
 {
     return(compileMath(instruction, signalTable, 0x79));
 }
예제 #29
0
 private CompiledInstruction compileNotEqual(NodeInstruction instruction, SignalTable signalTable)
 {
     return(compileComparison(instruction, signalTable, 0x1D));
 }
예제 #30
0
 private CompiledInstruction compileLessThanOrEqual(NodeInstruction instruction, SignalTable signalTable)
 {
     return(compileComparison(instruction, signalTable, 0x1C));
 }