Example #1
0
        /// <summary>
        /// Stops the PLC, assuming that you already have a running PLC.
        /// </summary>
        public Boolean stopPLC()
        {
            Console.WriteLine("Stopping " + project.Name);
            ITcSysManager4 systemManager = (ITcSysManager4)(project.Object);

            if (!systemManager.IsTwinCATStarted())
            {
                Console.WriteLine("No Twincat project running!!");
                return(false);
            }

            ITcSmTreeItem plcApp = getPLCApp(systemManager);

            System.Threading.Thread.Sleep(1000);
            if (!login(plcApp))
            {
                return(false);
            }

            System.Threading.Thread.Sleep(1000);
            Console.WriteLine("Stopping PLC");
            plcApp.ConsumeXml(createXMLString(PLCAction.STOP));

            if (!checkWithTimeout(COMMAND_TIMEOUT, () => checkXmlIsString(plcApp, "PlcAppState", "Stop")))
            {
                Console.WriteLine("Failed to stop!");
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Checks that a solution contains at least one PLC project and starts the project running.
        /// </summary>
        public Boolean startPLC()
        {
            Console.WriteLine("Starting " + project.Name);
            ITcSysManager4 systemManager = (ITcSysManager4)(project.Object);

            ITcSmTreeItem plcApp = getPLCApp(systemManager);

            System.Threading.Thread.Sleep(1000);
            if (!login(plcApp))
            {
                return(false);
            }

            if (isRunning(plcApp))
            {
                Console.WriteLine("PLC is running");
                return(true);
            }

            System.Threading.Thread.Sleep(1000);
            Console.WriteLine("Starting PLC");
            plcApp.ConsumeXml(createXMLString(PLCAction.START));

            if (!checkWithTimeout(COMMAND_TIMEOUT, () => isRunning(plcApp)))
            {
                Console.WriteLine("Failed to start!");
                return(false);
            }

            return(true);
        }
Example #3
0
 /// <summary>
 /// Checks that a solution contains at least one PLC project.
 /// </summary>
 /// <returns>The project that can be run</returns>
 public Project findPLCProject()
 {
     foreach (Project project in solution.Projects)
     {
         try
         {
             ITcSysManager4 twinCatProject = (ITcSysManager4)project.Object;
             ITcSmTreeItem  plcConfig      = twinCatProject.LookupTreeItem("TIPC");
             ITcPlcProject  iecProjectRoot = (ITcPlcProject)plcConfig.Child[1]; // Assume you want to run the first PLC project
             iecProjectRoot.BootProjectAutostart = true;
             iecProjectRoot.GenerateBootProject(true);
             Console.WriteLine("Found PLC Project: " + project.Name + "." + plcConfig.Name);
             return(project);
         } catch {
             Console.WriteLine(project.Name + " is not a Twincat project");
         }
     }
     return(null);
 }
        protected override void OnSolutionCreated()
        {
            string projectTemplate = null;

            if (string.IsNullOrEmpty(_context.ProjectTemplate))
            {
                projectTemplate = VsXaeTemplatePath;
            }
            else
            {
                projectTemplate = Path.Combine(ApplicationDirectory, _context.ProjectTemplate);
            }

            bool exists = File.Exists(projectTemplate);

            this.project       = (Project)CreateNewProject(this.ScriptName, projectTemplate);
            this.systemManager = (ITcSysManager4)project.Object;
            //base.OnSolutionCreated();
        }
Example #5
0
        /// <summary>
        /// Checks that a solution contains at least one PLC project and activates the configuration.
        /// </summary>
        public Boolean activatePLC()
        {
            Console.WriteLine("Simulating " + project.Name);
            ITcSysManager4 systemManager = (ITcSysManager4)(project.Object);

            Console.WriteLine("Activating Config");
            systemManager.ActivateConfiguration();
            System.Threading.Thread.Sleep(500);

            Console.WriteLine("Starting twinCAT");
            systemManager.StartRestartTwinCAT();
            System.Threading.Thread.Sleep(1000);

            if (!checkWithTimeout(START_TWINCAT_TIMEOUT, systemManager.IsTwinCATStarted))
            {
                Console.WriteLine("Twincat not starting, check that you have valid licenses!!");
                return(false);
            }

            return(true);
        }
Example #6
0
        /// <summary>
        /// Get the PLC App, assuming only one PLC.
        /// </summary>
        /// <param name="systemManager">The system manager to get the app from.</param>
        /// <returns>The PLC app</returns>
        private ITcSmTreeItem getPLCApp(ITcSysManager4 systemManager)
        {
            IEnumerable <ITcSmTreeItem> plcConfigs = systemManager.LookupTreeItem("TIPC").Child[1].Cast <ITcSmTreeItem>();

            return(plcConfigs.Where(child => child.ItemSubTypeName == "TREEITEMTYPE_PLCAPP").Single());
        }