private ITcSmTreeItem createPou(POUInfo pouInfo, ITcSmTreeItem parent, IWorker worker, XmlDocument doc) { XmlNode pouNode = doc.SelectSingleNode("TcPlcObject/POU"); string pouName = pouNode.Attributes["Name"].Value; worker.ProgressStatus = string.Format("Creating POU '{0}' ...", pouName); ITcSmTreeItem item = null; if (!TryLookupChild(parent, pouName, out item)) { item = parent.CreateChild(pouName, TreeItemType.PlcPouFunctionBlock.AsInt32(), "", null); } // some items need to be casted to a more special interface to gain access to all of their methods and properties, for example POUs which need // to be casted to the interface ITcPlcPou to get access to their unique methods and properties. ITcPlcPou pou = (ITcPlcPou)item; pou.DocumentXml = doc.OuterXml; // get/set PLC code of a POU in XML Format 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); }