private void PopulateListView(string filterName = null) { SymbolListViewItems?.Clear(); if (_plcConnections.Count == 0) { return; } foreach (ISymbol symbol in _plcConnections[_activePlc].Symbols) { if (filterName == null || symbol.InstancePath.ToLower().Contains(filterName.ToLower())) { SymbolListViewItems?.Add(new SymbolInfo { Path = symbol.InstancePath, Type = symbol.TypeName, Size = symbol.Size, IndexGroup = ((IAdsSymbol)symbol).IndexGroup, IndexOffset = ((IAdsSymbol)symbol).IndexOffset, IsStatic = symbol.IsStatic, CurrentValue = "pending..." // GetSymbolValue(symbol) // startup takes to long with loads of variables }); } } }
private void ConnectPlc() { _activePlc = 0; _activePorts = GetActivePlcPorts("127.0.0.1.1.1", 851); _plcConnections.Clear(); ComboBoxPlc.Items.Clear(); SymbolListViewItems?.Clear(); foreach (int port in _activePorts) { PlcConnection plcCon = new PlcConnection(new AmsAddress($"127.0.0.1.1.1:{port}")); plcCon.PlcConnectionError += PlcOnPlcConnectionError; plcCon.Connect(); if (plcCon.Connected) { plcCon.Connection.AdsStateChanged += PlcAdsStateChanged; plcCon.Connection.ConnectionStateChanged += PlcOnConnectionStateChanged; plcCon.Connection.AmsRouterNotification += PlcOnAmsRouterNotification; } _plcConnections.Add(plcCon); } if (_plcConnections.Count == 0) { UpdateDumpStatus("No active PLCs found", Colors.Orange); return; } if (_plcConnections[_activePlc].Connected) { UpdateDumpStatus("Retrieving symbols", Colors.GreenYellow); PopulateListView(); } // Populate Combobox if (_plcConnections.Count > 0) { foreach (int activePort in _activePorts) { ComboBoxItem cbi = new ComboBoxItem(); cbi.Content = activePort.ToString(); ComboBoxPlc.Items.Add(cbi); } ComboBoxPlc.SelectedIndex = 0; } PlcConnected = _plcConnections[_activePlc].Connected; ButtonDumpData.IsEnabled = PlcConnected; }