private ITcSmTreeItem createItf(ItfInfo itfInfo, ITcSmTreeItem parent, IWorker worker, XmlDocument doc)
        {
            XmlNode itfNode = doc.SelectSingleNode("TcPlcObject/Itf");
            string  itfName = itfNode.Attributes["Name"].Value;

            worker.ProgressStatus = string.Format("Creating Interface '{0}' ...", itfName);

            ITcSmTreeItem item = null;
            XmlElement    node = (XmlElement)doc.SelectSingleNode("TcPlcObject/Itf/Declaration");

            string declString = node.InnerText;

            if (!TryLookupChild(parent, itfName, out item))
            {
                item = parent.CreateChild(itfName, TreeItemType.PlcInterface.AsInt32(), "", declString);
            }

            //Debug.Fail("");
            ITcXmlDocument xmlDoc = (ITcXmlDocument)item;

            xmlDoc.DocumentXml = doc.OuterXml;
            ITcPlcDeclaration decl = (ITcPlcDeclaration)item;

            //decl.DeclarationText = node.InnerText;
            return(item);
        }
        private void generateMainDecl(ref ITcPlcDeclaration mainDecl, ref string[] boxName)
        {
            string sDeclStart = @"PROGRAM MAIN
VAR" + Environment.NewLine;

            string sDeclEnd = Environment.NewLine + "END_VAR" + Environment.NewLine;

            string sCommonVars = @"
    xEnable         : BOOL;
    xInitFlag		: BOOL;
	xRun			: BOOL;
	xStart			: BOOL;
	xStop			: BOOL;
    xEmergencyStop	: BOOL;
	xClearError		: BOOL;
	iIndex			: INT;
	lrTempReal		: LREAL;
	pTempBool		: POINTER TO BOOL;
	pTempDint		: POINTER TO DINT;
	xVisibility		: BOOL;
	artrigEvent		: ARRAY [1..5] OF r_trig;
	iAnimationIndex	: INT;
	xEmpty			: BOOL;
	xSimulate		: BOOL;
    uiIndex			: UINT;
	uiModeCycle		: UINT;
	xZoneTriggered	: BOOL;
	uiZoneActive	: UINT;
	iSetVelocity	: INT	:= 1000;
	xFwdRev			: BOOL;
	iCmdVelocity	: INT;
    xConfigInit			: BOOL := FALSE;
	tmrWebStartDelay	: TON;
	xTemp: BOOL;"    ;

            //Create formats for declaring new variables for each drive in the list
            string sUniqueVars       = "";
            string feedsFormat       = "{0}Feed			: ARRAY [1..2] OF BOOL;"+ Environment.NewLine;
            string zpaSettingsFormat = "a{0}ZpaSettings     : ARRAY[1..2] OF ST_ZpaSettings;" + Environment.NewLine;
            string zoneFormat        = "a{0}Out		: ARRAY [1..2] OF ST_ZoneOut;"+ Environment.NewLine;
            string mdrSettingsFormat = "{0}MdrSettings      : ST_Mdr_Settings;" + Environment.NewLine;

            //generate the variables needed for each function block
            for (int i = 0; i < _nDriveCount - 1; i++)
            {
                sUniqueVars += string.Format(feedsFormat, boxName[i]);
                sUniqueVars += string.Format(zpaSettingsFormat, boxName[i]);
                sUniqueVars += string.Format(zoneFormat, boxName[i]);
                sUniqueVars += string.Format(mdrSettingsFormat, boxName[i]);
                sUniqueVars += Environment.NewLine;
            }

            string sDeclarationText = sDeclStart + sCommonVars + sUniqueVars + sDeclEnd;

            mainDecl.DeclarationText = sDeclarationText;
        }//GenerateMainDecl()
Esempio n. 3
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;

            if (dte.ActiveWindow.ProjectItem.Object is ITcPlcDeclaration)
            {
                ITcPlcDeclaration declaration =
                    (ITcPlcDeclaration)dte.ActiveWindow.ProjectItem.Object;

                uint   indents = 0;
                string text    = declaration.DeclarationText;
                Global.indentation = text.Contains("\t") ? "\t" : "    ";
                Global.lineEnding  = "\r\n";
                string formatedCode = new CompositeCode(text)
                                      .Tokenize()
                                      .Format(ref indents);
                declaration.DeclarationText = formatedCode;
            }
        }
        }//LinkIoToPlc()

        private void createDriveStruct()
        {
            //create strings for the beginning and end of the struct declaration
            string structStart = "TYPE ST_EP7402:" + Environment.NewLine + "STRUCT" + Environment.NewLine;
            string structEnd   = "END_STRUCT" + Environment.NewLine + "END_TYPE" + Environment.NewLine;

            //create the DUT and assign it to a container
            ITcSmTreeItem     DUT         = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project^DUTs");
            ITcSmTreeItem     driveStruct = DUT.CreateChild("ST_EP7402", 606, "");
            ITcPlcDeclaration structDecl  = (ITcPlcDeclaration)driveStruct;

            string sdeclarationText;

            //create a string for generating the member declaration of the struct.
            string structMembers = @"stInputs   AT %I*  :   EP7402_Inputs;" + Environment.NewLine +
                                   "stOutputs   AT %Q*  :   EP7402_Outputs;" + Environment.NewLine;

            //combine the string into a single string to create the declaration text
            sdeclarationText           = structStart + structMembers + structEnd;
            structDecl.DeclarationText = sdeclarationText;
        }
        private ITcSmTreeItem createDut(DataTypeInfo info, ITcSmTreeItem parent, IWorker worker, XmlDocument doc)
        {
            XmlNode dutNode  = doc.SelectSingleNode("TcPlcObject/DUT");
            string  typeName = dutNode.Attributes["Name"].Value;

            worker.ProgressStatus = string.Format("Creating Type '{0}' ...", typeName);

            XmlNode declNode    = dutNode.SelectSingleNode("Declaration");
            string  declaration = string.Empty;

            declaration = declNode.InnerText;

            ITcSmTreeItem dataTypeItem = parent.CreateChild(typeName, TreeItemType.PlcDutStruct.AsInt32(), "", declaration);

            ITcPlcDeclaration decl  = (ITcPlcDeclaration)dataTypeItem;
            ITcXmlDocument    tcDoc = (ITcXmlDocument)dataTypeItem;

            string xml = tcDoc.DocumentXml;

            return(dataTypeItem);
        }
        private ITcSmTreeItem createGvl(GvlInfo gvlInfo, ITcSmTreeItem parent, IWorker worker, XmlDocument doc)
        {
            XmlNode gvlNode = doc.SelectSingleNode("TcPlcObject/GVL");
            string  gvlName = gvlNode.Attributes["Name"].Value;

            worker.ProgressStatus = string.Format("Creating GlobalVariable Sheet '{0}' ...", gvlName);

            ITcSmTreeItem item = null;

            if (!TryLookupChild(parent, gvlName, out item))
            {
                item = parent.CreateChild(gvlName, TreeItemType.PlcGvl.AsInt32());
            }

            ITcXmlDocument    xmlDoc = (ITcXmlDocument)item;
            ITcPlcDeclaration decl   = (ITcPlcDeclaration)item;

            XmlElement node = (XmlElement)doc.SelectSingleNode("TcPlcObject/GVL/Declaration");

            decl.DeclarationText = node.InnerText;
            return(item);
        }
        private void createFBCalls(string[] boxName)
        {
            //acuire project instance of MAIN Pou
            //then tell TwinCAT to create 3 new Actions for MAIN
            ITcSmTreeItem mainPOU    = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project^POUs^MAIN");
            ITcSmTreeItem fbBlockAct = mainPOU.CreateChild("A_Block", 608, "");
            ITcSmTreeItem fbInitAct  = mainPOU.CreateChild("A_Init", 608, "");

            ITcPlcPou pouMain = (ITcPlcPou)mainPOU;


            ITcPlcImplementation actBlock = (ITcPlcImplementation)fbBlockAct;
            ITcPlcImplementation actInit  = (ITcPlcImplementation)fbInitAct;

            ITcPlcImplementation pouMainImpl = (ITcPlcImplementation)pouMain;

            ITcPlcDeclaration pouMainDecl = (ITcPlcDeclaration)pouMain;

            generateMainDecl(ref pouMainDecl, ref boxName);
            generateMainImpl(ref pouMainImpl);
            generateBlockAct(ref actBlock, ref boxName);
            generateInitAct(ref actInit, ref boxName);
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            //-----------------------------------------------------------------------------------------------------------------------
            //                                          Retrieve all relevant data from config file
            //-----------------------------------------------------------------------------------------------------------------------

            ConfigFileReader configFileReader = new ConfigFileReader();
            Assigner         assigner         = new Assigner();

            MessageFilter.Register();

            //-----------------------------------------------------------------------------------------------------------------------
            //                                          Attach to existing Dte
            //-----------------------------------------------------------------------------------------------------------------------



            AssignedConfigFileData.pathToSolution = Assigner.ReplaceBlueprintValues(
                AssignedConfigFileData.pathToSolution,
                new string[] { "@NameOfProject@" },
                new string[] { AssignedConfigFileData.nameOfProject }
                );

            Console.WriteLine("pathToSolution: {0}", AssignedConfigFileData.pathToSolution);

            AssignedConfigFileData.pathToPOUsFolder = Assigner.ReplaceBlueprintValues(
                AssignedConfigFileData.pathToPOUsFolder,
                new string[] { "@NameOfPLCProject@" },
                new string[] { AssignedConfigFileData.nameOfPlcProject }
                );

            Console.WriteLine("pathToPOUsFolder: {0}", AssignedConfigFileData.pathToPOUsFolder);

            AssignedConfigFileData.pathToDUTsFolder = Assigner.ReplaceBlueprintValues(
                AssignedConfigFileData.pathToDUTsFolder,
                new string[] { "@NameOfPLCProject@" },
                new string[] { AssignedConfigFileData.nameOfPlcProject }
                );

            Console.WriteLine("pathToDUTsFolder: {0}", AssignedConfigFileData.pathToDUTsFolder);

            AssignedConfigFileData.pathToGVLsFolder = Assigner.ReplaceBlueprintValues(
                AssignedConfigFileData.pathToGVLsFolder,
                new string[] { "@NameOfPLCProject@" },
                new string[] { AssignedConfigFileData.nameOfPlcProject }
                );

            Console.WriteLine("pathToGVLsFolder: {0}", AssignedConfigFileData.pathToGVLsFolder);

            AssignedConfigFileData.pathToMAIN = Assigner.ReplaceBlueprintValues(
                AssignedConfigFileData.pathToMAIN,
                new string[] { "@NameOfPLCProject@" },
                new string[] { AssignedConfigFileData.nameOfPlcProject }
                );

            Console.WriteLine("pathToMAIN: {0}", AssignedConfigFileData.pathToMAIN);

            List <Project> projectList  = new List <Project>();
            Project        plcProj      = null;
            bool           projectFound = false;

            ITcPlcDeclaration    decl = (ITcPlcDeclaration)null;
            ITcPlcImplementation impl = (ITcPlcImplementation)null;

            ITcSmTreeItem currentMethod = null;
            ITcSmTreeItem pou           = null;
            ITcSmTreeItem dut           = null;
            ITcSmTreeItem gvl           = null;
            ITcSmTreeItem main          = null;
            ITcSmTreeItem modules       = null;
            ITcSmTreeItem constants     = null;
            ITcSmTreeItem system        = null;
            ITcSmTreeItem targetModule  = null;
            ITcSmTreeItem triggers      = null;
            ITcSmTreeItem eventManagers = null;
            ITcSmTreeItem interfaces    = null;
            ITcSmTreeItem i_sequence    = null;

            ITcSysManager sysManager = null;

            EnvDTE.DTE dte =
                DteAttacher.attachToExistingDte(
                    AssignedConfigFileData.pathToSolution,
                    AssignedConfigFileData.visualStudioVersion,
                    AssignedConfigFileData.nameOfProject

                    );

            dynamic solution = dte.Solution;

            Console.WriteLine("Full solution name:");
            Console.WriteLine(solution.FullName);

            Projects prjs = solution.projects;

            Console.WriteLine("Projects in solution: {0}", prjs.Count);
            for (int i = 1; i <= prjs.Count; i++)
            {
                projectList.Add(prjs.Item(i));
                Console.WriteLine("Project found: {0}", prjs.Item(i).Name);
                Console.WriteLine("Searching for project: {0}", AssignedConfigFileData.nameOfProject);
                if (prjs.Item(i).Name.Equals(AssignedConfigFileData.nameOfProject))
                {
                    plcProj      = prjs.Item(i);
                    projectFound = true;
                }
            }

            //-----------------------------------------------------------------------------------------------------------------------
            //                                          Perform checks
            //-----------------------------------------------------------------------------------------------------------------------

            Console.WriteLine("Performing checks:");

            if (projectFound)
            {
                Console.WriteLine("Project found.");
                sysManager = plcProj.Object;
            }
            else
            {
                Console.WriteLine("Project not found. Exiting on Enter.");
                Console.Read();
                return;
            }

            //Is POUs item available?
            Functions.SearchForItem(AssignedConfigFileData.pathToPOUsFolder, ref sysManager, ref pou);

            //Is DUTs item available?
            Functions.SearchForItem(AssignedConfigFileData.pathToDUTsFolder, ref sysManager, ref dut);

            //Is GVLs item available?
            Functions.SearchForItem(AssignedConfigFileData.pathToGVLsFolder, ref sysManager, ref gvl);

            //Is Main item available?
            Functions.SearchForItem(AssignedConfigFileData.pathToMAIN, ref sysManager, ref main);

            if (AssignedConfigFileData.activity.Equals("SpecificEventsModuleCreator"))
            {
                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------------- MAIN implementation -----------------------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------
                impl = (ITcPlcImplementation)main;
                impl.ImplementationText = AssignedConfigFileData.blueprintMainImplementation;

                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------------- Create methods for MAIN -------------------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------
                currentMethod        = main.CreateChild("systemTime", 609, "");
                decl                 = (ITcPlcDeclaration)currentMethod;
                decl.DeclarationText = AssignedConfigFileData.blueprintMainSystemTimeDeclaration;

                impl = (ITcPlcImplementation)currentMethod;
                impl.ImplementationText = AssignedConfigFileData.blueprintMainSystemTimeImplementation;

                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------------- Create the  ModulesGVL --------------------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------
                modules = gvl.CreateChild("Modules", 615, "", AssignedConfigFileData.blueprintModulesGvlDeclaration);

                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------------- Create the  ConstantsGVL ------------------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------
                constants = gvl.CreateChild("Constants", 615, "", AssignedConfigFileData.blueprintConstantsGvlDeclaration);

                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------------- Create the SystemGVL ----------------------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------
                system = gvl.CreateChild("System", 615, "", AssignedConfigFileData.blueprintSystemGvlDeclaration);

                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------------- Create the EventManagers folder -----------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------
                eventManagers = pou.CreateChild("EventManagers", 601, "", "1");

                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------------- Create the Interfaces folder --------------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------
                interfaces = pou.CreateChild("Interfaces", 601, "", "1");

                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------------- Create the I_Sequence interface -----------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------
                i_sequence = interfaces.CreateChild("I_Sequence", 618);

                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------------- Create the sequence interface method ------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------
                currentMethod        = i_sequence.CreateChild("sequence", 610);
                decl                 = (ITcPlcDeclaration)currentMethod;
                decl.DeclarationText = AssignedConfigFileData.blueprintInterfaceSequenceMethodDeclaration;
            }
            else
            {
                //Is the Module GVL present?
                Functions.SearchForSubItem("Modules", ref gvl, ref modules);

                //Is the Triggers GVL present?
                //Functions.SearchForSubItem("Triggers", ref gvl, ref triggers);

                //Is the Eventmanagers folder present?
                Functions.SearchForSubItem("EventManagers", ref pou, ref eventManagers);
            }

            //Is TargetModule present?

            /*
             * if (AssignedConfigFileData.activity.Equals("InjectNewEventManagerInTarget"))
             * {
             *  Functions.SearchForItem(AssignedConfigFileData.pathToTargetModule, ref sysManager, ref targetModule);
             * }
             */
            //Is the Interfaces folder present?
            //Functions.SearchForSubItem("Interfaces", ref pou, ref interfaces);

            //-----------------------------------------------------------------------------------------------------------------------
            //                                          Start activity
            //-----------------------------------------------------------------------------------------------------------------------

            Console.WriteLine("Executing program.");

            for (int i = 0; i < AssignedConfigFileData.modulesContainer.content.Length; i++)
            {
                if (AssignedConfigFileData.activity.Equals("GeneralEventsModuleCreator"))
                {
                    new GeneralEventsModuleCreator(i, pou, dut, gvl, eventManagers, modules, triggers);
                }
                else if (AssignedConfigFileData.activity.Equals("SpecificEventsModuleCreator"))
                {
                    new SpecificEventsModuleCreator(i, pou, dut, gvl, eventManagers, modules, triggers);
                }
            }
            MessageFilter.Revoke();
            Console.WriteLine("Finished!");
            Console.Read();
        }
Esempio n. 9
0
        private void CreateModuleCode()
        {
            String eventManagerName;

            //-----------------------------------------------------------------------------------------------------------------------
            //---------------------------------Create module In-Out Structs  --------------------------------------------------------
            //-----------------------------------------------------------------------------------------------------------------------

            moduleConditionsToFire = dut.CreateChild(
                module.getName + "conditionsToFire",
                606,
                "",
                Assigner.ReplaceBlueprintValues(
                    AssignedConfigFileData.blueprintModuleOutStruct,
                    new string[] { "@moduleName@" },
                    new string[] { module.getName }
                    )
                );

            //Structure that defines the Event-Triggers that will be used as inputs in the Eventmanager
            moduleEventTriggers = dut.CreateChild(
                module.getName + "EventTriggers",
                606,
                "",
                Assigner.ReplaceBlueprintValues(
                    AssignedConfigFileData.blueprintModuleInStruct,
                    new string[] { "@moduleName@" },
                    new string[] { module.getName }
                    )
                );


            //-----------------------------------------------------------------------------------------------------------------------
            //--------------------------------- Fill the  ModulesGVL ----------------------------------------------------------------
            //-----------------------------------------------------------------------------------------------------------------------

            modulesGvlImplementation = "\t" + module.getName + ": " + module.getName + ";" + "\n";
            decl  = (ITcPlcDeclaration)modules;
            index = decl.DeclarationText.IndexOf(keyVarGlobal);
            decl.DeclarationText =
                decl.DeclarationText.Insert(
                    index + (keyVarGlobal.Length + 1),
                    modulesGvlImplementation
                    );

            //-----------------------------------------------------------------------------------------------------------------------
            //------------------------------------------------Create the FB_TargetModule---------------------------------------------
            //-----------------------------------------------------------------------------------------------------------------------

            //604   TREEITEMTYPE_PLCPOUFB   POU Function Block
            ITcSmTreeItem targetModule = pou.CreateChild(module.getName, 604, "1");

            //-----------------------------------------------------------------------------------------------------------------------
            //--------------------------- Create the FB_TargetModule Methods --------------------------------------------------------
            //-----------------------------------------------------------------------------------------------------------------------
            moduleEventManagerDeclaration = null;
            eventNamesLists.Clear();

            foreach (EventManager eventManager in module.content)
            {
                eventNamesLists.Add(eventManager.content.eventNames);
                eventManagerNames.Add(eventManager.getName);
                moduleEventManagerDeclaration += Assigner.ReplaceBlueprintValues(
                    "\t" + AssignedConfigFileData.blueprintModuleEventManagerDeclaration + "\n",
                    new string[] { "@eventManagerName@" },
                    new string[] { eventManager.getName }
                    );

                moduleEventManagerImplementation += Assigner.ReplaceBlueprintValues(
                    AssignedConfigFileData.blueprintModuleEventManagerImplementation + "\n",
                    new string[] { "@eventManagerName@" },
                    new string[] { eventManager.getName }
                    );
            }

            foreach (String[] eventNamesGroup in eventNamesLists)
            {
                eventManagerName = eventManagerNames.First();
                eventManagerNames.RemoveAt(0);

                foreach (String eventName in eventNamesGroup)
                {
                    //Create EventMethods
                    currentMethod = targetModule.CreateChild(eventName + "Event", 609, "", methodDescription);

                    decl = (ITcPlcDeclaration)currentMethod;
                    decl.DeclarationText = Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintEventMethodDeclaration,
                        new string[] { "@eventName@" },
                        new string[] { eventName }
                        );

                    //Create SenderMethods
                    currentMethod = targetModule.CreateChild("fire" + Functions.UppercaseFirst(eventName) + "Event", 609, "", methodDescription);

                    decl = (ITcPlcDeclaration)currentMethod;

                    decl.DeclarationText = Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintSenderMethodDeclaration,
                        new string[] { "@eventName@" },
                        new string[] { eventName }
                        );

                    impl = (ITcPlcImplementation)currentMethod;
                    impl.ImplementationText = Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintSenderMethodImplementation,
                        new string[] { "@eventName@", "@eventManagerName@" },
                        new string[] { eventName, eventManagerName }
                        );

                    outConditionsToFire += "\t" + eventName + "Event : BOOL;\n";

                    eventRaiserImplementation += Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintEventRaiserImplementation + "\n",
                        new string[] { "@eventName@" },
                        new string[] { eventName }
                        );

                    moduleTriggerEventDeclaration += Assigner.ReplaceBlueprintValues(
                        "\t" + AssignedConfigFileData.blueprintModuleTriggerEventsDeclaration + "\n",
                        new string[] { "@eventName@" },
                        new string[] { Functions.UppercaseFirst(eventName) }
                        );
                }
            }

            //Fill the module structures with the relevant data
            //--------------------------------------------------------------------------------
            decl = (ITcPlcDeclaration)moduleEventTriggers;

            index = decl.DeclarationText.IndexOf(keyVarStruct);
            decl.DeclarationText = decl.DeclarationText.Insert(
                index + (keyVarStruct.Length + 1),
                moduleTriggerEventDeclaration
                );

            decl = (ITcPlcDeclaration)moduleConditionsToFire;

            index = decl.DeclarationText.IndexOf(keyVarStruct);
            decl.DeclarationText = decl.DeclarationText.Insert(
                index + (keyVarStruct.Length + 1),
                outConditionsToFire
                );
            //--------------------------------------------------------------------------------

            //eventRaiser method
            currentMethod = targetModule.CreateChild("eventRaiser", 609, "", methodDescription);


            decl = (ITcPlcDeclaration)currentMethod;
            decl.DeclarationText = AssignedConfigFileData.blueprintEventRaiserDeclaration;

            impl = (ITcPlcImplementation)currentMethod;
            impl.ImplementationText = eventRaiserImplementation;

            //callComponents method
            currentMethod = targetModule.CreateChild("callComponents", 609, "", methodDescription);


            decl = (ITcPlcDeclaration)currentMethod;
            decl.DeclarationText = AssignedConfigFileData.blueprintCallComponentsDeclaration;

            //registerSequence method
            currentMethod = targetModule.CreateChild("registerSequence", 609, "", methodDescription);


            decl = (ITcPlcDeclaration)currentMethod;
            decl.DeclarationText = AssignedConfigFileData.blueprintRegisterSequenceDeclarationText;

            impl = (ITcPlcImplementation)currentMethod;
            impl.ImplementationText = AssignedConfigFileData.blueprintRegisterSequenceImplementationText;

            //runSequence method
            currentMethod = targetModule.CreateChild("runSequence", 609, "", methodDescription);


            decl = (ITcPlcDeclaration)currentMethod;
            decl.DeclarationText = AssignedConfigFileData.blueprintRunSequenceDeclarationText;

            impl = (ITcPlcImplementation)currentMethod;
            impl.ImplementationText = AssignedConfigFileData.blueprintRunSequenceImplementationText;

            /*
             * currentMethod = targetModule.CreateChild("eventRaiser", 609, "", methodDescription);
             *
             * //M_EventRaiser
             * decl = (ITcPlcDeclaration)currentMethod;
             * decl.DeclarationText = AssignedConfigFileData.blueprintEventRaiserDeclaration;
             *
             * impl = (ITcPlcImplementation)currentMethod;
             * impl.ImplementationText = eventRaiserImplementation;
             *
             * currentMethod = targetModule.CreateChild("callComponents", 609, "", methodDescription);
             *
             * //M_CallComponents
             * decl = (ITcPlcDeclaration)currentMethod;
             * decl.DeclarationText = AssignedConfigFileData.blueprintCallComponentsDeclaration;
             */
            //-----------------------------------------------------------------------------------------------------------------------
            //-------------------------- Fill the declaration and implementation part of FB_TargetModule with code-------------------
            //-----------------------------------------------------------------------------------------------------------------------

            decl = (ITcPlcDeclaration)targetModule;
            impl = (ITcPlcImplementation)targetModule;

            decl.DeclarationText = Assigner.ReplaceBlueprintValues(
                AssignedConfigFileData.modulesDeclarations[targetIndex],
                new string[] { "@eventManagers", "@moduleName@" },
                new string[] { moduleEventManagerDeclaration, module.getName }
                );

            impl.ImplementationText = Assigner.ReplaceBlueprintValues(
                AssignedConfigFileData.modulesImplementations[targetIndex],
                new string[] { "@eventManagers" },
                new string[] { moduleEventManagerImplementation }
                );
        }
Esempio n. 10
0
        private void CreateEventManagerCode()
        {
            //-----------------------------------------------------------------------------------------------------------------------
            //------------------------------------------------Create the FB_EventManager---------------------------------------------
            //-----------------------------------------------------------------------------------------------------------------------
            foreach (EventManager eventManager in module.content)
            {
                ITcSmTreeItem fbEventManager = eventManagers.CreateChild(eventManager.getName + "EventManager", 604, "1");

                String[] eventNameGroup = eventManager.content.eventNames;

                outEventManagerEvents         = null;
                eventManagerEventsStrings     = null;
                eventDispatcherImplementation = null;
                handlerOperations             = null;
                enumEventDeclaration          = null;
                triggersImplementation        = null;
                foreach (String eventName in eventNameGroup)
                {
                    outEventManagerEvents += "\t" + eventName + "Event : BOOL;\n";

                    if (eventNameGroup.Last() == eventName)
                    {
                        eventManagerEventsStrings += "\t\t'" + eventName + "Event'\n";
                    }
                    else
                    {
                        eventManagerEventsStrings += "\t\t'" + eventName + "Event',\n";
                    }


                    eventDispatcherImplementation += Assigner.ReplaceBlueprintValues(
                        "\n" + AssignedConfigFileData.blueprintEventDispatcherImplementation,
                        new string[] { "@eventManagerName@", "@eventName@" },
                        new string[] { eventManager.getName, eventName }
                        );

                    handlerOperations += Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintHandlerOperation + "\n",
                        new string[] { "@eventManagerName@", "@eventName@", "@moduleName@" },
                        new string[] { eventManager.getName, eventName, module.getName }
                        );

                    enumEventDeclaration += "\t" + eventName + "Event,\n";

                    triggersImplementation += "\t" + eventName + "RTrigger : R_TRIG;" + "\n";
                    //-----------------------------------------------------------------------------------------------------------------------
                    //--------------------------- Create the FB_EventManager eventReceivers -------------------------------------------------
                    //-----------------------------------------------------------------------------------------------------------------------

                    //Implement receivers
                    currentReceiver = fbEventManager.CreateChild(eventName + "Receiver", 611, "", propertyDescription);

                    decl = (ITcPlcDeclaration)currentReceiver;
                    decl.DeclarationText = Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintReceiversDeclaration,
                        new string[] { "@eventName@" },
                        new string[] { eventName }
                        );

                    //Implement getters
                    currentReceiver = currentReceiver.CreateChild("", 613, "", "1");

                    impl = (ITcPlcImplementation)currentReceiver;
                    impl.ImplementationText = Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintReceiversGetterImplementation,
                        new string[] { "@eventManagerName@", "@eventName@" },
                        new string[] { eventManager.getName, eventName }
                        );
                }

                //-----------------------------------------------------------------------------------------------------------------------
                //-------------------------- Create the  E_<X>Event Enumaration ---------------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------

                //605   TREEITEMTYPE_PLCDUTENUM     DUT enum data type
                dut.CreateChild(
                    eventManager.getName + "Event",
                    605, "",
                    Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintEnumEventDeclaration,
                        new string[] { "@eventManagerName@", "@eventNames" },
                        new string[] { eventManager.getName, enumEventDeclaration }
                        )
                    );

                //-----------------------------------------------------------------------------------------------------------------------
                //-------------------------- Create the  EventManager-Structures ----------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------

                dut.CreateChild(
                    eventManager.getName + "EventRecord",
                    606,
                    "",
                    Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintEventRecordDeclaration,
                        new string[] { "@eventManagerName@" },
                        new string[] { eventManager.getName }
                        )
                    );

                //Structure that defines the Event-Triggers that will be used as inputs in the Eventmanager
                eventManagerEventTriggers = dut.CreateChild(
                    eventManager.getName + "EventTriggers",
                    606,
                    "",
                    Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintEventManagerInStruct,
                        new string[] { "@eventManagerName@" },
                        new string[] { eventManager.getName }
                        )
                    );

                decl = (ITcPlcDeclaration)eventManagerEventTriggers;

                index = decl.DeclarationText.IndexOf(keyVarStruct);
                decl.DeclarationText = decl.DeclarationText.Insert(
                    index + (keyVarStruct.Length + 1),
                    triggersImplementation
                    );

                eventManagerEventReceivers = dut.CreateChild(
                    eventManager.getName + "EventReceiver",
                    606,
                    "",
                    Assigner.ReplaceBlueprintValues(
                        AssignedConfigFileData.blueprintEventManagerOutStruct,
                        new string[] { "@eventManagerName@" },
                        new string[] { eventManager.getName }
                        )
                    );

                decl  = (ITcPlcDeclaration)eventManagerEventReceivers;
                index = decl.DeclarationText.IndexOf(keyVarStruct);
                decl.DeclarationText = decl.DeclarationText.Insert(
                    index + (keyVarStruct.Length + 1),
                    outEventManagerEvents
                    );
                //-----------------------------------------------------------------------------------------------------------------------
                //-------------------------- Fill the declaration and implementation part of FB_EventManager with code-------------------
                //-----------------------------------------------------------------------------------------------------------------------
                decl = (ITcPlcDeclaration)fbEventManager;
                impl = (ITcPlcImplementation)fbEventManager;

                decl.DeclarationText = Assigner.ReplaceBlueprintValues(
                    AssignedConfigFileData.blueprintEventManagerDeclaration,
                    new string[] { "@eventManagerName@", "@eventStrings", "@moduleName@" },
                    new string[] { eventManager.getName, eventManagerEventsStrings, module.getName }
                    );


                impl.ImplementationText = AssignedConfigFileData.blueprintEventManagerImplementation;

                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------- Create the FB_EventManager Methods --------------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------

                //M_CheckForRaceCondition
                currentMethod = fbEventManager.CreateChild("checkForRaceCondition", 609, "", methodDescription);

                decl = (ITcPlcDeclaration)currentMethod;
                decl.DeclarationText = AssignedConfigFileData.blueprintRaceConditionDeclaration;

                impl = (ITcPlcImplementation)currentMethod;
                impl.ImplementationText = Assigner.ReplaceBlueprintValues(
                    AssignedConfigFileData.blueprintRaceConditionImplementation,
                    new string[] { "@eventManagerName@" },
                    new string[] { eventManager.getName }
                    );

                //M_EventDispatcher
                currentMethod = fbEventManager.CreateChild("eventDispatcher", 609, "", methodDescription);

                decl = (ITcPlcDeclaration)currentMethod;
                decl.DeclarationText = AssignedConfigFileData.blueprintEventDispatcherDeclaration;

                impl = (ITcPlcImplementation)currentMethod;
                impl.ImplementationText = eventDispatcherImplementation;

                //M_ExecuteHandler
                currentMethod = fbEventManager.CreateChild("executeHandler", 609, "", methodDescription);

                decl = (ITcPlcDeclaration)currentMethod;
                decl.DeclarationText = AssignedConfigFileData.blueprintExecuteHandlerDeclaration;

                impl = (ITcPlcImplementation)currentMethod;
                impl.ImplementationText = Assigner.ReplaceBlueprintValues(
                    AssignedConfigFileData.blueprintExecuteHandlerImplementation,
                    new string[] { "@handlerOperations" },
                    new string[] { handlerOperations }
                    );

                //M_UpdateEventHistory
                currentMethod = fbEventManager.CreateChild("updateEventHistory", 609, "", methodDescription);

                decl = (ITcPlcDeclaration)currentMethod;
                decl.DeclarationText = AssignedConfigFileData.blueprintUpdateEventHistoryDeclaration;


                impl = (ITcPlcImplementation)currentMethod;

                impl.ImplementationText = AssignedConfigFileData.blueprintUpdateEventHistoryImplementation;

                //M_UpdateEventRecord
                currentMethod = fbEventManager.CreateChild("updateEventRecord", 609, "", methodDescription);

                decl = (ITcPlcDeclaration)currentMethod;
                decl.DeclarationText = AssignedConfigFileData.blueprintUpdateEventRecordDeclaration;

                impl = (ITcPlcImplementation)currentMethod;
                impl.ImplementationText = Assigner.ReplaceBlueprintValues(
                    AssignedConfigFileData.blueprintUpdateEventRecordImplementation,
                    new string[] { "@unequal" },
                    new string[] { "<>" }
                    );
                //FB_Init
                currentMethod        = fbEventManager.CreateChild("FB_init", 609, "", methodDescription);
                decl                 = (ITcPlcDeclaration)currentMethod;
                decl.DeclarationText = Assigner.ReplaceBlueprintValues(
                    AssignedConfigFileData.blueprintEventManagerFBInitDeclarationText,
                    new string[] { "@moduleName@" },
                    new string[] { module.getName }
                    );
                impl = (ITcPlcImplementation)currentMethod;
                impl.ImplementationText = Assigner.ReplaceBlueprintValues(
                    AssignedConfigFileData.blueprintEventManagerFBInitImplementationText,
                    new string[] { "@moduleName@" },
                    new string[] { module.getName }
                    );
                //-----------------------------------------------------------------------------------------------------------------------
                //--------------------------- Create the FB_EventManager disable signal -------------------------------------------------
                //-----------------------------------------------------------------------------------------------------------------------
                disableSignal =
                    fbEventManager.
                    CreateChild("disableEventManagerSignal", 611, "", propertyDescription);

                decl = (ITcPlcDeclaration)disableSignal;
                decl.DeclarationText = AssignedConfigFileData.blueprintDisableEventManagerSignalDeclaration;

                //Implement getter
                currentSignal           = disableSignal.CreateChild("", 613, "", "1");
                impl                    = (ITcPlcImplementation)currentSignal;
                impl.ImplementationText = AssignedConfigFileData.blueprintDisableEventManagerSignalGetterImplementation;

                //Implement setter
                currentSignal           = disableSignal.CreateChild("", 614, "", "1");
                impl                    = (ITcPlcImplementation)currentSignal;
                impl.ImplementationText = AssignedConfigFileData.blueprintDisableEventManagerSignalSetterImplementation;

                Console.WriteLine("Code for " + eventManager.getName + "EventManager" + " created.");
            }
        }
Esempio n. 11
0
        public void PLCdeclarations(DataTable dt)
        {
            string mainVar        = @"VAR_GLOBAL" + Environment.NewLine;
            string endMain        = Environment.NewLine + @"          
END_VAR";
            string constDeclStart = @"VAR_GLOBAL CONSTANT" + Environment.NewLine;
            string constDeclEnd   = Environment.NewLine + @"          
END_VAR";

            createDriveStruct();
            System.Threading.Thread.Sleep(3000);
            //Add function blocks to MAIN declaration
            ITcSmTreeItem main      = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project^GVLs");
            ITcSmTreeItem GVL       = main.CreateChild("MDR_Control_FBs", 615, "", 0);
            ITcSmTreeItem StructGVL = main.CreateChild("EP7402_List", 615, "", 0);
            //Cast to specific interface for declaration and implementation area
            ITcPlcDeclaration mainDecl   = (ITcPlcDeclaration)GVL;
            ITcPlcDeclaration structDecl = (ITcPlcDeclaration)StructGVL;



            //Get current declaration and implementation area content
            string strMainDecl   = mainDecl.DeclarationText;
            string strStructDecl = structDecl.DeclarationText;

            //string strMainImpl = mainImpl.ImplementationText;
            _nDriveCount = dt.Rows.Count;
            string[] boxName = new string[_nDriveCount];
            int      j       = 0;
            int      i       = 0;

            string structCount = string.Format(" nDriveCount : UINT := {0};", _nDriveCount);

            for (i = 0; i < _nDriveCount - 1; i++)
            {
                boxName[i] = dt.Rows[j].ItemArray[0].ToString() + j.ToString();
                //Console.WriteLine(boxName[i]);
                j++;
            }


            declarations             = string.Join(": FB_MDR_Control;" + Environment.NewLine, boxName);
            mainDecl.DeclarationText = mainVar + declarations + endMain;

            for (i = 0; i < _nDriveCount - 1; i++)
            {
                boxName[i] = boxName[i].Insert(0, "st");
            }


            declarations = string.Join(": ST_EP7402;" + Environment.NewLine, boxName);
            structDecl.DeclarationText = mainVar + declarations + endMain + Environment.NewLine + constDeclStart + structCount + constDeclEnd;
            createFBCalls(boxName);

            System.Threading.Thread.Sleep(2000);
            var settings = dte.GetObject("TcAutomationSettings");

            settings.SilentMode = true;
            dte.Solution.SolutionBuild.Build(true); // compile the plc project
            settings.SilentMode = false;
        }