public ProjectHealthChecker()
 {
     projectManager  = ProjectManager.GetInstance();
     eProjectManager = EProjectManager.GetInstance();
 }
Esempio n. 2
0
        /// <summary>
        /// Установить привязку устройства.
        /// </summary>
        /// <param name="description">Описание устройства</param>
        /// <param name="actionMatch">Действие канала</param>
        /// <param name="module">Модуль ввода-вывода</param>
        /// <param name="node">Узел ввода-вывода</param>
        /// <param name="clampFunction">Функция клеммы</param>
        /// <param name="comment">Комментарий к устройству</param>
        private void SetBind(string description, Match actionMatch,
                             IO.IOModule module, IO.IONode node, Function clampFunction,
                             string comment)
        {
            int clamp = Convert.ToInt32(clampFunction.Properties
                                        .FUNC_ADDITIONALIDENTIFYINGNAMEPART.ToString());

            var descriptionMatches = Regex.Matches(description,
                                                   DeviceManager.BINDING_DEVICES_DESCRIPTION_PATTERN);
            int devicesCount = descriptionMatches.Count;

            if (devicesCount < 1 && !description.Equals(CommonConst.Reserve))
            {
                ProjectManager.GetInstance().AddLogMessage(
                    $"\"{module.Function.VisibleName}:{clamp}\" - неверное " +
                    $"имя привязанного устройства - \"{description}\".");
            }

            foreach (Match descriptionMatch in descriptionMatches)
            {
                string deviceName = descriptionMatch.Groups["name"].Value;
                var    device     = deviceManager.GetDevice(deviceName);

                var clampComment = "";
                if (actionMatch.Success)
                {
                    clampComment = actionMatch.Value;
                    if (clampComment.Contains(
                            CommonConst.NewLineWithCarriageReturn))
                    {
                        clampComment = clampComment.Replace(
                            CommonConst.NewLineWithCarriageReturn, "");
                    }
                }

                var    error       = "";
                string channelName = "IO-Link";
                int    logicalPort = Array
                                     .IndexOf(module.Info.ChannelClamps, clamp) + 1;
                int moduleOffset = module.InOffset;

                if (devicesCount == 1 &&
                    module.Info.AddressSpaceType ==
                    IO.IOModuleInfo.ADDRESS_SPACE_TYPE.AOAIDODI)
                {
                    if (device.Channels.Count == 1)
                    {
                        List <IODevice.IOChannel> chanels =
                            device.Channels;
                        channelName = ApiHelper
                                      .GetChannelNameForIOLinkModuleFromString(
                            chanels.First().Name);
                    }
                    else
                    {
                        channelName = ApiHelper
                                      .GetChannelNameForIOLinkModuleFromString(comment);
                    }
                }

                DeviceManager.GetInstance().AddDeviceChannel(device,
                                                             module.Info.AddressSpaceType, node.N - 1,
                                                             module.PhysicalNumber % 100, clamp, clampComment,
                                                             out error, module.PhysicalNumber, logicalPort,
                                                             moduleOffset, channelName);

                if (error != "")
                {
                    error = string.Format("\"{0}:{1}\" : {2}",
                                          module.Function.VisibleName, clamp, error);
                    ProjectManager.GetInstance().AddLogMessage(error);
                }
            }
        }