Esempio n. 1
0
        public IOAddressManager(string projectPath)
        {
            this.ProjectPath = projectPath;

            ListOfAvailableIOAddress = new IOAddressList();
            ListOfIOConnections      = new IOConnectionList();

            proxyOfHWConfig = new HWConfigurationProxy(ProjectPath);

            #region Get Hardware Config File of Project

            string hwConfigFile = null;

            // Search in project file
            try
            {
                string[] files = System.IO.Directory.GetFiles(projectPath, @"*.VAR");
                if (files != null && files.Count() > 0)
                {
                    IniFile iniFile = new IniFile(files[0]);
                    hwConfigFile = iniFile.GetValueS("STATION", "FILE0");
                    if (!string.IsNullOrEmpty(hwConfigFile))
                    {
                        hwConfigFile = projectPath.PathCombine(hwConfigFile + ".hwconfig");
                    }
                }
            }
            catch (Exception)
            {
            }

            // Search .hwconfig file
            if (string.IsNullOrEmpty(hwConfigFile))
            {
                try
                {
                    string[] files = System.IO.Directory.GetFiles(projectPath, @"*.hwconfig");
                    if (files != null && files.Count() > 0)
                    {
                        hwConfigFile = files[0];
                    }
                }
                catch (Exception)
                {
                }
            }

            #endregion

            this.SetHWConfigFile(hwConfigFile);

            // reset dirty flag
            Dirty = false;
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
 public void GetIOAddressList(ref IOAddressList list)
 {
     list = ListOfAvailableIOAddress;
 }
Esempio n. 4
0
        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);
        }