/// <summary> /// Чтение привязки клеммы модуля ввода-вывода. /// </summary> /// <param name="node">Узел</param> /// <param name="module">Модуль</param> /// <param name="clampFunction">Функция клеммы</param> private void ReadModuleClampBinding(IO.IONode node, IO.IOModule module, Function clampFunction) { bool skip = NeedToSkip(module, clampFunction); if (skip == true) { return; } string description = ApiHelper.GetFunctionalText(clampFunction); var descriptionMatches = Regex.Matches(description, DeviceManager.BINDING_DEVICES_DESCRIPTION_PATTERN); const string ValveTerminalNamePattern = @"=*-Y(?<n>\d+)"; var valveTerminalRegex = new Regex(ValveTerminalNamePattern); var valveTerminalMatch = valveTerminalRegex.Match(description); if (valveTerminalMatch.Success && descriptionMatches.Count == 1) { description = ReadValveTerminalBinding(description); } string comment; Match actionMatch; CorrectDataIfMultipleBinding(ref description, out actionMatch, out comment); SetBind(description, actionMatch, module, node, clampFunction, comment); }
/// <summary> /// Чтение модулей ввода-вывода /// </summary> /// <param name="isContainsNodes">Прочитаны или нет узлы</param> private void ReadModules(bool isContainsNodes) { foreach (var function in functionsForSearching) { bool needSkipModule = NeedSkipModule(function); if (needSkipModule == true) { continue; } var match = IONameRegex.Match(function.VisibleName); int moduleNumber = Convert.ToInt32(match.Groups["n"].Value); int shortModuleNumber = moduleNumber % 100; int shortNodeNumber; if (isContainsA1 == true) { shortNodeNumber = moduleNumber / 100; } else { shortNodeNumber = moduleNumber / 100 - numberA1; } string type = GetModuleTypeFromFunction(function); IO.IONode node = IOManager[shortNodeNumber]; if (IOManager[shortNodeNumber] != null) { IO.IOModuleInfo moduleInfo = GetIOModuleInfo(function, type); int inOffset; int outOffset; GetInAndOutOffset(shortNodeNumber, moduleInfo, out inOffset, out outOffset); IO.IOModule nodeModule = new IO.IOModule(inOffset, outOffset, moduleInfo, moduleNumber, function); node.DI_count += moduleInfo.DI_count; node.DO_count += moduleInfo.DO_count; node.AI_count += moduleInfo.AI_count; node.AO_count += moduleInfo.AO_count; node.SetModule(nodeModule, shortModuleNumber); } else { ProjectManager.GetInstance().AddLogMessage($"Для" + $" \"{function.VisibleName}\" - \"{type}\", " + $"не найден узел номер {++shortNodeNumber}."); } } }
/// <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)) { Logs.AddMessage($"\"{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); Logs.AddMessage(error); } } }
/// <summary> /// Чтение модулей ввода-вывода /// </summary> /// <param name="isContainsNodes">Прочитаны или нет узлы</param> private void ReadModules(bool isContainsNodes) { foreach (var function in functionsForSearching) { bool needSkipModule = NeedSkipModule(function); if (needSkipModule == true) { continue; } var match = IONameRegex.Match(function.VisibleName); int moduleNumber = Convert.ToInt32(match.Groups["n"].Value); int shortModuleNumber = moduleNumber % 100; int shortNodeNumber; if (isContainsA1 == true) { shortNodeNumber = moduleNumber / 100; } else { shortNodeNumber = moduleNumber / 100 - numberA1; } string type = GetModuleTypeFromFunction(function); IO.IONode node = IOManager[shortNodeNumber]; if (IOManager[shortNodeNumber] != null) { IO.IOModuleInfo moduleInfo = GetIOModuleInfo(function, type); int inOffset; int outOffset; GetInAndOutOffset(shortNodeNumber, moduleInfo, out inOffset, out outOffset); IO.IOModule nodeModule = new IO.IOModule(inOffset, outOffset, moduleInfo, moduleNumber, function); node.DI_count += moduleInfo.DICount; node.DO_count += moduleInfo.DOCount; node.AI_count += moduleInfo.AICount; node.AO_count += moduleInfo.AOCount; bool moduleNotExist = node[shortModuleNumber - 1] == null; if (moduleNotExist) { node.SetModule(nodeModule, shortModuleNumber); } else { Logs.AddMessage($"Главная функция модуля " + $"ввода-вывода \'{function.VisibleName}\' " + $"определяется дважды, проверьте расстановку " + $"главных функций на модулях. "); } } else { Logs.AddMessage($"Для" + $" \"{function.VisibleName}\" - \"{type}\", " + $"не найден узел номер {++shortNodeNumber}."); } } }