private void PortalSelect_Load(object sender, EventArgs e) { listBox1.Items.Clear(); List <ProcItem> items = new List <ProcItem>(); tiaThread.RunSync((_) => { foreach (TiaPortalProcess proc in TiaPortal.GetProcesses()) { FileInfo proj = proc.ProjectPath; string path = null; if (proj != null) { path = proj.Name; } if (path == null) { path = "No project loaded"; } ProcItem item = new ProcItem(proc, path); items.Add(item); } return(null); }, null); foreach (ProcItem item in items) { listBox1.Items.Add(item); listBox1.SetSelected(0, true); } connectBtn.Enabled = (listBox1.SelectedItem != null); }
public static void OpenProjectOnly(string ProjectPath, ref TiaPortal tiaPortal, ref Project project) { Console.WriteLine("Starting TIA Portal"); try { tiaPortal = new TiaPortal(TiaPortalMode.WithoutUserInterface); } catch (Exception e) { Program.CancelGeneration("Could not start TIAP.", e); return; } Console.WriteLine("TIA Portal has started"); ProjectComposition projects = tiaPortal.Projects; Console.WriteLine("Opening Project..."); FileInfo projectPath = new FileInfo(ProjectPath); //edit the path according to your project //Project project = null; try { project = projects.Open(projectPath); } catch (Exception e) { Program.CancelGeneration("Could not open project " + projectPath.FullName, e); return; } }
public BuildTask(TreeNodeBuilder builder, TreeNodeCollection nodes, TiaPortal tia) { this.builder = builder; this.nodes = nodes; this.TIA = tia; handler = new HandlerAsync(this); }
public static void AttachToTIA(string ProjectPath, ref TiaPortal tiaPortal, ref Project project) { foreach (TiaPortalProcess tiaPortalProcess in TiaPortal.GetProcesses()) { string currentProjectPath = ((tiaPortalProcess.ProjectPath != null && !string.IsNullOrEmpty(tiaPortalProcess.ProjectPath.FullName)) ? Path.GetFullPath(tiaPortalProcess.ProjectPath.FullName) : "None"); Console.WriteLine("tiaPortalProcess: " + tiaPortalProcess.Mode); Console.WriteLine("ProjectPath: " + currentProjectPath); Console.WriteLine(""); //string currentProject = ((tiaPortalProcess.ProjectPath != null && !string.IsNullOrEmpty(tiaPortalProcess.ProjectPath.FullName)) ? tiaPortalProcess.ProjectPath.FullName : "None"); if (currentProjectPath == ProjectPath) { Console.WriteLine("Attaching to TIA Portal"); try { tiaPortal = tiaPortalProcess.Attach(); project = tiaPortal.Projects[0]; } catch (Siemens.Engineering.EngineeringSecurityException e) { Program.CancelGeneration("Could not attach to running TIAP with open project.", e); project = null; } catch (Exception e) { Program.CancelGeneration("Could not attach to running TIAP with open project.", e); project = null; } return; } } }
public static void Handle(NodeHandler handler, TiaPortal tia) { foreach (Project p in tia.Projects) { handleProject(handler, p); } }
public CreateHmiPresetConstantTagsTask(TiaPortal portal, TagFolder folder, ConstantLookup constants) { this.portal = portal; this.folder = folder; this.constants = constants; Description = "Update HMI preset constant table " + PRESET_CONSTANT_TABLE_NAME; }
public static Project CreateProjectIfNotExists(TiaPortal tiaPortal, string projectFullPath) { Project project; // Open if (File.Exists(projectFullPath)) { FileInfo fileInfo = new FileInfo(projectFullPath); project = tiaPortal.Projects.FirstOrDefault(obj => obj.Path.FullName.Equals(projectFullPath)); if (project == null) { project = tiaPortal.Projects.Open(fileInfo); } } // Create else { string projectName = Path.GetFileNameWithoutExtension(projectFullPath); var directory = Path.GetDirectoryName(projectFullPath); DirectoryInfo directoryInfo = new DirectoryInfo(directory ?? throw new InvalidOperationException()); project = tiaPortal.Projects.Create(directoryInfo, projectName); } return(project); }
public void OpenGlobalLibrary(TiaPortal tiaportal, TextBox txt_box) { try { var availableLibraries = tiaportal.GlobalLibraries.GetGlobalLibraryInfos(); foreach (GlobalLibraryInfo info in availableLibraries) { txt_box.Text = "Library Name: " + info.Name + Environment.NewLine + "Library Path: " + info.Path + Environment.NewLine + "Library Type: " + info.LibraryType + Environment.NewLine + "Library IsOpen: " + info.IsOpen; } //Bibliotheken öffnen (funktioniert bisher nicht) //Bibliothek mittels System.IO.FileInfo öffnen FileInfo fileInfo = new FileInfo(@"D:\Program Files\Siemens\Automation\Portal V15\lib\Sys\Long Functions\Long Functions.as15"); //GlobalLibrary userLib = tiaportal.GlobalLibraries.Open(fileInfo, OpenMode.ReadWrite); ////---------------------------------- ////Bibliothek mittels GlobalLibraryInfo öffnen //IList<GlobalLibraryInfo> libraryInfos = tiaportal.GlobalLibraries.GetGlobalLibraryInfos(); //GlobalLibraryInfo libInfo = libraryInfos[0]; //check for the info you need from the list, e.g. //GlobalLibrary libraryOpenedWithInfo; //if (libInfo.Name == "myLibrary") // libraryOpenedWithInfo = tiaportal.GlobalLibraries.Open(libInfo); } catch (Exception e) { MessageBox.Show(e.Message); } }
public bool CurrentProject(TiaPortalProcess tiaProcess, TiaPortal _MyTiaPortal, Project _MyProject) { bool ProjectStatus; IList <TiaPortalProcess> processes = TiaPortal.GetProcesses(); switch (processes.Count) { case 1: tiaProcess = processes[0]; _MyTiaPortal = tiaProcess.Attach(); if (_MyTiaPortal.Projects.Count <= 0) { ProjectStatus = false; return(ProjectStatus); } _MyProject = _MyTiaPortal.Projects[0]; ProjectStatus = true; break; case 0: ProjectStatus = false; return(ProjectStatus); default: ProjectStatus = false; return(ProjectStatus); } return(ProjectStatus); }
private void connectToolStripMenuItem_Click(object sender, EventArgs e) { if (select_dialog == null) { select_dialog = new PortalSelect(tiaThread); } if (select_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { TiaPortalProcess proc = select_dialog.selectedProcess(); if (proc != null) { WaitConnect wait = new WaitConnect(); wait.Show(); Application.DoEvents(); try { tiaPortal = (TiaPortal)tiaThread.RunSync((_) => { return(proc.Attach()); }, null); connectToolStripMenuItem.Enabled = false; btn_connect.Enabled = false; disconnectToolStripMenuItem.Enabled = true; btn_disconnect.Enabled = true; PortalConnected(); } catch (EngineeringException ex) { MessageBox.Show("Failed to connect to TIAPortal: " + ex.Message); } wait.Hide(); wait.Dispose(); } } }
public SelectHMI(TiaPortal portal) { tiaPortal = portal; InitializeComponent(); VisibleChanged += updateList; itemTree.MouseDoubleClick += treeDoubleClick; }
private void AksForInstance() { tiaPortal = new Siemens.Engineering.TiaPortal(Siemens.Engineering.TiaPortalMode.WithoutUserInterface); var processes = TiaPortal.GetProcesses().ToArray(); var sLst = processes.Select(x => "Projekt : " + (x.ProjectPath != null ? x.ProjectPath.ToString() : "-")).ToArray(); AppDomain domain = AppDomain.CreateDomain("another domain"); CrossAppDomainDelegate action = () => { var app = new Application(); var ask = new SelectPortalInstance(); var p = AppDomain.CurrentDomain.GetData("processes") as string[]; ask.lstInstances.ItemsSource = p; app.Run(ask); AppDomain.CurrentDomain.SetData("idx", ask.lstInstances.SelectedIndex); }; domain.SetData("processes", sLst); domain.DoCallBack(action); var idx = (int)domain.GetData("idx"); tiaPortal = processes[idx].Attach(); tiapProject = tiaPortal.Projects[0]; this.ProjectFile = processes[idx].ProjectPath.ToString(); }
internal void LoadViaOpennessDlls() { tiaPortal = new TiaPortal(TiaPortalMode.WithoutUserInterface); tiapProject = tiaPortal.Projects.Open(ProjectFile); var main = new TIAOpennessProjectFolder(this) { Name = "Main" }; ProjectStructure = main; foreach (var d in tiapProject.Devices) { if (d.Subtype.StartsWith("S7300") || d.Subtype.StartsWith("S7400")) { var fld = new TIAOpennessProjectFolder(this) { Name = d.Name, Comment = d.Comment != null?d.Comment.GetText(CultureInfo.CurrentCulture) : null }; main.SubItems.Add(fld); LoadSubDevicesViaOpennessDlls(fld, d); } } // switch (tiaType) //{ // case "Siemens.Automation.DomainModel.ProjectData": // fld = new TIAProjectFolder(this, Node); // break; // case "Siemens.Automation.DomainModel.FolderData": // { // var subType = Node.SelectSingleNode("attribSet[@id='" + CoreAttributesId + "']/attrib[@name='Subtype']").InnerText; // if (subType == "ProgramBlocksFolder" || subType == "ProgramBlocksFolder.Subfolder") // { // fld = new TIABlocksFolder(this, Node); // } // else // { // fld = new TIAProjectFolder(this, Node); // } // break; // } // case "Siemens.Simatic.HwConfiguration.Model.DeviceData": // fld = new TIAProjectFolder(this, Node); // break; // case "Siemens.Simatic.HwConfiguration.Model.S7ControllerTargetData": // fld = new TIACPUFolder(this, Node); // break; // case "Siemens.Automation.DomainModel.EAMTZTagTableData": // fld = new TIASymTabFolder(this, Node); // break; // //case "Siemens.Simatic.PlcLanguages.Model.DataBlockData": // // fld = new TIAProjectFolder(this, Node); // // break; // default: // break; //} }
protected override void ProcessRecord() { base.ProcessRecord(); TiaPortalMode pmode = (mode ? TiaPortalMode.WithUserInterface : TiaPortalMode.WithoutUserInterface); TiaPortal tp = new TiaPortal(pmode); WriteObject(tp); }
public CreatePlcCompileTask(TiaPortal portal, PlcSoftware plc) { this.portal = portal; this.plc = plc; Description = "Complie PLC software for " + plc.Name; }
public BrowseDialog(TiaPortal portal) { InitializeComponent(); AutoExpandMaxChildren = -1; builder = new TIATree.TreeNodeBuilder(portal); VisibleChanged += updateList; blockTree.MouseDoubleClick += treeDoubleClick; }
public WorkerArg(TiaPortal portal, IEngineeringCompositionOrObject top, ParseCtxt ctxt) { this.portal = portal; this.top = top; this.ctxt = ctxt; }
public HMItagBuilder(TiaPortal portal, PlcSoftware plc, HmiTarget hmi, ConstantLookup constants) { this.portal = portal; this.plc = plc; this.hmi = hmi; this.constants = constants; btn_run.Enabled = false; FindDB(); }
public CreateHmiTagsFromBlockTask(TiaPortal portal, PlcBlock block, TagFolder folder, string function, ConstantLookup constants) { this.portal = portal; this.folder = folder; this.block = block; this.function = function; this.constants = constants; Description = "Update HMI tag table " + function + " for block " + block.Name; }
public CopyPlcTypeTask(TiaPortal portal, PlcType from, PlcSoftware to, bool overwrite) { this.portal = portal; fromType = from; toPlc = to; this.overwrite = overwrite; Selected = true; Description = "Copy type " + from.Name + " to " + to.Name; }
public CopyPlcBlockTask(TiaPortal portal, PlcBlock from, PlcSoftware to, bool overwrite) { this.portal = portal; fromBlock = from; toPlc = to; this.overwrite = overwrite; Selected = true; Description = "Copy block " + from.Name + " to " + to.Name; }
private void btn_ConnectTIA(object sender, EventArgs e) { btn_Connect.Enabled = false; IList <TiaPortalProcess> processes = TiaPortal.GetProcesses(); switch (processes.Count) { case 1: _tiaProcess = processes[0]; MyTiaPortal = _tiaProcess.Attach(); if (MyTiaPortal.GetCurrentProcess().Mode == TiaPortalMode.WithUserInterface) { rdb_WithUI.Checked = true; } else { rdb_WithoutUI.Checked = true; } if (MyTiaPortal.Projects.Count <= 0) { txt_Status.Text = "No TIA Portal Project was found!"; btn_Connect.Enabled = true; return; } MyProject = MyTiaPortal.Projects[0]; break; case 0: txt_Status.Text = "No running instance of TIA Portal was found!"; btn_Connect.Enabled = true; return; default: txt_Status.Text = "More than one running instance of TIA Portal was found!"; btn_Connect.Enabled = true; return; } txt_Status.Text = _tiaProcess.ProjectPath.ToString(); btn_Start.Enabled = false; btn_Connect.Enabled = true; btn_Dispose.Enabled = true; btn_CompileHW.Enabled = true; btn_CloseProject.Enabled = true; btn_SearchProject.Enabled = false; btn_Save.Enabled = true; btn_AddHW.Enabled = true; btnCreateProject.Enabled = false; btnExportBlocks.Enabled = true; btnExportTagTables.Enabled = true; btnImportBlock.Enabled = true; btnImportTagTables.Enabled = true; btnImportUDT.Enabled = true; btnExportUDT.Enabled = true; btnHWConfig.Enabled = true; }
public BrowseDialog(TIAAsyncWrapper thread, TiaPortal portal) { InitializeComponent(); AutoExpandMaxChildren = -1; builder = new TIATree.TreeNodeBuilder(thread, portal); builder.BuildDone += TreeDone; VisibleChanged += UpdateList; FormClosing += FormClosingEventHandler; blockTree.MouseDoubleClick += TreeDoubleClick; }
private void disconnectToolStripMenuItem_Click(object sender, EventArgs e) { tiaPortal.Dispose(); tiaPortal = null; folder_dialog = null; data_block_dialog = null; browse_dialog = null; connectToolStripMenuItem.Enabled = true; disconnectToolStripMenuItem.Enabled = false; }
public CreatePresetRecallBlockTask(TiaPortal portal, IList <PresetTag> tags, PlcBlockGroup blockGroup, string blockName, string value_type_name, string enable_type_name) { this.portal = portal; this.tags = tags; this.resultGroup = blockGroup; this.valueTypeName = value_type_name; this.enableTypeName = enable_type_name; this.blockName = blockName; Description = "Create recall SCL block " + blockName; }
public CreatePresetScreenPopupTask(TiaPortal portal, IList <PresetTag> tags, ScreenPopupFolder folder, XmlDocument templates, string popup_name, string group_name) { this.portal = portal; this.tags = tags; this.folder = folder; this.templates = templates; popupName = popup_name; groupName = group_name; Description = "Create preset popup screen " + popupName; }
/// <summary> /// Constructor w/Paramateres /// </summary> /// <param name="libraries"></param> /// <param name="worksheets"></param> /// <param name="tiaPortal"></param> /// <param name="tiaPortalProject"></param> public HardwareGeneratorViewModel(string networkListPath, string eplanPath, TiaPortal tiaPortal, Project tiaPortalProject) { Initialize(); this.tiaPortal = tiaPortal; this.tiaPortalProject = tiaPortalProject; this.networkListPath = networkListPath; this.eplanPath = eplanPath; PopulateTreeView(); PopulateLibs(); }
public PresetGenerate(TiaPortal portal, IEngineeringCompositionOrObject top, List <HmiTarget> hmiTargets, string culture) { InitializeComponent(); tiaPortal = portal; FormClosing += FormClosingEventHandler; presetListView.AutoGenerateColumns = false; presetList = new PresetTagList { Culture = culture }; presetListView.DataSource = presetList; writeButton.Enabled = false; exportButton.Enabled = false; parser = new TagParser(portal); parser.HandleTag += HandleTag; parser.ParseDone += ParseDone; parser.ParseAsync(top, log); IEngineeringCompositionOrObject node = top; while (node.Parent is PlcBlockGroup) { node = node.Parent; } PlcBlockGroup top_group = (PlcBlockGroup)node; resultGroup = top_group.Groups.Find("Preset"); if (resultGroup == null) { resultGroup = top_group.Groups.Create("Preset"); } while (node != null && !(node is PlcSoftware)) { node = node.Parent; } if (node == null) { throw new Exception("No PlcSoftware node found"); } plcSoftware = (PlcSoftware)node; typeGroup = plcSoftware.TypeGroup.Groups.Find("Preset"); if (typeGroup == null) { typeGroup = plcSoftware.TypeGroup.Groups.Create("Preset"); } this.hmiTargets = hmiTargets; Project proj = tiaPortal.Projects[0]; LanguageAssociation langs = proj.LanguageSettings.ActiveLanguages; cultureComboBox.Items.Clear(); cultureComboBox.Items.AddRange(langs.Select(l => l.Culture.Name).ToArray()); cultureComboBox.SelectedItem = culture; }
private void PortalSelect_Load(object sender, EventArgs e) { listBox1.Items.Clear(); foreach (TiaPortalProcess proc in TiaPortal.GetProcesses()) { ProcItem item = new ProcItem(proc); listBox1.Items.Add(item); listBox1.SetSelected(0, true); } connectBtn.Enabled = (listBox1.SelectedItem != null); }
private void AksForInstanceWithFilename(string file) { tiaPortal = new Siemens.Engineering.TiaPortal(Siemens.Engineering.TiaPortalMode.WithoutUserInterface); var processes = TiaPortal.GetProcesses().ToArray(); var process = processes.First(x => x.ProjectPath != null && x.ProjectPath.FullName == file); tiaPortal = process.Attach(); tiapProject = tiaPortal.Projects[0]; this.ProjectFile = process.ProjectPath.ToString(); }
internal void LoadViaOpennessDlls() { for (int i = 0; i < 10; i++) { try { if (tiaPortal != null) { tiaPortal.Dispose(); tiaPortal = null; } tiaPortal = new TiaPortal(TiaPortalMode.WithoutUserInterface); tiapProject = tiaPortal.Projects.Open(ProjectFile); } catch (Siemens.Engineering.EngineeringSecurityException ex) { throw; } catch (Exception ex) { if (i == 9) throw; } if (tiapProject != null) break; } var main = new TIAOpennessProjectFolder(this) { Name = "Main" }; ProjectStructure = main; //var frm = new sliver.Windows.Forms.StateBrowserForm(); //frm.ObjectToBrowse = tiapProject; //frm.Show(); foreach (var d in tiapProject.Devices) { Console.WriteLine(d.Subtype); if (d.Subtype.EndsWith(".Device") && !d.Subtype.StartsWith("GSD.") && !d.Subtype.StartsWith("ET200eco.")) //d.Subtype.StartsWith("S7300") || d.Subtype.StartsWith("S7400") || d.Subtype.StartsWith("S71200") || d.Subtype.StartsWith("S71500")) { var controller = d.DeviceItems.OfType<ControllerTarget>().FirstOrDefault(); if (controller == null) { var fld = new TIAOpennessProjectFolder(this) { Name = d.Name, TiaPortalItem = d, Comment = d.Comment != null ? d.Comment.GetText(CultureInfo.CurrentCulture) : null }; main.SubItems.Add(fld); LoadSubDevicesViaOpennessDlls(fld, d); } else { var fld = new TIAOpennessControllerFolder(this) { Name = d.Name, TiaPortalItem = d, Comment = d.Comment != null ? d.Comment.GetText(CultureInfo.CurrentCulture) : null }; main.SubItems.Add(fld); LoadControlerFolderViaOpennessDlls(fld, controller); } } } }
public TreeNodeBuilder(TiaPortal tia) { TIA = tia; }
private void connectToolStripMenuItem_Click(object sender, EventArgs e) { if (select_dialog == null) { select_dialog = new PortalSelect(); } if (select_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { TiaPortalProcess proc = select_dialog.selectedProcess(); if (proc != null) { WaitConnect wait = new WaitConnect(); wait.Show(); Application.DoEvents(); try { tiaPortal = proc.Attach(); connectToolStripMenuItem.Enabled = false; disconnectToolStripMenuItem.Enabled = true; } catch (EngineeringException ex) { MessageBox.Show("Failed to connect to TIAPortal: " + ex.Message); } wait.Hide(); wait.Dispose(); } } }