예제 #1
0
 public AutomationInterface(EnvDTE.Project project)
 {
     sysManager     = (ITcSysManager10)project.Object;
     configManager  = (ITcConfigManager)sysManager.ConfigurationManager;
     plcTreeItem    = sysManager.LookupTreeItem(Constants.PLC_CONFIGURATION_SHORTCUT);
     routesTreeItem = sysManager.LookupTreeItem(Constants.RT_CONFIG_ROUTE_SETTINGS_SHORTCUT);
 }
예제 #2
0
        public void setupTestCrate()
        {
            DialogResult dialogResult;

            //Check solution not empty

            if (String.IsNullOrEmpty(SlnPath))
            {
                MessageBox.Show("You have not selected a solution folder", "Oopsie", MessageBoxButtons.OK);
                return;
            }
            //CHECK CONFIG NOT EMPTY FIRST!!!
            if (ConfigFolder == @"\Config")
            {
                MessageBox.Show("You have not selected a configuration folder", "Oopsie", MessageBoxButtons.OK);
                return;
            }

            //If no open project, load the selected one
            if (solution == null)
            {
                openSolution();
            }
            else //check we have a message filter as using already open project
            {
                if (!MessageFilter.IsRegistered)
                {
                    MessageFilter.Register();
                }
            }

            //populate the "project" object
            Project = grabSolutionProject();
            //Check we successfully got the project
            if (Project == null)
            {
                MessageBox.Show("Failed to load in project");
                cleanUp();
                return;
            }


            //User prompt to connect to hardware
            dialogResult = MessageBox.Show(@"Connect to test crate." + Environment.NewLine + "Once connected press OK to confirm or cancel to exit the automated setup", "Time for a break", MessageBoxButtons.OKCancel);
            if (dialogResult == DialogResult.Cancel)
            {
                cleanUp();
                return;
            }

            //Set target platform, we are using TwinCAT RT (x64), PLC will not build if this does not match the build method argument later.
            ITcConfigManager configManager = (ITcConfigManager)SystemManager.ConfigurationManager;

            configManager.ActiveTargetPlatform = "TwinCAT RT (x64)";


            //Solution loaded and project loaded
            //Next task: add NC and parameterise

            //Check if an NC task exists, create if not (task exists in default tc_generic code)
            try
            {
                //Look for existing NC Task
                SystemManager.LookupTreeItem("TINC").Child[1].LookupChild("Axes");
            }
            catch
            {
                //Add NC Task
                createNcTask();
            }


            //Check whether the project already has axes and prompt user
            if (getAxisCount() != 0)
            {
                dialogResult = MessageBox.Show("Axes already exists in this solution. Do you want to remove them?", "Time for a break", MessageBoxButtons.YesNoCancel);
                if (dialogResult == DialogResult.Cancel)
                {
                    cleanUp();
                    return;
                }
                if (dialogResult == DialogResult.Yes)
                {
                    deleteAxes();
                }
            }
            //Add axes equal to number of xml files in the NC folder
            // addNcAxes(getNcXmlCount());
            addNamedNcAxes();

            //Check whether the project already has IO in it and prompt user
            if (getIoCount() != 0)
            {
                dialogResult = MessageBox.Show("Hardware already exists in this solution. Do you want to remove this?", "Time for a break", MessageBoxButtons.YesNoCancel);
                if (dialogResult == DialogResult.Cancel)
                {
                    MessageFilter.Revoke();
                    return;
                }
                if (dialogResult == DialogResult.Yes)
                {
                    deleteIo();
                }
            }
            //Add the IO from a CSV file
            importIoList();
            //Run through all device xmls and import
            importAllIoXmls();
            MessageBox.Show("IO XML Import complete");
            //Setup axis parameters from available axis xmls
            ncConsumeAllMaps();
            MessageBox.Show("NC Parameter import complete");
            //Add the plc "stuff"
            plcImportDeclarations();
            MessageBox.Show("PLC declarations updated");
            //New PLC "stuff" to add
            importApplications();
            MessageBox.Show("Application Specific PROGs imported");
            importAxes();
            MessageBox.Show("Axis PROGs imported");
            setupProgAction();
            MessageBox.Show("PROG action updated");
            buildPlcProject();
            MessageBox.Show("PLC compiled");
            importXmlMap();
            MessageBox.Show("Import mappings complete");

            try
            {
                //SystemManager.ActivateConfiguration();
            }
            catch
            {
                cleanUp();
                throw new ApplicationException("Unable to activate configuration");
            }
            cleanUp();
            MessageBox.Show("Success!");
        }