コード例 #1
0
        /// <summary>
        /// Расчет идентификаторов для базы каналов
        /// </summary>
        private static void CalculateIdentificatorsForChannelBase(
            TreeNode subtype, XmlElement elm, XmlNamespaceManager nsmgr,
            string baseId, List <string> subTypesId, XmlDocument xmlDoc)
        {
            const int maxTagsCount = 65535;
            string    xpath        = "//subtypes:subtype[subtypes:sdrvname='" +
                                     subtype.Text + "']";
            var subElm = elm.SelectSingleNode(xpath, nsmgr) as XmlElement;

            if (subElm != null)
            {
                nsmgr.AddNamespace("channels", "http://brestmilk.by/channels/");
                var channelsElm = subElm.ChildNodes[9] as XmlElement;
                var channelsId  = new List <long>();
                foreach (TreeNode channel in subtype.Nodes)
                {
                    XmlNode tagNode = null;
                    foreach (XmlNode node in channelsElm.ChildNodes)
                    {
                        if (node.InnerText.Contains(channel.Text))
                        {
                            tagNode = node;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (tagNode == null)
                    {
                        // Нахождение адреса канала среди свободных
                        if (channelsId.Count == 0)
                        {
                            long beginId = long
                                           .Parse((long.Parse(baseId).ToString("X2") +
                                                   long.Parse(subElm.ChildNodes[0].InnerText)
                                                   .ToString("X2") + "0000"),
                                                  System.Globalization.NumberStyles.HexNumber);
                            for (int i = 0; i < maxTagsCount; i++)
                            {
                                channelsId.Add(beginId + i);
                            }

                            foreach (XmlElement channId in channelsElm
                                     .ChildNodes)
                            {
                                long id = long.Parse(
                                    channId.FirstChild.InnerText);
                                if (channelsId.Contains(id))
                                {
                                    channelsId.Remove(id);
                                }
                            }
                        }

                        long channelId = channelsId[0];
                        channelsId.RemoveAt(0);
                        AddChannel(xmlDoc, channel, channelsElm, channelId);
                    }
                }
            }
            else
            {
                if (subTypesId.Count > 0)
                {
                    long subtypeId = long.Parse(subTypesId[0]);
                    subTypesId.RemoveAt(0);
                    XmlElement newSubtype = AddSubType(xmlDoc, elm, subtype,
                                                       subtypeId);
                    string hex = long.Parse(baseId).ToString("X2") +
                                 subtypeId.ToString("X2");
                    for (int i = 0; i < subtype.Nodes.Count; i++)
                    {
                        long channelId = long.Parse((hex + i.ToString("X4")),
                                                    System.Globalization.NumberStyles.HexNumber);
                        AddChannel(xmlDoc, subtype.Nodes[i], newSubtype,
                                   channelId);
                    }
                }
                else
                {
                    Logs.AddMessage("Превышено количество подтипов " +
                                    "в базе каналов.");
                    return;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Сохранить описание проекта
        /// </summary>
        /// <param name="param">Параметры</param>
        public static void Save(object param)
        {
            var par = param as ParametersForSave;

            if (!par.silentMode)
            {
                Logs.Show();
                Logs.DisableButtons();
                Logs.SetProgress(0);
            }

            try
            {
                try
                {
                    if (!Directory.Exists(par.path))
                    {
                        Directory.CreateDirectory(par.path);
                    }
                }
                catch (DriveNotFoundException)
                {
                    if (!par.silentMode)
                    {
                        Logs.AddMessage("Ошибка подключения к диску с " +
                                        "проектами. Подключите диск!");
                        Logs.SetProgress(100);
                    }
                    return;
                }

                SaveIOFile(par);

                if (par.silentMode == false)
                {
                    Logs.SetProgress(50);
                }

                SaveTechObjectsFile(par);
                SaveTechDevicesFile(par);
                SaveRestrictionsFile(par);
                SaveMainFile(par);
                SaveModbusFile(par);
                SaveProfibusFile(par);
                SavePrgFile(par);

                if (par.silentMode == false)
                {
                    if (!Logs.IsEmpty())
                    {
                        Logs.AddMessage("Done.");
                        Logs.ShowLastLine();
                    }
                    else
                    {
                        Logs.Hide();
                    }
                }
            }
            catch (Exception ex)
            {
                if (par.silentMode == false)
                {
                    Logs.AddMessage("Exception - " + ex);
                    Logs.AddMessage("");
                    Logs.AddMessage("");
                    Logs.ShowLastLine();
                }
            }
            finally
            {
                if (!par.silentMode && Logs.IsNull() == false)
                {
                    Logs.EnableButtons();
                    Logs.SetProgress(100);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Формирование общей структуры базы каналов
        /// </summary>
        private static XmlElement WriteCommonXMLPart(XmlDocument xmlDoc)
        {
            string     nsDriver     = "http://brestmilk.by/driver/";
            string     prefixDriver = "driver";
            XmlElement firstLevel   = xmlDoc.CreateElement(prefixDriver, "inf", nsDriver);

            firstLevel.InnerText = "BASE F11F3DCC-09F8-4D04-BCB7-81D5D7C48C78";
            xmlDoc.DocumentElement.AppendChild(firstLevel);
            firstLevel           = xmlDoc.CreateElement(prefixDriver, "dbbuild", nsDriver);
            firstLevel.InnerText = "4";
            xmlDoc.DocumentElement.AppendChild(firstLevel);
            firstLevel = xmlDoc.CreateElement(prefixDriver, prefixDriver, nsDriver);
            xmlDoc.DocumentElement.AppendChild(firstLevel);

            XmlElement secondLevel = xmlDoc.CreateElement(prefixDriver, "id", nsDriver);

            secondLevel.InnerText = "1";
            firstLevel.AppendChild(secondLevel);
            secondLevel           = xmlDoc.CreateElement(prefixDriver, "tid", nsDriver);
            secondLevel.InnerText = "0";
            firstLevel.AppendChild(secondLevel);
            secondLevel           = xmlDoc.CreateElement(prefixDriver, "dllname", nsDriver);
            secondLevel.InnerText = "PAC_easy_drv_LZ.dll";
            firstLevel.AppendChild(secondLevel);
            secondLevel           = xmlDoc.CreateElement(prefixDriver, "access", nsDriver);
            secondLevel.InnerText = "2";
            firstLevel.AppendChild(secondLevel);
            secondLevel           = xmlDoc.CreateElement(prefixDriver, "maxsubtypescount", nsDriver);
            secondLevel.InnerText = "10";
            firstLevel.AppendChild(secondLevel);
            secondLevel           = xmlDoc.CreateElement(prefixDriver, "enabled", nsDriver);
            secondLevel.InnerText = "-1";
            firstLevel.AppendChild(secondLevel);
            secondLevel           = xmlDoc.CreateElement(prefixDriver, "descr", nsDriver);
            secondLevel.InnerText = "Система PLC-X1";
            firstLevel.AppendChild(secondLevel);
            secondLevel           = xmlDoc.CreateElement(prefixDriver, "drvname", nsDriver);
            secondLevel.InnerText = Path.GetFileNameWithoutExtension(xmlDoc.BaseURI);
            firstLevel.AppendChild(secondLevel);
            secondLevel           = xmlDoc.CreateElement(prefixDriver, "defname", nsDriver);
            secondLevel.InnerText = "Opc Driver";
            firstLevel.AppendChild(secondLevel);
            secondLevel           = xmlDoc.CreateElement(prefixDriver, "defdescr", nsDriver);
            secondLevel.InnerText = "Универсальный драйвер для протоколов Modbus и SNMP";
            firstLevel.AppendChild(secondLevel);
            secondLevel = xmlDoc.CreateElement(prefixDriver, "communication", nsDriver);
            secondLevel.SetAttribute(
                "xmlns:communication", "http://brestmilk.by/communication/");
            firstLevel.AppendChild(secondLevel);

            string     nsParam    = "http://brestmilk.by/parameters/";
            string     pefixParam = "parameters";
            XmlElement thirdLevel = xmlDoc.CreateElement(
                "communication", pefixParam, "http://brestmilk.by/communication/");

            thirdLevel.SetAttribute("xmlns:parameters", nsParam);
            secondLevel.AppendChild(thirdLevel);

            XmlElement forthLevel = xmlDoc.CreateElement(
                pefixParam, "parameter", nsParam);

            thirdLevel.AppendChild(forthLevel);
            XmlElement fifthLevel =
                xmlDoc.CreateElement(pefixParam, "name", nsParam);

            fifthLevel.InnerText = "TYPE";
            forthLevel.AppendChild(fifthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "value", nsParam);
            fifthLevel.InnerText = "COM";
            forthLevel.AppendChild(fifthLevel);

            forthLevel = xmlDoc.CreateElement(pefixParam, "parameter", nsParam);
            thirdLevel.AppendChild(forthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "name", nsParam);
            fifthLevel.InnerText = "PORTNAME";
            forthLevel.AppendChild(fifthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "value", nsParam);
            fifthLevel.InnerText = "COM4";
            forthLevel.AppendChild(fifthLevel);

            forthLevel = xmlDoc.CreateElement(pefixParam, "parameter", nsParam);
            thirdLevel.AppendChild(forthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "name", nsParam);
            fifthLevel.InnerText = "SPEED";
            forthLevel.AppendChild(fifthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "value", nsParam);
            fifthLevel.InnerText = "12";
            forthLevel.AppendChild(fifthLevel);

            forthLevel = xmlDoc.CreateElement(pefixParam, "parameter", nsParam);
            thirdLevel.AppendChild(forthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "name", nsParam);
            fifthLevel.InnerText = "PARITY";
            forthLevel.AppendChild(fifthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "value", nsParam);
            fifthLevel.InnerText = "0";
            forthLevel.AppendChild(fifthLevel);

            forthLevel = xmlDoc.CreateElement(pefixParam, "parameter", nsParam);
            thirdLevel.AppendChild(forthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "name", nsParam);
            fifthLevel.InnerText = "DATABITS";
            forthLevel.AppendChild(fifthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "value", nsParam);
            fifthLevel.InnerText = "4";
            forthLevel.AppendChild(fifthLevel);

            forthLevel = xmlDoc.CreateElement(pefixParam, "parameter", nsParam);
            thirdLevel.AppendChild(forthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "name", nsParam);
            fifthLevel.InnerText = "STOPBITS";
            forthLevel.AppendChild(fifthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "value", nsParam);
            fifthLevel.InnerText = "0";
            forthLevel.AppendChild(fifthLevel);

            secondLevel = xmlDoc.CreateElement(prefixDriver, "init_parameters",
                                               nsDriver);
            secondLevel.SetAttribute("xmlns:parameters", nsParam);
            firstLevel.AppendChild(secondLevel);

            thirdLevel = xmlDoc.CreateElement(pefixParam, "parameter", nsParam);
            secondLevel.AppendChild(thirdLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "name", nsParam);
            fifthLevel.InnerText = "IP";
            thirdLevel.AppendChild(fifthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "value", nsParam);
            fifthLevel.InnerText = "IP127.0.0.1";
            thirdLevel.AppendChild(fifthLevel);

            thirdLevel = xmlDoc.CreateElement(pefixParam, "parameter", nsParam);
            secondLevel.AppendChild(thirdLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "name", nsParam);
            fifthLevel.InnerText = "PLC_NAME";
            thirdLevel.AppendChild(fifthLevel);
            fifthLevel = xmlDoc.CreateElement(pefixParam, "value", nsParam);
            if (string.IsNullOrEmpty(EProjectManager.GetInstance().GetCurrentProjectName()))
            {
                Logs.AddMessage("Не задано PLC_NAME.");
                fifthLevel.InnerText = "PLC_NAME";
            }
            else
            {
                string projectName = EProjectManager.GetInstance().GetCurrentProjectName();
                EProjectManager.GetInstance().CheckProjectName(ref projectName);
                fifthLevel.InnerText = projectName;
            }

            thirdLevel.AppendChild(fifthLevel);

            thirdLevel = xmlDoc.CreateElement(pefixParam, "parameter", nsParam);
            secondLevel.AppendChild(thirdLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "name", nsParam);
            fifthLevel.InnerText = "PORT";
            thirdLevel.AppendChild(fifthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "value", nsParam);
            fifthLevel.InnerText = "10000";
            thirdLevel.AppendChild(fifthLevel);

            thirdLevel = xmlDoc.CreateElement(pefixParam, "parameter", nsParam);
            secondLevel.AppendChild(thirdLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "name", nsParam);
            fifthLevel.InnerText = "Kontroller";
            thirdLevel.AppendChild(fifthLevel);
            fifthLevel           = xmlDoc.CreateElement(pefixParam, "value", nsParam);
            fifthLevel.InnerText = "LINUX";
            thirdLevel.AppendChild(fifthLevel);

            secondLevel = xmlDoc.CreateElement(
                prefixDriver, "common_parameters", nsDriver);
            secondLevel.SetAttribute("xmlns:parameters", nsParam);
            firstLevel.AppendChild(secondLevel);

            secondLevel = xmlDoc.CreateElement(
                prefixDriver, "final_parameters", nsDriver);
            secondLevel.SetAttribute("xmlns:parameters", nsParam);
            firstLevel.AppendChild(secondLevel);

            secondLevel = xmlDoc.CreateElement(prefixDriver, "subtypes", nsDriver);
            secondLevel.SetAttribute("xmlns:subtypes",
                                     "http://brestmilk.by/subtypes/");
            firstLevel.AppendChild(secondLevel);
            return(secondLevel);
        }
コード例 #4
0
        /// <summary>
        /// Сохранить привязку объектов к объектам в prg.lua
        /// </summary>
        /// <param name="attachedObjects">Словарь привязанных объектов</param>
        /// <returns></returns>
        private static string SaveObjectsBindingToPrgLua(
            Dictionary <int, string> attachedObjects)
        {
            var res  = "";
            var temp = "";

            string previouslyObjectName = "";
            bool   isDigit = false;

            foreach (var val in attachedObjects)
            {
                var techObj      = techObjectManager.GetTObject(val.Key);
                var attachedObjs = val.Value.Split(' ');
                foreach (string value in attachedObjs)
                {
                    isDigit = int.TryParse(value, out _);
                    if (isDigit)
                    {
                        var attachedTechObject = techObjectManager.GetTObject(
                            Convert.ToInt32(value));
                        if (attachedTechObject == null)
                        {
                            string objName = techObj.Name + techObj.TechNumber
                                             .ToString();
                            string msg = $"Для объекта {objName} не найден " +
                                         $"привязанный агрегат под номером {value}.\n";
                            Logs.AddMessage(msg);
                            continue;
                        }

                        var attachedTechObjectType = attachedTechObject
                                                     .NameEplanForFile.ToLower();
                        var attachedTechObjNameForFile =
                            attachedTechObjectType +
                            attachedTechObject.TechNumber;
                        var techObjNameForFile = "prg." +
                                                 techObj.NameEplanForFile.ToLower() +
                                                 techObj.TechNumber;

                        if (previouslyObjectName != techObj.NameEplanForFile
                            .ToLower() && previouslyObjectName != "")
                        {
                            temp += "\n";
                        }

                        temp += techObjNameForFile + "." +
                                attachedTechObject.BaseTechObject.BindingName +
                                " = prg." + attachedTechObjNameForFile + "\n";

                        previouslyObjectName = techObj.NameEplanForFile
                                               .ToLower();
                    }
                    else
                    {
                        string msg = $"В объекте \"{techObj.EditText[0]} " +
                                     $"{techObj.TechNumber}\" ошибка заполнения поля " +
                                     $"\"Привязанные устройства\"\n";
                        Logs.AddMessage(msg);
                    }
                }
            }

            if (temp != "")
            {
                res += "\n" + temp + "\n";
            }
            return(res);
        }