public void AddIOConnection(string uniqueID, string connectorPath) { RemoveIOConnection(uniqueID, connectorPath); IOAddress item = ListOfAvailableIOAddress.GetIOAddress(uniqueID); if (item != null) { ListOfIOConnections.Add(new IOConnection(item, connectorPath)); } }
public void Init(XmlNodeList IOConnectionList) { ListOfIOConnections.Clear(); foreach (XmlNode item in IOConnectionList) { string uniqueID = item.SelectSingleNode("UniqueID").InnerText; string connectorPath = item.SelectSingleNode("ConnectorPath").InnerText; IOAddress address = GetAddressItem(uniqueID); if (address != null)//in case of inconsistency e.g. connection with invalide address stored in xref.data { ListOfIOConnections.Add(new IOConnection(address, connectorPath)); } } // reset dirty flag Dirty = false; }
public IOAddressList ParseHWConfigFile(string fileName) { //parse hwconfig and generate a new IO address list IOAddressList newIOAddressList = new IOAddressList(); if (string.IsNullOrEmpty(fileName)) { return(newIOAddressList); } string HWConfigurationPath = fileName; try { XmlDocument doc = new XmlDocument(); doc.Load(HWConfigurationPath); XmlNode root = doc.DocumentElement; XmlNodeList IOAddressList = root.SelectNodes("..//hwModule//properties//moduleSpecificProperties//property//address"); foreach (XmlNode node in IOAddressList) { IOAddress newAddress = new IOAddress(); newAddress.SymbolicName = node.ParentNode.SelectSingleNode("value").InnerText; newAddress.DisplayName = node.ParentNode.SelectSingleNode("displayName").InnerText; //obsolete //newAddress.AddressType = node.Attributes["dataType"].Value; newAddress.VMEAddress = node.SelectSingleNode("vmeBusAddress").InnerText; newAddress.UniqueID = node.SelectSingleNode("uniqueAddressID").InnerText; newAddress.AllowedCPUTypes = node.SelectSingleNode("allowedCPUTypes").InnerText.Split(new char[] { ';' }).ToList(); newAddress.AllowedFunctionBlockTypes = node.SelectSingleNode("allowedFunctionBlockTypes").InnerText.Split(new char[] { ';' }).ToList(); newAddress.AllowedVMESlots = node.SelectSingleNode("allowedVMESlots").InnerText.Split(new char[] { ';' }).ToList(); //find in "commonProperties" a property named "Name" and take as the ProviderName XmlNodeList commonProperties = node.ParentNode.ParentNode.ParentNode.SelectNodes("commonProperties//property"); foreach (XmlNode commonProperty in commonProperties) { if (commonProperty.Attributes["name"].Value == "Name") { newAddress.ProviderName = commonProperty.SelectSingleNode("value").InnerText; break; } } newIOAddressList.Add(newAddress); } //mapping cpu name to slot number mapOfSlotToCPU.Clear(); XmlNodeList moduleList = root.SelectNodes("..//hwModule"); foreach (XmlNode module in moduleList) { XmlNodeList commonPropertyList = module.SelectNodes("properties//commonProperties//property"); string CPUName = string.Empty; string slotNumber = string.Empty; foreach (XmlNode commonProperty in commonPropertyList) { if (commonProperty.Attributes["name"].Value.Equals("Name")) { CPUName = commonProperty.SelectSingleNode("value").InnerText; } if (commonProperty.Attributes["name"].Value.Equals("Slot")) { slotNumber = commonProperty.SelectSingleNode("value").InnerText; } } if (!slotNumber.Equals(string.Empty) && !CPUName.Equals(string.Empty) && !mapOfSlotToCPU.ContainsKey(CPUName)) { mapOfSlotToCPU.Add(CPUName, slotNumber); } } return(newIOAddressList); } catch (Exception) { return(newIOAddressList); } }
public IOConnection(IOAddress address, string connectorPath) { Address = address; ConnectorPath = connectorPath; }
public bool SetHWConfigFile(string fileName) { if (proxyOfHWConfig == null) { return(false); } if (string.IsNullOrEmpty(fileName)) { return(false); } try { IOAddressList newIOAddressList = proxyOfHWConfig.ParseHWConfigFile(fileName); Dictionary <string, IOAddress> newIOAddressDic = newIOAddressList.ToDictionary(); IOAddress[] listOfAvailableIOAddress = ListOfAvailableIOAddress.ToArray <IOAddress>(); foreach (var ioAddress in listOfAvailableIOAddress) { if (newIOAddressDic.ContainsKey(ioAddress.UniqueID)) { // still exist IOAddress newAddress = newIOAddressDic[ioAddress.UniqueID]; newIOAddressDic.Remove(ioAddress.UniqueID); if (ListOfAvailableIOAddress.InsertNewIOAddress(newAddress)) { if (IOAddressChanged != null && IsAddressUsed(ioAddress.UniqueID)) { IOAddressChanged(newAddress.ToString() + " is updated."); } } } else { // removed ListOfAvailableIOAddress.Remove(ioAddress); if (IOAddressChanged != null && IsAddressUsed(ioAddress.UniqueID)) { IOAddressChanged(ioAddress.ToString() + " is not valid any more."); } // remove connection(s) of this IOAddress(by UniqueID) var connections = ListOfIOConnections.Where(a => a.Address.UniqueID == ioAddress.UniqueID); foreach (var conn in connections) { ListOfIOConnections.Remove(conn); } } } //add new IO addresses into the list foreach (var rest in newIOAddressDic.Values) { ListOfAvailableIOAddress.InsertNewIOAddress(rest); } return(true); } catch (Exception ee) { Trace.WriteLine("###[" + ee.Message + "]; Exception : " + ee.Source); Trace.WriteLine("###" + ee.StackTrace); } return(false); }