private static void iterDataBlock(NodeHandler handler, IBlockAggregation blocks) { foreach (IBlock block in blocks) { handleDataBlock(handler, block); } }
public List <ProjectBlockInfo> readPlcBlocksList() { if (_blockInfos != null) { return(_blockInfos); } IBlockAggregation blocks = null; var o = this.TiaPortalItem as ProgramblockUserFolder; if (o != null) { blocks = o.Blocks; } var q = this.TiaPortalItem as ProgramblockSystemFolder; if (q != null) { blocks = q.Blocks; } _blockInfos = new List <ProjectBlockInfo>(); foreach (var block in blocks) { var info = new TIAOpennessProjectBlockInfo() { Name = block.Name, IBlock = block, ParentFolder = this }; if (block.Type == BlockType.DB) { info.BlockType = DataTypes.PLCBlockType.DB; } else if (block.Type == BlockType.FB) { info.BlockType = DataTypes.PLCBlockType.FB; } else if (block.Type == BlockType.FC) { info.BlockType = DataTypes.PLCBlockType.FC; } else if (block.Type == BlockType.OB) { info.BlockType = DataTypes.PLCBlockType.OB; } else if (block.Type == BlockType.UDT) { info.BlockType = DataTypes.PLCBlockType.UDT; } info.BlockNumber = block.Number; _blockInfos.Add(info); } return(_blockInfos); }
private void alarmDefsToolStripMenuItem_Click(object sender, EventArgs e) { if (tiaPortal != null) { if (folder_dialog == null) { folder_dialog = new BrowseDialog(tiaPortal); folder_dialog.Descend = TIATree.ControllerOnly; folder_dialog.Leaf = (o => o is IBlockAggregation); folder_dialog.AutoExpandMaxChildren = 1; folder_dialog.AcceptText = "Generate"; folder_dialog.Text = "Select where to generate block"; } if (folder_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (folder_dialog.SelectedObject is IBlockAggregation) { IBlockAggregation folder = (IBlockAggregation)folder_dialog.SelectedObject; string filename = AlarmDB.buildFile(defs); try { folder.Import(filename, ImportOptions.Override); } catch (Siemens.Engineering.EngineeringException ex) { MessageBox.Show(this, "Failed to import alarm definitions: " + ex.Message); System.IO.File.Delete(filename); return; } System.IO.File.Delete(filename); // Move up the tree until we find a ControllerTarget IEngineeringObject obj = folder.Parent; while (!(obj is ControllerTarget)) { obj = obj.Parent; // Shouldn't happen, but just in case if (obj == null) { MessageBox.Show(this, "No controller found as parent"); return; } } ControllerTarget controller = (ControllerTarget)obj; List <ConstTable.Constant> consts = new List <ConstTable.Constant>(); foreach (AlarmDefinition alarm in defs) { consts.Add(new ConstTable.Constant("Alarm" + alarm.Name, alarm.ID, alarm.Text)); } filename = ConstTable.buildFile("Alarms", consts); try { controller.ControllerTagFolder.TagTables.Import(filename, ImportOptions.Override); } catch (Siemens.Engineering.EngineeringException ex) { MessageBox.Show(this, "Failed to import constants: " + ex.Message); System.IO.File.Delete(filename); return; } System.IO.File.Delete(filename); } } } }