private void btnLoad_Click(object sender, System.EventArgs e) { treeViewSymbols.Nodes.Clear(); try { if (!cbFlat.Checked) { TcAdsSymbolInfo symbol = symbolLoader.GetFirstSymbol(true); while (symbol != null) { treeViewSymbols.Nodes.Add(CreateNewNode(symbol)); symbol = symbol.NextSymbol; } } else { foreach (TcAdsSymbolInfo symbol in symbolLoader) { TreeNode node = new TreeNode(symbol.Name); node.Tag = symbol; treeViewSymbols.Nodes.Add(node); } } } catch (Exception err) { MessageBox.Show(err.Message); } }
public void LoadSymbols3() { try { symbolLoader = m_adsClient.CreateSymbolInfoLoader(); } catch (Exception err) { throw (new SystemException(err.Message)); } m_plcSymbols.Clear(); m_plcSymbols2.Clear(); TcAdsSymbolInfo symbol = symbolLoader.GetFirstSymbol(true); while (symbol != null) { if (symbol.Name.Contains("GVL_") == true) { CreateNewNode4(symbol); } symbol = symbol.NextSymbol; } }
internal ControllerConnection(TcAdsClient client) { _client = client; _declarationSpace = new DeclarationSpace(this); _infoLoader = _client.CreateSymbolInfoLoader(); _infoLoader.GetFirstSymbol(true); _symbols = _infoLoader.GetSymbols(forceReload: true); }
private void btnLoad_Click(object sender, System.EventArgs e) { treeViewSymbols.Nodes.Clear(); //check adr info AmsAddress serverAddress = null; try { // check if port is a hex value if (tbAdsPort.Text.StartsWith(("0x")) || tbAdsPort.Text.StartsWith(("0X"))) { string sHexValue = tbAdsPort.Text.Substring(2); serverAddress = new AmsAddress(tbNetID.Text, Int32.Parse(sHexValue, System.Globalization.NumberStyles.HexNumber)); } // interpret as dec value else { serverAddress = new AmsAddress(tbNetID.Text, Int32.Parse(tbAdsPort.Text)); } } catch { MessageBox.Show("Invalid AMS NetId " + tbNetID.Text + " or Ams port " + tbAdsPort.Text + "!"); return; } //connect try { //orig for just 127.0...: adsClient.Connect(Convert.ToInt32(tbAdsPort.Text)); adsClient.Connect(serverAddress.NetId, serverAddress.Port); symbolLoader = adsClient.CreateSymbolInfoLoader(); if (!cbFlat.Checked) { TcAdsSymbolInfo symbol = symbolLoader.GetFirstSymbol(true); while (symbol != null) { treeViewSymbols.Nodes.Add(CreateNewNode(symbol)); symbol = symbol.NextSymbol; } } else { foreach (TcAdsSymbolInfo symbol in symbolLoader) { TreeNode node = new TreeNode(symbol.Name); node.Tag = symbol; treeViewSymbols.Nodes.Add(node); } } } catch (Exception err) { MessageBox.Show(err.Message); } }
public void CreateSymbolTypesFile3(string PREFIX, string fileName = "") { try { if (fileName == string.Empty) { fileName = "plc_symbols.txt"; } m_swSymbols = new StreamWriter(fileName); m_plcSymbolsList = new List <string>(); if (symbolLoader == null) { symbolLoader = m_adsClient.CreateSymbolInfoLoader(); } } catch (Exception err) { if (m_swSymbols != null) { m_swSymbols.Close(); } throw (new SystemException(err.Message)); } TcAdsSymbolInfo symbol = symbolLoader.GetFirstSymbol(true); while (symbol != null) { CreateNewNode2(symbol); symbol = symbol.NextSymbol; } if (m_swSymbols != null) { m_swSymbols.Close(); } }
public void LoadSymbols() { try { symbolLoader = m_adsClient.CreateSymbolInfoLoader(); } catch (Exception err) { throw (new SystemException(err.Message)); } m_plcSymbols.Clear(); m_plcSymbols2.Clear(); TcAdsSymbolInfo symbol = symbolLoader.GetFirstSymbol(true); while (symbol != null) { string symbolName = symbol.Name.TrimStart('.'); m_plcSymbols.Add(symbolName, symbol); PLC_SYMBOLS p = new PLC_SYMBOLS(); p.Name = symbolName; p.IndexGroup = symbol.IndexGroup; p.IndexOffset = symbol.IndexOffset; p.IndexOffset = symbol.IndexOffset; p.Size = symbol.Size; p.Type = symbol.Type; p.Datatype = symbol.Datatype; string ShortName = symbol.ShortName.TrimStart('.'); p.ShortName = ShortName; try { p.Value = m_adsClient.ReadSymbol(symbol).ToString(); m_plcSymbols2.Add(p.Name, p); } catch (AdsDatatypeNotSupportedException err) { p.Value = err.Message; } catch (Exception err) { //MessageBox.Show("Unable to read Symbol Info. " + err.Message); } symbol = symbol.NextSymbol; } }
/// <summary> /// Imports the tags directly from PLC. /// </summary> /// <param name="adsAddress">The ads address to PLC. Port is hardcoded to 851.</param> /// <param name="adsPort">The ads port.</param> /// <returns> /// List of imported tags. /// </returns> /// <exception cref="PlcCommunicationException">Cannot import tags online. Connection to PLC failed.</exception> /// <exception cref="System.NotImplementedException">Cannot resolve tag scope and name. FullName contains more than one . operator!</exception> /// <exception cref="AdsErrorException">When connection to PLC is not possible an exception will be thrown.</exception> public ICollection <Tag> ImportTags(string adsAddress, int adsPort) { _logger.Debug(string.Format("Importing all tags recursively from the plc under '{0}:{1}'", adsAddress, adsPort)); TcAdsSymbolInfo symbol; try { InitializieConnection(adsAddress, adsPort); //int count = _symbolLoader.GetSymbolCount(false); symbol = _symbolLoader.GetFirstSymbol(false); } catch (AdsErrorException e) { throw new PlcCommunicationException("Cannot import tags online. Connection to PLC failed.", adsAddress, adsPort.ToString(CultureInfo.InvariantCulture), string.Empty, e); } var tmpRootTag = new Tag(); ImportChildTagsRecursively(tmpRootTag, symbol, adsPort); return(tmpRootTag.Childs.ToList()); }