/// <summary> /// Returns a Collection of all ExternalSourceFiles in the PlcSoftware /// </summary> /// <param name="plcSoftware">PlcSoftware to be searched</param> /// <returns>Collection of ExternalSourceFiles</returns> /// <exception cref="System.ArgumentNullException">Parameter is null;PlcSoftware</exception> public static IEnumerable <PlcExternalSource> GetAllPlcExternalSourceFiles(PlcSoftware plcSoftware) { if (plcSoftware == null) { throw new ArgumentNullException(nameof(plcSoftware), "Parameter is null"); } var collection = new Collection <object>(); RecursiveGetAllElements(plcSoftware.ExternalSourceGroup, ref collection); return(collection.Cast <PlcExternalSource>()); }
/// <summary> /// Searches recursively through the PlcSoftware to find the block with given name. /// </summary> /// <param name="plcSoftware">PlcSoftware to be searched</param> /// <param name="blockName">Name to be searched for</param> /// <returns>Reference to found block</returns> /// <exception cref="System.ArgumentNullException">Parameter is null;PlcSoftware</exception> /// <exception cref="System.ArgumentException">Parameter is null or empty;blockName</exception> public static PlcBlock FindBlockByName(PlcSoftware plcSoftware, string blockName) { if (plcSoftware == null) { throw new ArgumentNullException(nameof(plcSoftware), "Parameter is null"); } if (string.IsNullOrEmpty(blockName)) { throw new ArgumentException("Parameter is null or empty", nameof(blockName)); } return(RecursiveFindElementByName(plcSoftware.BlockGroup, blockName) as PlcBlock); }
/// <summary> /// Searches recursively through the PlcSoftware to find the PlcType with given name. /// </summary> /// <param name="plcSoftware">PlcSoftware to be searched</param> /// <param name="datatypeName">Name to be searched for</param> /// <returns>Reference to found PlcTagTable</returns> /// <exception cref="System.ArgumentNullException">Parameter is null;PlcSoftware</exception> /// <exception cref="System.ArgumentException">Parameter is null or empty;datatypeName</exception> public static PlcType FindPlcTypeByName(PlcSoftware plcSoftware, string datatypeName) { if (plcSoftware == null) { throw new ArgumentNullException(nameof(plcSoftware), "Parameter is null"); } if (string.IsNullOrEmpty(datatypeName)) { throw new ArgumentException("Parameter is null or empty", nameof(datatypeName)); } return(RecursiveFindElementByName(plcSoftware.TypeGroup, datatypeName) as PlcType); }
/// <summary> /// Returns a TreeView of all PlcTypes in the PlcSoftware /// </summary> /// <param name="plcSoftware">PlcSoftware to be searched</param> /// <returns>TreeView of PlcTypes</returns> /// <exception cref="System.ArgumentNullException">Parameter is null;PlcSoftware</exception> public static TreeViewItem GetDatatypesTreeView(PlcSoftware plcSoftware) { if (plcSoftware == null) { throw new ArgumentNullException(nameof(plcSoftware), "Parameter is null"); } var collection = new TreeViewItem(); RecursiveGetTreeView(plcSoftware.TypeGroup, ref collection); return(collection); }
//Imports user data type private static void ImportUserDataType(PlcSoftware plcSoftware) { try { FileInfo fullFilePath = new FileInfo(@"C:\testUDT\udt.xml"); PlcTypeComposition types = plcSoftware.TypeGroup.Types; IList <PlcType> importedTypes = types.Import(fullFilePath, ImportOptions.Override); } catch (Exception ex) { MessageBox.Show("Chyba: " + ex.Message); } }
public static string CompileCodeBlock(PlcSoftware plcSoftware) { string message = null; CodeBlock block = plcSoftware.BlockGroup.Blocks.Find("MyCodeBlock") as CodeBlock; if (block != null) { ICompilable compileService = block.GetService <ICompilable>(); CompilerResult result = compileService.Compile(); message = WriteCompilerResults(result); } return(message); }
/// <summary> /// Returns a Collection of Blocks with the specified Programming language /// </summary> /// <param name="plcSoftware">PlcSoftware to be searched</param> /// <param name="language">Programming language to search for</param> /// <returns>Collection of matching blocks</returns> /// <exception cref="System.ArgumentNullException">Parameter is null;PlcSoftware</exception> public static IEnumerable <PlcBlock> FindBlocksByLanguage(PlcSoftware plcSoftware, ProgrammingLanguage language) { if (plcSoftware == null) { throw new ArgumentNullException(nameof(plcSoftware), "Parameter is null"); } var ret = new Collection <PlcBlock>(); RecursiveFindBlocksByLanguage(plcSoftware.BlockGroup, language, ref ret); return(ret); }
/// <summary> /// Searches recursively through the PlcSoftware to find the PlcTagTable with given name. /// </summary> /// <param name="plcSoftware">PlcSoftware to be searched</param> /// <param name="tagTableName">Name to be searched for</param> /// <returns>Reference to found PlcTagTable</returns> /// <exception cref="System.ArgumentNullException">Parameter is null;PlcSoftware</exception> /// <exception cref="System.ArgumentException">Parameter is null or empty;tagTableName</exception> public static PlcTagTable FindPlcTagTableByName(PlcSoftware plcSoftware, string tagTableName) { if (plcSoftware == null) { throw new ArgumentNullException(nameof(plcSoftware), "PlcSoftware"); } if (string.IsNullOrEmpty(tagTableName)) { throw new ArgumentException("Parameter is null or empty", nameof(tagTableName)); } return(RecursiveFindElementByName(plcSoftware.TagTableGroup, tagTableName) as PlcTagTable); }
private void Compile(object sender, EventArgs e) { btn_CompileHW.Enabled = false; string devname = txt_Device.Text; bool found = false; foreach (Device device in MyProject.Devices) { DeviceItemComposition deviceItemAggregation = device.DeviceItems; foreach (DeviceItem deviceItem in deviceItemAggregation) { if (deviceItem.Name == devname || device.Name == devname) { SoftwareContainer softwareContainer = deviceItem.GetService <SoftwareContainer>(); if (softwareContainer != null) { if (softwareContainer.Software is PlcSoftware) { PlcSoftware controllerTarget = softwareContainer.Software as PlcSoftware; if (controllerTarget != null) { found = true; ICompilable compiler = controllerTarget.GetService <ICompilable>(); CompilerResult result = compiler.Compile(); txt_Status.Text = "Compiling of " + controllerTarget.Name + ": State: " + result.State + " / Warning Count: " + result.WarningCount + " / Error Count: " + result.ErrorCount; } } if (softwareContainer.Software is HmiTarget) { HmiTarget hmitarget = softwareContainer.Software as HmiTarget; if (hmitarget != null) { found = true; ICompilable compiler = hmitarget.GetService <ICompilable>(); CompilerResult result = compiler.Compile(); txt_Status.Text = "Compiling of " + hmitarget.Name + ": State: " + result.State + " / Warning Count: " + result.WarningCount + " / Error Count: " + result.ErrorCount; } } } } } } if (found == false) { txt_Status.Text = "Found no device with name " + txt_Device.Text; } btn_CompileHW.Enabled = true; }
//****************************Export_IMport_UDT********************************************** //Exports a user defined type private static void ExportUserDefinedType(PlcSoftware plcSoftware) { try { string udtname = "udt"; PlcTypeComposition types = plcSoftware.TypeGroup.Types; PlcType udt = types.Find(udtname); udt.Export(new FileInfo(string.Format(@"C:\testUDT\" + udt.Name + ".xml")), ExportOptions.WithDefaults); } catch (Exception ex) { MessageBox.Show("Chyba: " + ex.Message); } }
//Exports a regular block private static void ExportRegularBlock(PlcSoftware plcSoftware) { try { foreach (PlcBlock block in plcSoftware.BlockGroup.Blocks) { block.Export(new FileInfo(string.Format(@"C:\test\" + block.Name + ".xml")), ExportOptions.WithDefaults); } } catch (Exception ex) { MessageBox.Show("Chyba: " + ex.Message); } }
void AddDevice(Project project) { btn_AddHW.Enabled = false; string MLFB = "OrderNumber:" + txt_OrderNo.Text + "/" + txt_Version.Text; string name = txt_AddDevice.Text; string devname = "station" + txt_AddDevice.Text; bool found = false; foreach (Device device in project.Devices) { foreach (DeviceItem deviceItem in device.DeviceItems) { if (deviceItem.Name == devname || device.Name == devname) { SoftwareContainer softwareContainer = deviceItem.GetService <SoftwareContainer>(); if (softwareContainer != null) { if (softwareContainer.Software is PlcSoftware) { PlcSoftware controllerTarget = softwareContainer.Software as PlcSoftware; if (controllerTarget != null) { found = true; } } if (softwareContainer.Software is HmiTarget) { HmiTarget hmitarget = softwareContainer.Software as HmiTarget; if (hmitarget != null) { found = true; } } } } } } if (found == true) { txt_Status.Text = "Device " + txt_Device.Text + " already exists"; } else { Device deviceName = project.Devices.CreateWithItem(MLFB, name, devname); txt_Status.Text = "Add Device Name: " + name + " with Order Number: " + txt_OrderNo.Text + " and Firmware Version: " + txt_Version.Text; } btn_AddHW.Enabled = true; }
public static PlcSoftware GetPlcSoftware(Device device) //gets Plc SW of the device { // var allDeviceItems = device.DeviceItems; //also can use DeviceItemComppsition = var foreach (DeviceItem deviceItem in device.DeviceItems) { SoftwareContainer softwareContainer = deviceItem.GetService <SoftwareContainer>(); if (softwareContainer != null) { Software softwareBase = softwareContainer.Software; PlcSoftware plcSoftware = softwareBase as PlcSoftware; return(plcSoftware); } } return(null); }
public static string Compile(Project project, int index) //to compile all project { var allDevices = project.Devices; Device device = DeviceMethods.GetDevice(project, index); string message = null; PlcSoftware plcSoftware = DeviceItemMethods.GetPlcSoftware(device); //software message = CompileMethods.CompilePlcSoftware(plcSoftware); message += CompileMethods.CompileCodeBlock(plcSoftware); //HmiTarget hmiTarget = DeviceItemMethods.GetHmiTarget(device); //hardware //message += CompileMethods.CompileHmiTarget(hmiTarget); return(message); }
static private PlcSoftware GetPlcSoftware(Device device) { DeviceItemComposition deviceItemComposition = device.DeviceItems; foreach (DeviceItem deviceItem in deviceItemComposition) { SoftwareContainer softwareContainer = deviceItem.GetService <SoftwareContainer>(); if (softwareContainer != null) { Software softwareBase = softwareContainer.Software; PlcSoftware plcSoftware = softwareBase as PlcSoftware; return(plcSoftware); } } return(null); }
// close project private void btnClose_Click(object sender, EventArgs e) { if (project != null) { listBox1.Items.Clear(); listBox2.Items.Clear(); treeView1.Nodes.Clear(); txtProject.Text = "Project: "; //project.Save(); project.Close(); software = null; project = null; } }
private void menuSofwareAdd_Click(object sender, EventArgs e) { PlcSoftware soft = (PlcSoftware)treeView1.SelectedNode.Tag; PlcBlockGroup group = soft.BlockGroup; string name = string.Empty; DialogResult dlg = Input.InputBox("Enter new group name", "New group", ref name); if (dlg == DialogResult.OK) { if (name != string.Empty) { group.Groups.Create(name); IterateThroughDevices(project); } } }
private void btn_hmi_tags_Click(object sender, EventArgs e) { PlcSoftware plc = null; if (!find_plc(projectTreeView.Nodes, ref plc)) { MessageBox.Show("More than one PLC is selected"); return; } if (plc == null) { MessageBox.Show("No PLC is selected"); return; } HmiTarget hmi = null; if (!find_hmi(projectTreeView.Nodes, ref hmi)) { MessageBox.Show("More than one HMI device is selected"); return; } if (hmi == null) { MessageBox.Show("No HMI device is selected"); return; } ConstantLookup constants = new ConstantLookup(); try { constants.Populate(tiaPortal, plc); } catch (Exception ex) { MessageBox.Show("Failed to build lookup table for user constants: " + ex.Message); return; } HMItagBuilder hmi_tags = new HMItagBuilder(tiaPortal, plc, hmi, constants); hmi_tags.ShowDialog(); }
public CopySelection(TiaPortal portal, PlcSoftware plc, HmiTarget hmi) { this.portal = portal; this.plc = plc; this.hmi = hmi; InitializeComponent(); btn_copy.Enabled = false; fromTreeView.AfterCheck += node_AfterCheck; toTreeView.AfterCheck += node_AfterCheck; worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.WorkerReportsProgress = true; worker.RunWorkerCompleted += Worker_RunWorkerCompleted; worker.DoWork += Worker_DoWork; worker.ProgressChanged += Worker_ProgressChanged; worker.RunWorkerAsync(); }
private static void ExportSystemBlocks(PlcSoftware plcsoftware) { try { PlcBlockGroup sbSystemGroup = plcsoftware.BlockGroup; foreach (PlcBlockGroup group in sbSystemGroup.Groups) { foreach (PlcBlock block in group.Blocks) { block.Export(new FileInfo(string.Format(@"C:\test\" + block.Name + ".xml")), ExportOptions.WithDefaults); } } } catch (Exception ex) { MessageBox.Show("Chyba: " + ex); } }
private static void ExportBlocks(PlcSoftware software) { string name = software.Name; Console.WriteLine(name); foreach (PlcBlock block in software.BlockGroup.Blocks) { HandleBlock(block, software); } foreach (PlcBlockGroup blockGroup in software.BlockGroup.Groups) { Console.WriteLine("Handling block group " + blockGroup.Name); foreach (PlcBlock block in blockGroup.Blocks) { HandleBlock(block, software); } } }
//Imports tag tables to the tag system group private static void ImportTagTable(PlcSoftware plcSoftware) { try { PlcTagTableSystemGroup plcTagTableSystemGroup = plcSoftware.TagTableGroup; PlcTagTableComposition tagTables = plcTagTableSystemGroup.TagTables; string[] files = Directory.GetFiles(@"C:\testTables\", "*", SearchOption.AllDirectories); foreach (var file in files) { tagTables.Import(new FileInfo(file), ImportOptions.Override); } } catch (Exception ex) { MessageBox.Show("Chyba: " + ex.Message); } }
//Import blocks private static void ImportBlocks(PlcSoftware plcSoftware, string path) { try { // PlcBlockGroup blockGroup = plcSoftware.BlockGroup; // IList<PlcBlock> blocks = blockGroup.Blocks.Import(new FileInfo(path), ImportOptions.Override); PlcBlockGroup blockGroup = plcSoftware.BlockGroup; string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); foreach (var block in files) { IList <PlcBlock> blocks = blockGroup.Blocks.Import(new FileInfo(block), ImportOptions.Override); } } catch (Exception ex) { MessageBox.Show("Chyba: " + ex.Message); } }
// we need to enumerate through the tree since there is no function in the API? public bool NameExists(string Name, PlcSoftware Software) { List <string> list = new List <string>(); list = GetAllBlocksNames(Software.BlockGroup, list); if (list.Contains(Name)) { return(true); } list = new List <string>(); list = GetAllDataTypesNames(Software.TypeGroup, list); if (list.Contains(Name)) { return(true); } return(false); }
private void closeToolStripMenuItem_Click(object sender, EventArgs e) { if (project != null) { SaveProject(); listBox1.Items.Clear(); listBox2.Items.Clear(); treeView1.Nodes.Clear(); txtProject.Text = "Project: "; txtSaved.Text = "..."; project.Close(); software = null; project = null; } }
private void btn_preset_Click(object sender, EventArgs e) { PlcSoftware plc = null; if (!find_plc(projectTreeView.Nodes, ref plc)) { MessageBox.Show("More than one PLC is selected"); return; } if (plc == null) { MessageBox.Show("No PLC is selected"); return; } List <HmiTarget> hmis = new List <HmiTarget>(); find_hmis(projectTreeView.Nodes, ref hmis); presetGenerate = new PresetGenerate(tiaPortal, plc.BlockGroup, hmis, culture); presetGenerate.ShowDialog(); }
public static void InsertBlocksFromSclSource(PlcSoftware plcSoftware, string sourceName, string sourcePath) { // Create source var source = plcSoftware.ExternalSourceGroup.ExternalSources.FirstOrDefault(obj => obj.Name.Equals(sourceName)); if (source == null) { Console.WriteLine("Load SCL sources..."); source = plcSoftware.ExternalSourceGroup.ExternalSources.CreateFromFile(sourceName, sourcePath); } // Create block from source PlcBlock block = plcSoftware.BlockGroup.Blocks.FirstOrDefault(obj => obj.Name.Equals(sourceName)); if (block == null) { Console.WriteLine("Generate block..."); GenerateBlockOption options = GenerateBlockOption.KeepOnError; source.GenerateBlocksFromSource(options); } }
public new void Save() { Device currentDevice = AllDevices[0]; CentralFSourceAddress_attribue = Service.Get1ValueAndDeviceItemWithAttribute(currentDevice.DeviceItems, "Failsafe_CentralFSourceAddress"); LowerBoundForFDestinationAddresses_attribues = Service.Get1ValueAndDeviceItemWithAttribute(currentDevice.DeviceItems, "Failsafe_LowerBoundForFDestinationAddresses"); UpperBoundForFDestinationAddresses_attribues = Service.Get1ValueAndDeviceItemWithAttribute(currentDevice.DeviceItems, "Failsafe_UpperBoundForFDestinationAddresses"); //xFDestinationAddress_attribues = Service.GetValueAndDeviceItemsWithAttribute(currentDevice.DeviceItems, "Failsafe_FDestinationAddress"); try { originalSubnet = FirstPnNetworkInterfaces[0].Nodes[0].ConnectedSubnet; originalIoSystem = FirstPnNetworkInterfaces[0].IoConnectors[0].ConnectedToIoSystem; } catch (EngineeringTargetInvocationException) { } //GetAll_I_DeviceParnerAdresses(); plcSoftware = Service.GetPlcSoftware(currentDevice); GetAllToConnections(); }
private static void EnumeratePlcDataTypeGroup(PlcTypeUserGroup typeGroup, PlcSoftware plcsoftware, string path) { if (typeGroup.Name.EndsWith("Test")) { return; } path += typeGroup.Name + "\\"; Directory.CreateDirectory(path); foreach (var plcType in typeGroup.Types) { plcsoftware.ExternalSourceGroup.GenerateSource(new List <PlcType> { plcType }, new FileInfo(path + plcType.Name + ".udt")); } foreach (PlcTypeUserGroup typeSubGroup in typeGroup.Groups) { EnumeratePlcDataTypeGroup(typeSubGroup, plcsoftware, path); } }
private void btn_preset_import_Click(object sender, EventArgs e) { PlcSoftware plc = null; if (!find_plc(projectTreeView.Nodes, ref plc)) { MessageBox.Show("More than one PLC is selected"); return; } if (plc == null) { MessageBox.Show("No PLC is selected"); return; } if (loadPresetList.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Dictionary <string, PresetGroup> preset_groups; try { PresetDocument.Load(loadPresetList.FileName, out preset_groups, culture); } catch (Exception ex) { MessageBox.Show("Failed to load presets from file " + loadPresetList.FileName + ": " + ex.Message); return; } try { UpdatePresetValues(plc, preset_groups); } catch (Exception ex) { MessageBox.Show("Failed to update presets loaded from file " + loadPresetList.FileName + ": " + ex.Message); return; } } }