public SolutionHandler(string filePath, string FileName) { this.BASEFOLDER = filePath; this._solutionName = _tcProjectName = FileName; this.adsClient = new TcAdsClient(); MessageFilter.Register(); /* ----------------------------------------------------------------- * Creates new solution based off of TwinCAT's XAE and PLC templates. * -----------------------------------------------------------------*/ if (dte == null) { CreateNewProject(); } pro = sol.Projects.Item(1); sysMan = (ITcSysManager11)pro.Object; //System.Threading.Thread.Sleep(5000); ITcSmTreeItem plc = sysMan.LookupTreeItem("TIPC"); plc.CreateChild("Untitled1", 0, "", "Standard PLC Template"); //---Navigate to References node and cast to Library Manager interface ITcSmTreeItem references = sysMan.LookupTreeItem("TIPC^Untitled1^Untitled1 Project^References"); ITcPlcLibraryManager libraryManager = (ITcPlcLibraryManager)this.RetrieveLibMan(); /* ------------------------------------------------------ * Check to see if library already exists, if it does it will delete before adding to avoid any exceptions. * ------------------------------------------------------ */ foreach (ITcPlcLibRef libraryReference in libraryManager.References) { if (libraryReference is ITcPlcLibrary) { ITcPlcLibrary library = (ITcPlcLibrary)libraryReference; if (library.Name == "MDR_Control") { DeleteLibrary(ref libraryManager); } } } /* ------------------------------------------------------ * Add our MDR library to the project References. * ------------------------------------------------------ */ AddLibrary(ref libraryManager); MessageFilter.Revoke(); }//Constructor()
//This contructor is meant to be used for testing individual methods //It should never be called in a live use public SolutionHandler() { dte = attachToExistingDte(@"C:\Users\NathanM\Desktop\DELETE ME\Garth Gaddy\TestDirectory\Test4.sln", ProgID); sol = dte.Solution; pro = sol.Projects.Item(1); sysMan = (ITcSysManager11)pro.Object; adsClient = new TcAdsClient(); ITcSmTreeItem drive = sysMan.LookupTreeItem(@"TIID^Device_1^InfeedWest0"); LinkIoToPlc(drive); }
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; }