/// <summary> /// Расчет для стандартного IO-Link модуля от Phoenix Contact. /// </summary> private void CalculateForPhoenixContact() { foreach (int clamp in moduleInfo.ChannelClamps) { if (devices[clamp] != null && devices[clamp][0] != null) { int deviceOffset; Device.IODevice.IOChannel channel = devicesChannels[clamp][0]; Device.IODevice device = devices[clamp][0]; if (channel.Name == "DI" || channel.Name == "DO") { int moduleOffset = channel.ModuleOffset; int logicalClamp = channel.LogicalClamp; int discreteOffset = CalculateDiscreteOffsetForIOLink( moduleOffset, logicalClamp); moduleInfo.ChannelAddressesIn[clamp] = discreteOffset; moduleInfo.ChannelAddressesOut[clamp] = discreteOffset; } else { moduleInfo.ChannelAddressesIn[clamp] = offsetIn; moduleInfo.ChannelAddressesOut[clamp] = offsetOut; deviceOffset = device.IOLinkProperties.GetMaxIOLinkSize(); offsetIn += deviceOffset; offsetOut += deviceOffset; } } } }
private void devicesTreeViewAdv_DrawNode(object sender, DrawTextEventArgs e) { e.TextColor = Color.Black; if (e.Node.Level == 1 || e.Node.Level == 2) { e.Font = itemFontType; return; } Node currentNode = (Node)e.Node.Tag; if (currentNode.Tag is Device.IODevice.IOChannel) { e.Font = itemFontNoDevice; Device.IODevice.IOChannel ch = currentNode.Tag as Device.IODevice.IOChannel; if (!ch.IsEmpty()) { e.Font = itemFontIsDevice; e.Text = ch.Name + " " + ch.Comment + $" (A{ch.FullModule}:" + ch.PhysicalClamp + ")"; } else { e.Text = ch.Name + " " + ch.Comment; } } }
/// <summary> /// Сортировка дерева с помощью List.Sort /// </summary> /// <param name="nodes">Список Nodes в узле</param> /// <param name="parent">Родительский узел, где лежат Nodes</param> private void TreeSort(List <Node> nodes, Node parent) { // Если меньше или 1, то нет смысла сортировать if (nodes.Count > 1) { // Собственный Comparer для List nodes.Sort((x, y) => { int res = 0; if (x.Tag is Device.IODevice.IOChannel && y.Tag is Device.IODevice.IOChannel) { Device.IODevice.IOChannel wx = x.Tag as Device.IODevice.IOChannel; Device.IODevice.IOChannel wy = y.Tag as Device.IODevice.IOChannel; res = Device.IODevice.IOChannel.Compare(wx, wy); return(res); } if (x.Tag is Device.DeviceType && y.Tag is Device.DeviceType) { res = ((Device.DeviceType)x.Tag).CompareTo( (Device.DeviceType)y.Tag); return(res); } if (x.Nodes.Count > 0 && x.Nodes[0].Tag is Device.Device && y.Nodes.Count > 0 && y.Nodes[0].Tag is Device.Device) { res = Device.Device.Compare( x.Nodes[0].Tag as Device.Device, y.Nodes[0].Tag as Device.Device); return(res); } if (x.Tag is Device.Device && y.Tag is Device.Device) { res = Device.Device.Compare(x.Tag as Device.Device, y.Tag as Device.Device); return(res); } res = string.Compare( x.Text, y.Text); return(res); }); // Очищаем Nodes parent.Nodes.Clear(); // Записываем отсортированные и сортируем сразу следующие foreach (Node node in nodes) { parent.Nodes.Add(node); TreeSort(node.Nodes.ToList(), node); } } }
public void AssignChannelToDevice(int chN, Device.IODevice dev, Device.IODevice.IOChannel ch) { if (devices.GetLength(0) <= chN) { System.Windows.Forms.MessageBox.Show("Error!"); } if (devices[chN] == null) { devices[chN] = new List <Device.IODevice>(); } if (devicesChannels[chN] == null) { devicesChannels[chN] = new List <Device.IODevice.IOChannel>(); } devices[chN].Add(dev); devicesChannels[chN].Add(ch); }
/// <summary> /// Добавление данных привязки конкретного модуля /// </summary> /// <param name="channel">Канал устройства</param> /// <param name="device">Устройство</param> /// <param name="deviceConnections">Словарь с собранными данными /// привязок устройств</param> /// <param name="deviceFunctions">Главные функции устройств для /// поиска обновленных данных</param> private void CollectModuleData(Device.IODevice device, Device.IODevice.IOChannel channel, Function[] deviceFunctions, ref Dictionary <string, string> deviceConnections) { const string IOModulePrefix = "A"; const string ASInterfaceModule = "655"; string deviceVisibleName = IOModulePrefix + channel.FullModule; var deviceFunction = deviceFunctions. FirstOrDefault(x => x.VisibleName.Contains(deviceVisibleName)); if (deviceFunction == null) { return; } deviceVisibleName += ChannelPostfix + channel.PhysicalClamp. ToString(); string functionalText = device.EPlanName; string devicePartNumber = deviceFunction.ArticleReferences[0] .PartNr; // Для модулей ASi не нужно добавлять комментарии // к имени устройств. if (!devicePartNumber.Contains(ASInterfaceModule)) { if (device.Description.Contains(PlusSymbol)) { // Так как в комментариях может использоваться знак // "плюс", то заменим его на какую-то константу, // которую при обновлении функционального текста // преобразуем обратно. string replacedDeviceDescription = device.Description. Replace(PlusSymbol.ToString(), SymbolForPlusReplacing); functionalText += CommonConst.NewLineWithCarriageReturn + replacedDeviceDescription; if (!string.IsNullOrEmpty(channel.Comment)) { functionalText += CommonConst.NewLineWithCarriageReturn + channel.Comment; } } else { functionalText += CommonConst.NewLineWithCarriageReturn + device.Description; if (!string.IsNullOrEmpty(channel.Comment)) { functionalText += CommonConst.NewLineWithCarriageReturn + channel.Comment; } } if (IsPhoenixContactIOLinkModule(devicePartNumber) && device.Channels.Count > 1) { functionalText += CommonConst.NewLineWithCarriageReturn + ApiHelper.GetChannelNameForIOLinkModuleFromString( channel.Name); } } else { functionalText += WhiteSpace; } if (deviceConnections.ContainsKey(deviceVisibleName)) { deviceConnections[deviceVisibleName] += functionalText; } else { deviceConnections.Add(deviceVisibleName, functionalText); } }
public static void Execute(TreeNodeAdv treeNode) { Node node = treeNode.Tag as Node; Device.IODevice dev = node.Tag as Device.IODevice; if (dev != null) { bool isDevHidden = true; //Показываем каналы. foreach (Device.IODevice.IOChannel ch in dev.Channels) { if (ch.IsEmpty()) { isDevHidden = false; } } node.IsHidden = isDevHidden; if (treeNode.Children.Count < 1) { return; } else { List <TreeNodeAdv> childs = treeNode.Children.ToList(); foreach (TreeNodeAdv child in childs) { Execute(child); } return; } } Device.IODevice.IOChannel chn = node.Tag as Device.IODevice.IOChannel; if (chn != null) { if (chn.IsEmpty()) { node.IsHidden = false; } else { node.IsHidden = true; } if (treeNode.Children.Count < 1) { return; } else { List <TreeNodeAdv> childs = treeNode.Children.ToList(); foreach (TreeNodeAdv child in childs) { Execute(child); } return; } } if (treeNode.Children.Count < 1) { node.IsHidden = false; } else { List <TreeNodeAdv> childs = treeNode.Children.ToList(); foreach (TreeNodeAdv child in childs) { Execute(child); } return; } }