示例#1
0
        /// <summary>
        /// Сортировка каналов устройства для соответствия.
        /// </summary>
        public void sortChannels()
        {
            if (dType == DeviceType.V)
            {
                if (DI.Count > 1)
                {
                    List <IOChannel> tmp = new List <IOChannel>();

                    foreach (string descr in new string[] { "Открыт", "Закрыт" })
                    {
                        IOChannel resCh = DI.Find(delegate(IOChannel ch)
                        {
                            return(ch.Comment == descr);
                        });

                        if (resCh != null)
                        {
                            tmp.Add(resCh);
                        }
                    }

                    DI = tmp;
                }

                if (DO.Count > 1)
                {
                    List <IOChannel> tmp2 = new List <IOChannel>();

                    foreach (string descr in new string[] { "Открыть", "Открыть мини", "Открыть ВС",
                                                            "Открыть НС", "Закрыть" })
                    {
                        IOChannel resCh = DO.Find(delegate(IOChannel ch)
                        {
                            return(ch.Comment == descr);
                        });

                        if (resCh != null)
                        {
                            tmp2.Add(resCh);
                        }
                    }

                    DO = tmp2;
                }
            }
        }
示例#2
0
        public override string SetSubType(string subtype)
        {
            base.SetSubType(subtype);

            string errStr = "";

            switch (subtype)
            {
            case "QT":
                parameters.Add("P_C0", null);
                parameters.Add("P_MIN_V", null);
                parameters.Add("P_MAX_V", null);
                break;

            case "QT_OK":
                parameters.Add("P_C0", null);
                parameters.Add("P_MIN_V", null);
                parameters.Add("P_MAX_V", null);

                DI.Add(new IOChannel("DI", -1, -1, -1, ""));
                break;

            case "QT_IOLINK":
                parameters.Add("P_ERR", null);

                SetIOLinkSizes(ArticleName);
                break;

            case "":
                errStr = string.Format("\"{0}\" - не задан тип" +
                                       " (QT, QT_OK, QT_IOLINK).\n",
                                       Name);
                break;

            default:
                errStr = string.Format("\"{0}\" - неверный тип" +
                                       " (QT, QT_OK, QT_IOLINK).\n",
                                       Name);
                break;
            }

            return(errStr);
        }
示例#3
0
        public override string SetSubType(string subtype)
        {
            base.SetSubType(subtype);

            string errStr = "";

            switch (subtype)
            {
            case "M":
                DI.Add(new IOChannel("DI", -1, -1, -1, "Обратная связь"));

                break;

            case "M_FREQ":
                DI.Add(new IOChannel("DI", -1, -1, -1, "Обратная связь"));
                AO.Add(new IOChannel("AO", -1, -1, -1, "Частота вращения"));

                break;

            case "M_REV":
                DI.Add(new IOChannel("DI", -1, -1, -1, "Обратная связь"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Реверс"));

                break;

            case "M_REV_FREQ":
                DI.Add(new IOChannel("DI", -1, -1, -1, "Обратная связь"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Реверс"));
                AO.Add(new IOChannel("AO", -1, -1, -1, "Частота вращения"));

                break;

            case "M_REV_2":
                DI.Add(new IOChannel("DI", -1, -1, -1, "Обратная связь"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Реверс"));

                break;

            case "M_REV_FREQ_2":
                DI.Add(new IOChannel("DI", -1, -1, -1, "Обратная связь"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Реверс"));
                AO.Add(new IOChannel("AO", -1, -1, -1, "Частота вращения"));

                break;


            case "M_REV_2_ERROR":
                DI.Add(new IOChannel("DI", -1, -1, -1, "Авария"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Реверс"));

                break;

            case "M_REV_FREQ_2_ERROR":
                DI.Add(new IOChannel("DI", -1, -1, -1, "Обратная связь"));
                DI.Add(new IOChannel("DI", -1, -1, -1, "Авария"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Реверс"));
                AO.Add(new IOChannel("AO", -1, -1, -1, "Частота вращения"));

                break;

            case "M_ATV":
                DO.Clear();
                properties.Add("IP", null);
                break;

            case "":
                errStr = string.Format("\"{0}\" - не задан тип" +
                                       " (M, M_FREQ, M_REV, M_REV_FREQ, M_REV_2," +
                                       " M_REV_FREQ_2, M_REV_2_ERROR, M_REV_FREQ_2_ERROR, " +
                                       "M_ATV).\n", Name);
                break;

            default:
                errStr = string.Format("\"{0}\" - неверный тип" +
                                       " (M, M_FREQ, M_REV, M_REV_FREQ, M_REV_2," +
                                       " M_REV_FREQ_2, M_REV_2_ERROR, M_REV_FREQ_2_ERROR, " +
                                       "M_ATV).\n", Name);
                break;
            }

            return(errStr);
        }
示例#4
0
        public override string SetSubType(string subtype)
        {
            base.SetSubType(subtype);

            string errStr = "";

            switch (subtype)
            {
            case "V_DO1":
                DO.Add(new IOChannel("DO", -1, -1, -1, ""));
                break;

            case "V_DO2":
                DO.Add(new IOChannel("DO", -1, -1, -1, "Закрыть"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Открыть"));
                break;

            case "V_DO1_DI1_FB_OFF":
                DO.Add(new IOChannel("DO", -1, -1, -1, ""));
                DI.Add(new IOChannel("DI", -1, -1, -1, ""));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);
                break;

            case "V_DO1_DI1_FB_ON":
                DO.Add(new IOChannel("DO", -1, -1, -1, ""));
                DI.Add(new IOChannel("DI", -1, -1, -1, ""));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);
                break;

            case "V_DO1_DI2":
                DO.Add(new IOChannel("DO", -1, -1, -1, ""));
                DI.Add(new IOChannel("DI", -1, -1, -1, "Закрыт"));
                DI.Add(new IOChannel("DI", -1, -1, -1, "Открыт"));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);
                break;

            case "V_DO2_DI2":
            case "V_DO2_DI2_BISTABLE":
                DO.Add(new IOChannel("DO", -1, -1, -1, "Закрыть"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Открыть"));
                DI.Add(new IOChannel("DI", -1, -1, -1, "Закрыт"));
                DI.Add(new IOChannel("DI", -1, -1, -1, "Открыт"));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);
                break;

            case "V_MIXPROOF":
                DO.Add(new IOChannel("DO", -1, -1, -1, "Открыть"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Открыть НС"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Открыть ВС"));
                DI.Add(new IOChannel("DI", -1, -1, -1, "Закрыт"));
                DI.Add(new IOChannel("DI", -1, -1, -1, "Открыт"));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);
                break;

            case "V_IOLINK_MIXPROOF":
                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);

                AO.Add(new IOChannel("AO", -1, -1, -1, ""));
                AI.Add(new IOChannel("AI", -1, -1, -1, ""));

                SetIOLinkSizes(ArticleName);
                break;

            case "V_AS_MIXPROOF":
                AO.Add(new IOChannel("AO", -1, -1, -1, ""));
                AI.Add(new IOChannel("AI", -1, -1, -1, ""));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);

                rtParameters.Add("R_AS_NUMBER", null);
                break;

            case "V_BOTTOM_MIXPROOF":
                DO.Add(new IOChannel("DO", -1, -1, -1, "Открыть"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Открыть мини"));
                DO.Add(new IOChannel("DO", -1, -1, -1, "Открыть НС"));
                DI.Add(new IOChannel("DI", -1, -1, -1, "Закрыт"));
                DI.Add(new IOChannel("DI", -1, -1, -1, "Открыт"));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);
                break;

            case "V_AS_DO1_DI2":
                AO.Add(new IOChannel("AO", -1, -1, -1, ""));
                AI.Add(new IOChannel("AI", -1, -1, -1, ""));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);

                rtParameters.Add("R_AS_NUMBER", null);
                break;

            case "V_IOLINK_DO1_DI2":
                AO.Add(new IOChannel("AO", -1, -1, -1, ""));
                AI.Add(new IOChannel("AI", -1, -1, -1, ""));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);

                SetIOLinkSizes(ArticleName);
                break;

            case "V_IOLINK_VTUG_DO1":
                rtParameters.Add("R_VTUG_NUMBER", null);
                rtParameters.Add("R_VTUG_SIZE", 1);

                AO.Add(new IOChannel("AO", -1, -1, -1, ""));
                break;

            case "V_IOLINK_VTUG_DO1_FB_OFF":
                rtParameters.Add("R_VTUG_NUMBER", null);
                rtParameters.Add("R_VTUG_SIZE", 1);

                AO.Add(new IOChannel("AO", -1, -1, -1, ""));
                DI.Add(new IOChannel("DI", -1, -1, -1, ""));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);
                break;

            case "V_IOLINK_VTUG_DO1_FB_ON":
                rtParameters.Add("R_VTUG_NUMBER", null);
                rtParameters.Add("R_VTUG_SIZE", 1);

                AO.Add(new IOChannel("AO", -1, -1, -1, ""));
                DI.Add(new IOChannel("DI", -1, -1, -1, ""));

                parameters.Add("P_ON_TIME", null);
                parameters.Add("P_FB", 1);
                break;

            case "":
                errStr = string.Format(
                    "\"{0}\" - не задан тип (V_DO1, V_DO2, ...).\n", name);
                break;

            default:
                errStr = string.Format(
                    "\"{0}\" - неверный тип (V_DO1, V_DO2, ...).\n", name);
                break;
            }

            return(errStr);
        }
示例#5
0
        /// <summary>
        /// Добавление канала ввода\вывода к устройству.
        /// </summary>
        /// <param name="devName">Имя устройство.</param>
        /// <param name="description">Описание устройства.</param>
        /// <param name="subType">Подтип устройства.</param>
        /// <param name="paramStr">Дополнительный строковый параметр - параметры.</param>
        /// <param name="rtParamStr">Дополнительный строковый параметр - рабочие параметры.</param>
        /// <param name="propStr">Дополнительный строковый параметр - свойства.</param>
        /// <param name="errStr">Описание ошибки при ее наличии.</param>
        private IODevice AddDevice(string devName, string description,
                                   string subType, string paramStr, string rtParamStr, string propStr,
                                   int dLocation, out string errStr, string articleName)
        {
            errStr = "";
            IODevice dev = null;

            string name;
            string objectName;
            int    objectNumber;
            string deviceType;
            int    deviceNumber;


            CheckDeviceName(devName, out name, out objectName,
                            out objectNumber, out deviceType, out deviceNumber);

            // Если изделия нет или пустое, то оставляем пустое
            if (articleName == "" || articleName == null)
            {
                articleName = "";
            }

            switch (deviceType)
            {
            case "V":
                dev = new V(name, description, deviceNumber, objectName,
                            objectNumber, articleName);
                break;

            case "VC":
                dev = new VC(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "M":
            case "N":
                dev = new M(name, description, deviceNumber, objectName,
                            objectNumber, articleName);
                break;

            case "LS":
                dev = new LS(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "TE":
                dev = new TE(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "GS":
                dev = new GS(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "FS":
                dev = new FS(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "FQT":
                dev = new FQT(name, description, deviceNumber, objectName,
                              objectNumber, articleName);
                break;

            case "AO":
                dev = new AO(name, description, deviceNumber, objectName,
                             objectNumber);
                break;

            case "LT":
                dev = new LT(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "OS":
            case "DI":
                dev = new DI(name, description, deviceNumber, objectName,
                             objectNumber);
                break;

            case "UPR":
            case "DO":
                dev = new DO(name, description, deviceNumber, objectName,
                             objectNumber);
                break;

            case "QT":
                dev = new QT(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "AI":
                dev = new AI(name, description, deviceNumber, objectName,
                             objectNumber);
                break;

            case "HA":
                dev = new HA(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "HL":
                dev = new HL(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "SB":
                dev = new SB(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "WT":
                dev = new WT(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "PT":
                dev = new PT(name, description, deviceNumber, objectName,
                             objectNumber, articleName);
                break;

            case "Y":
                dev = new Y(name, description, deviceNumber, objectName,
                            objectNumber, articleName);
                break;

            case "DEV_VTUG":     // Совместимость со старыми проектами
                dev = new DEV_VTUG(name, description, deviceNumber, objectName,
                                   objectNumber, articleName);
                break;

            case "F":
                dev = new F(name, description, deviceNumber, objectName,
                            objectNumber, articleName);
                break;

            default:
                break;
            }

            if (dev != null)
            {
                if (!devices.Contains(dev))
                {
                    subType = subType.ToUpper();

                    errStr += dev.SetSubType(subType);

                    //Разбор параметров.
                    if (paramStr != "")
                    {
                        //Шаблоны для разбора параметров - 0-20 .
                        const string paramsPattern = @"(?<p_name>\w+)=(?<p_value>-?\d+\.?\d*),*";

                        Match paramsMatch = Regex.Match(paramStr, paramsPattern, RegexOptions.IgnoreCase);
                        while (paramsMatch.Success)
                        {
                            string res;
                            if (paramsMatch.Groups["p_value"].Value.EndsWith("."))
                            {
                                string str = paramsMatch.Groups["p_value"].Value.Remove(paramsMatch.Groups["p_value"].Value.Length - 1);
                                res = dev.SetParameter(paramsMatch.Groups["p_name"].Value, Convert.ToDouble(str));
                            }
                            else
                            {
                                res = dev.SetParameter(paramsMatch.Groups["p_name"].Value,
                                                       Convert.ToDouble(paramsMatch.Groups["p_value"].Value));
                            }
                            if (res != "")
                            {
                                errStr += devName + " - " + res;
                            }

                            paramsMatch = paramsMatch.NextMatch();
                        }
                    }

                    //Разбор рабочих параметров.
                    if (rtParamStr != "")
                    {
                        //Шаблоны для разбора параметров - 0-20 .
                        const string paramsPattern = @"(?<p_name>\w+)=(?<p_value>-?\d+\.?\d*),*";

                        Match paramsMatch = Regex.Match(rtParamStr, paramsPattern, RegexOptions.IgnoreCase);
                        while (paramsMatch.Success)
                        {
                            string res;
                            if (paramsMatch.Groups["p_value"].Value.EndsWith("."))
                            {
                                string str = paramsMatch.Groups["p_value"].Value.Remove(paramsMatch.Groups["p_value"].Value.Length - 1);
                                res = dev.SetRuntimeParameter(paramsMatch.Groups["p_name"].Value, Convert.ToDouble(str));
                            }
                            else
                            {
                                res = dev.SetRuntimeParameter(paramsMatch.Groups["p_name"].Value,
                                                              Convert.ToDouble(paramsMatch.Groups["p_value"].Value));
                            }
                            if (res != "")
                            {
                                errStr += devName + " - " + res;
                            }

                            paramsMatch = paramsMatch.NextMatch();
                        }
                    }

                    //Разбор свойств.
                    if (propStr != "")
                    {
                        //Шаблоны для разбора параметров - 0-20 .
                        const string propPattern = @"(?<p_name>\w+)=(?<p_value>\'[\w.]*\'),*";

                        Match propsMatch = Regex.Match(propStr, propPattern, RegexOptions.IgnoreCase);
                        while (propsMatch.Success)
                        {
                            string res = dev.SetProperty(propsMatch.Groups["p_name"].Value,
                                                         propsMatch.Groups["p_value"].Value);

                            if (res != "")
                            {
                                errStr += devName + " - " + res;
                            }
                            if (propsMatch.Groups["p_name"].Value.Equals("IP"))
                            {
                                bool foundMatch = false;
                                var  ipprop     = propsMatch.Groups["p_value"].Value.Trim(new char[] { '\'' });
                                try
                                {
                                    foundMatch = Regex.IsMatch(ipprop, @"\A(?:^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$)\Z");
                                }
                                catch
                                {
                                    // Syntax error in the regular expression
                                }
                                if (!foundMatch)
                                {
                                    errStr += String.Format("Устройство {0}: неверный IP-адрес - \'{1}\'.\n", devName, ipprop);
                                }
                            }

                            propsMatch = propsMatch.NextMatch();
                        }
                    }

                    //Установка параметра номер а шкафа для устройства.
                    dev.SetLocation(dLocation);

                    devices.Add(dev);
                }
                else
                {
                    errStr = string.Format("\"{0}\"  - дублируется.",
                                           devName);
                }
            }
            else
            {
                errStr = string.Format("\"{0}\" - неизвестное устройство.",
                                       devName);
            }
            return(dev);
        }