private Software GetDevice(Project project, string MLFB, string name, string devname) { foreach (Device device in project.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) { return(softwareContainer.Software as PlcSoftware); } if (softwareContainer.Software is HmiTarget) { return(softwareContainer.Software as HmiTarget); } } } } } return(null); }
private static void IterDeviceItem(NodeHandler handler, DeviceItemComposition items) { foreach (DeviceItem item in items) { handleDeviceItem(handler, item); } }
private static void IterDeviceItem(IList <HmiTarget> hmi, DeviceItemComposition items) { foreach (DeviceItem item in items) { handleDeviceItem(hmi, item); } }
public static IList <DeviceItem> GetDeviceItemsWithAttribute(DeviceItemComposition aDeviceItems, string aAttributeName, string aAttributeValue) { List <DeviceItem> returnDeviceItems = new List <DeviceItem>(); IList <DeviceItem> addDeviceItems; if (aDeviceItems != null) { foreach (DeviceItem currentDeviceItem in aDeviceItems) { try { string attributeValue = currentDeviceItem.GetAttribute(aAttributeName).ToString(); if ((attributeValue == aAttributeValue) || (aAttributeValue == "*")) { returnDeviceItems.Add(currentDeviceItem); } } catch (EngineeringNotSupportedException) { } catch (Exception ex) { Program.FaultMessage("Could not get Attribute", ex, "Service.GetDeviceItemsWithAttribute"); } //check sub DeviceItems - recursive addDeviceItems = GetDeviceItemsWithAttribute(currentDeviceItem.DeviceItems, aAttributeName, aAttributeValue); returnDeviceItems.AddRange(addDeviceItems); } } return(returnDeviceItems); }
/// <summary> /// Nutzen Sie diese Methode, um alle TIA DeviceItems in eine Liste<DeviceItem> zu schreiben /// </summary> /// <param name="project"></param> /// <returns></returns> public void EnumerateDeviceItem(Project project, List <DeviceItem> list_deviceItem) { list_deviceItem.Clear(); //Alte Elemente löschen foreach (Device device in project.Devices) { DeviceItemComposition deviceItemAggregation = device.DeviceItems; foreach (DeviceItem deviceItem in deviceItemAggregation) { list_deviceItem.Add(deviceItem); } } }
private void btn_AddHW_Click(object sender, EventArgs e) { 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 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; } } 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 = MyProject.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; }
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; }
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); }
public static IList <AttributeAndAddress> GetValueAndAddressWithAttribute(DeviceItemComposition aDeviceItems, string aAttributeName) { List <AttributeAndAddress> returnDeviceItems = new List <AttributeAndAddress>(); IList <AttributeAndAddress> addDeviceItems; if (aDeviceItems != null) { foreach (DeviceItem currentDeviceItem in aDeviceItems) { addDeviceItems = GetValueAndAddressWithAttribute(currentDeviceItem.Addresses, aAttributeName); returnDeviceItems.AddRange(addDeviceItems); addDeviceItems = GetValueAndAddressWithAttribute(currentDeviceItem.DeviceItems, aAttributeName); returnDeviceItems.AddRange(addDeviceItems); } } return(returnDeviceItems); }
public static AttributeAndDeviceItem Get1ValueAndDeviceItemWithAttribute(DeviceItemComposition aDeviceItems, string aAttributeName) { AttributeAndDeviceItem returnDeviceItem; if (aDeviceItems != null) { foreach (DeviceItem currentDeviceItem in aDeviceItems) { try { object attributeValue = currentDeviceItem.GetAttribute(aAttributeName); returnDeviceItem = new AttributeAndDeviceItem(); returnDeviceItem.Name = aAttributeName; returnDeviceItem.Value = attributeValue; returnDeviceItem.DeviceItem = currentDeviceItem; return(returnDeviceItem); } catch (EngineeringNotSupportedException) { } catch (Exception ex) { Program.FaultMessage("Could not get Attribute", ex, "Service.Get1ValueAndDeviceItemWithAttribute"); } //check sub DeviceItems - recursive returnDeviceItem = Get1ValueAndDeviceItemWithAttribute(currentDeviceItem.DeviceItems, aAttributeName); if (returnDeviceItem != null) { return(returnDeviceItem); } } } return(null); }
void GetHWAddInfo(Project project, TreeView tv_item) { string devname = tv_item.SelectedNode.Text; foreach (Device device in project.Devices) { //Attribute für Geräte/Geräteelemente var typeidentifier = "TypeIdentifier"; //var ordernumber = "OrderNumber"; var typename = "TypeName"; //Achtung bei GSD Device funktioniert Typename nicht var name = "Name"; DeviceItemComposition deviceItemAggregation = device.DeviceItems; foreach (DeviceItem deviceItem in deviceItemAggregation) { if (deviceItem.Name == devname) { object attributeNamesInfo = ((IEngineeringObject)deviceItem).GetAttribute(typename); txt_addHwInfoDevice.Text = attributeNamesInfo.ToString(); object attributeValueDeviceItem = ((IEngineeringObject)deviceItem).GetAttribute(typeidentifier); txt_addHwInfoDeviceItem.Text = attributeValueDeviceItem.ToString(); //object ordernumberInfo = ((IEngineeringObject)deviceItem).GetAttribute(ordernumber); //txt_addHwInfo3.Text = ordernumberInfo.ToString(); } else if (device.Name == devname) { object attributeValueDevice1 = ((IEngineeringObject)device).GetAttribute(name); txt_addHwInfoDevice.Text = attributeValueDevice1.ToString(); object attributeValueDevice2 = ((IEngineeringObject)device).GetAttribute(typeidentifier); txt_addHwInfoDeviceItem.Text = attributeValueDevice2.ToString(); } } } }
void RemoveCheckedNodes(TreeNodeCollection nodes, Project project) { foreach (TreeNode node in nodes) { if (node != null) { if (node.Checked) //Projektknoten { checkedNodes.Add(node); //Markierte Knoten werden der jeweiligen Liste hinzugefügt } else { foreach (TreeNode node1 in node.Nodes) { if (node1.Checked) //Deviceknoten { checkedNodes.Add(node1); //Markierte Knoten werden der jeweiligen Liste hinzugefügt } else { foreach (TreeNode node2 in node1.Nodes) { if (node2.Checked) //DeviceItemknoten { checkedNodes.Add(node2); //Markierte Knoten werden der jeweiligen Liste hinzugefügt } } } } } } } foreach (TreeNode checkedNode in checkedNodes) { if (checkedNode != null) { string devname = checkedNode.Text; //Device/DeviceItem Name von TreeView Auswahl foreach (Device device in project.Devices) // Schreibt alle zu löschenden Devices/DeviceItems in eine Liste { DeviceItemComposition deviceItemAggregation = device.DeviceItems; foreach (DeviceItem deviceItem in deviceItemAggregation) { if (deviceItem.Name == devname) { checkedDeviceItems1.Add(deviceItem); } } if (device.Name == devname) { checkedDevices1.Add(device); } } } nodes.Remove(checkedNode); //Ausgewählten Knoten im TreeView löschen } for (int i = 0; i < checkedDevices1.Count(); i++) // Löscht die Devices aus der Liste { Device deviceToDelete = checkedDevices1[checkedDevices1.Count() - 1 - i]; deviceToDelete.Delete(); //Ausgewähltes Device im TIA löschen } for (int u = 0; u < checkedDeviceItems1.Count(); u++) // Löscht die DeviceItems aus der Liste { DeviceItem deviceItemToDelete = checkedDeviceItems1[checkedDeviceItems1.Count() - 1 - u]; deviceItemToDelete.Delete(); //Ausgewähltes DeviceItem im TIA löschen } //Listenelemente löschen nach Iteration checkedDeviceItems1.Clear(); checkedDevices1.Clear(); checkedNodes.Clear(); }
public static IList <AttributeAndDeviceItem> GetValueAndDeviceItemsWithAttribute(DeviceItemComposition aDeviceItems, string aAttributeName) { List <AttributeAndDeviceItem> returnDeviceItems = new List <AttributeAndDeviceItem>(); IList <AttributeAndDeviceItem> addDeviceItems; if (aDeviceItems != null) { foreach (DeviceItem currentDeviceItem in aDeviceItems) { try { object attributeValue = currentDeviceItem.GetAttribute(aAttributeName); AttributeAndDeviceItem newItem = new AttributeAndDeviceItem(); newItem.Name = aAttributeName; newItem.Value = attributeValue; newItem.DeviceItem = currentDeviceItem; returnDeviceItems.Add(newItem); } catch (EngineeringNotSupportedException) { } catch (Exception ex) { Program.FaultMessage("Could not get Attribute", ex, "Service.GetValueAndDeviceItemsWithAttribute"); } //check sub DeviceItems - recursive addDeviceItems = GetValueAndDeviceItemsWithAttribute(currentDeviceItem.DeviceItems, aAttributeName); returnDeviceItems.AddRange(addDeviceItems); } } return(returnDeviceItems); }