//Symbols SQL Live data public int ReadNSqlTypes() { TcAdsSymbolInfoLoader symbolLoader; symbolLoader = adsClient.CreateSymbolInfoLoader(); //parse now int NTagsSQL = 0; int Counter = 0; int Match = 0; foreach (TcAdsSymbolInfo symbol in symbolLoader) { //TODO OPTIONAL: Implement a configurable filter here if (symbol.Type.Contains("SQL_SND") && symbol.Name.Contains("Val")) { PLCvar plcVar = new PLCvar(symbol.Name, symbol.Type); // listBoxDBLog.Items.Add(symbol.Name); //Debug Match++; System.Threading.Thread.Sleep(1); } if (Counter > 1 | symbol.Name != null) { NTagsSQL = Match; } Counter++; } //(sender as BackgroundWorker).ReportProgress(100, null); //listBoxDBLog.Items.Add(NTagsSQL); return(NTagsSQL); }
/////////////////////////////////////////////////////////////////////////////// public TwincatConfig(TcAdsClient _tcAds) { string type = ""; try { this.m_tcAds = _tcAds; this.Variables = new Dictionary <string, TwincatVariable>(); this.m_symbolLoader = this.m_tcAds.CreateSymbolInfoLoader(); foreach (TcAdsSymbolInfo symbol in this.m_symbolLoader) { if (symbol.Name.Contains("UBS_")) { type = symbol.Type.ToString(); if (this.m_tipos.ContainsKey(type)) { this.Variables.Add(symbol.Name, new TwincatVariable(symbol, this.m_tipos[type])); } } } } catch (Exception e) { MessageBox.Show(new Form() { TopMost = true }, type + e.ToString(), "Error", MessageBoxButtons.OK); } }
private void Form1_Load(object sender, System.EventArgs e) { try { log.Debug("Start app debugging"); log.Info("Start timer tick- 10sec "); InitTimer(); //Connecto ADS Server log.Info("Connecting to PLC via ADS "); adsClient = new TcAdsClient(); adsClient.Connect(netidplc, 851); symbolLoader = adsClient.CreateSymbolInfoLoader(); //Open connection log.Info("Connecting to PostgreSQL Server "); TestconnOpen(); //Open connection log.Info("Connecting to PostgreSQL Server "); PrepareLiveTable(); PrepareAccuTable(); } catch (Exception err) { log.Debug(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); } }
//List public List <PLCvar> GetPLCvars() { List <PLCvar> symbolsList = new List <PLCvar>(); TcAdsSymbolInfoLoader symbolLoader; symbolLoader = adsClient.CreateSymbolInfoLoader(); foreach (TcAdsSymbolInfo symbol in symbolLoader) { symbolsList.Add(new PLCvar(symbol.Name, symbol.Type)); } return(symbolsList); }
//Symbols ALL (ADS) public List <string> GetPLCSymbols() { List <string> symbolsList = new List <string>(); TcAdsSymbolInfoLoader symbolLoader; symbolLoader = adsClient.CreateSymbolInfoLoader(); foreach (TcAdsSymbolInfo symbol in symbolLoader) { symbolsList.Add(symbol.Name); } return(symbolsList); }
private void Form1_Load(object sender, System.EventArgs e) { try { adsClient = new TcAdsClient(); adsClient.Connect(851); symbolLoader = adsClient.CreateSymbolInfoLoader(); } catch (Exception err) { MessageBox.Show(err.Message); } }
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> /// Parses an PLC array of type T. Supports pointered arrays (POINTER TO ...). /// In case of pointered array it will skipp NULL pointers and import only valid instances. /// </summary> /// <param name="plcPath">The path in PLC to the array.</param> /// <param name="twinCatClient">The adsClient instance.</param> /// <param name="typeOfElements">Marshall type representation in .NET. See Beckhoff TwinCat 3 manual for an example.</param> /// <returns> /// Dictionary of imported and converted (.NET type) array elements and their pathes. /// </returns> public static IEnumerable GetArrayElements(this TcAdsClient twinCatClient, string plcPath, Type typeOfElements) { var elements = new ArrayList(); TcAdsSymbolInfoLoader symbolLoader = twinCatClient.CreateSymbolInfoLoader(); TcAdsSymbolInfo arraySymbol = symbolLoader.FindSymbol(plcPath); if (arraySymbol == null) { return(elements); } var stream = new AdsStream(8); var reader = new AdsBinaryReader(stream); TcAdsSymbolInfo elementSymbol = arraySymbol.FirstSubSymbol; while (elementSymbol != null) { stream.Position = 0; twinCatClient.Read(elementSymbol.IndexGroup, elementSymbol.IndexOffset, stream); var pointerValue = PlcSystem.IsX64Mode ? reader.ReadInt64() : reader.ReadInt32(); if (pointerValue != 0) { string plcArrayElementPath = elementSymbol.Name; if (elementSymbol.IsPointer) { plcArrayElementPath = string.Format("{0}^", plcArrayElementPath); } var handle = twinCatClient.CreateVariableHandle(plcArrayElementPath); try { object element = twinCatClient.ReadAny(handle, typeOfElements); elements.Add(element); } finally { twinCatClient.DeleteVariableHandle(handle); } } elementSymbol = elementSymbol.NextSymbol; } return(elements); }
public List <string> GetPLCSymbolsNameAccuSQL() { List <string> symbolsList = new List <string>(); TcAdsSymbolInfoLoader symbolLoader; symbolLoader = adsClient.CreateSymbolInfoLoader(); foreach (TcAdsSymbolInfo symbol in symbolLoader) { if (symbol.Name.Contains("SQL_SND") & symbol.Name.Contains("TagName") & symbol.Name.Contains("ACCU")) { symbolsList.Add(symbol.Name); } } return(symbolsList); }
private void InitializieConnection(string adsAddress, int adsPort) { try { _twinCatClient = new TcAdsClient(); _twinCatClient.Connect(adsAddress, adsPort); _symbolLoader = _twinCatClient.CreateSymbolInfoLoader(); } catch (AdsErrorException e) { throw new PlcCommunicationException("Can't establish connection to PLC", adsAddress, adsPort.ToString(CultureInfo.InvariantCulture), string.Empty, e); } }
/// <summary> /// Creates and initializes the <see cref="TcAdsClient"/>. /// </summary> /// <param name="path">The connection string or path (file path or IP address depending on implementation). In case of Beckhoff this is the AdsAddress.</param> /// <param name="port">The ADS Port in case of Beckhoff implementation.</param> public void Initialize(string path, int port) { _logger.Init(GetType()); _path = path; _port = port; try { _twinCatClient = new TcAdsClient(); _twinCatClient.Connect(path, port); _symbolLoader = _twinCatClient.CreateSymbolInfoLoader(); } catch (AdsErrorException e) { throw new PlcCommunicationException("Can't establish connection to PLC", path, port.ToString(CultureInfo.InvariantCulture), string.Empty, e); } }
public void LoadSymbols2() { try { symbolLoader = m_adsClient.CreateSymbolInfoLoader(); } catch (Exception err) { throw (new SystemException(err.Message)); } m_plcSymbols.Clear(); m_plcSymbols2.Clear(); foreach (TcAdsSymbolInfo symbol in symbolLoader) { m_plcSymbols.Add(symbol.Name, symbol); PLC_SYMBOLS p = new PLC_SYMBOLS(); p.Name = symbol.Name; p.IndexGroup = symbol.IndexGroup; p.IndexOffset = symbol.IndexOffset; p.IndexOffset = symbol.IndexOffset; p.Size = symbol.Size; p.Type = symbol.Type; p.Datatype = symbol.Datatype; p.ShortName = symbol.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); } } }
public List <string> ReadSQLTypes() { var listSQLTags = new List <string>(); TcAdsSymbolInfoLoader symbolLoader; symbolLoader = adsClient.CreateSymbolInfoLoader(); foreach (TcAdsSymbolInfo symbol in symbolLoader) { if (symbol.Type.Contains("ST_SQL")) { PLCvar plcVar = new PLCvar(symbol.Name, symbol.Type); listSQLTags.Add(symbol.Name); System.Threading.Thread.Sleep(1); } } return(new List <string>()); }
/// <summary> /// Reads a pointer value of the specified <paramref name="typeOfValue"/>. /// </summary> /// <param name="twinCatClient">The twin cat client to read from.</param> /// <param name="plcPath">The path in the PC to the element.</param> /// <param name="typeOfValue">The expected type of the value.</param> /// <returns> /// The value of the element at the specified <paramref name="plcPath"/>. /// </returns> public static object GetPointerValue(this TcAdsClient twinCatClient, string plcPath, Type typeOfValue) { TcAdsSymbolInfoLoader symbolLoader = twinCatClient.CreateSymbolInfoLoader(); TcAdsSymbolInfo symbol = symbolLoader.FindSymbol(plcPath); if (symbol == null) { return(null); } var stream = new AdsStream(8); var reader = new AdsBinaryReader(stream); stream.Position = 0; twinCatClient.Read(symbol.IndexGroup, symbol.IndexOffset, stream); var pointerValue = PlcSystem.IsX64Mode ? reader.ReadInt64() : reader.ReadInt32(); if (pointerValue != 0) { string plcArrayElementPath = symbol.Name; if (symbol.IsPointer) { plcArrayElementPath = string.Format("{0}^", plcArrayElementPath); } var handle = twinCatClient.CreateVariableHandle(plcArrayElementPath); try { return(twinCatClient.ReadAny(handle, typeOfValue)); } finally { twinCatClient.DeleteVariableHandle(handle); } } return(null); }
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 loadHierarchy(WoopsaObject root) { try { _symbolLoader = _tcAds.CreateSymbolInfoLoader(); _woopsaObjects = new Dictionary<string, WoopsaObject>(); _woopsaProperties = new Dictionary<string, WoopsaAdsProperty>(); foreach (TcAdsSymbolInfo symbol in _symbolLoader) { WoopsaObject newObject = null; WoopsaAdsProperty newProperty = null; TcAdsSymbolInfo parentInfo; WoopsaValueType propertyType; string[] path = symbol.Name.Split('.'); string name = path[path.Length - 1]; bool isProperties = BeckhoffToWoopsaValueType(symbol.Type, out propertyType); if (symbol.Parent != null) { parentInfo = symbol.Parent; if (_woopsaObjects.ContainsKey(parentInfo.Name)) { if (isProperties) { newProperty = new WoopsaAdsProperty(_woopsaObjects[parentInfo.Name], name, propertyType, _woopsaAdsPropertyGet, _woopsaAdsPropertySet, symbol); } else newObject = new WoopsaObject(_woopsaObjects[parentInfo.Name], name); } else { throw new Exception("Parent WoopsaObject not found !"); } } else { if (isProperties) { newProperty = new WoopsaAdsProperty(root, name, propertyType, _woopsaAdsPropertyGet, _woopsaAdsPropertySet, symbol); } else newObject = new WoopsaObject(root, name); } if (isProperties) _woopsaProperties.Add(symbol.Name, newProperty); else _woopsaObjects.Add(symbol.Name, newObject); } }catch(Exception e) { DiagnosticWindow.AddToDebug(e.Message); } isHierarchieLoaded = true; }
public void loadHierarchy(WoopsaObject root) { try { _symbolLoader = _tcAds.CreateSymbolInfoLoader(); _woopsaObjects = new Dictionary <string, WoopsaObject>(); _woopsaProperties = new Dictionary <string, WoopsaAdsProperty>(); foreach (TcAdsSymbolInfo symbol in _symbolLoader) { WoopsaObject newObject = null; WoopsaAdsProperty newProperty = null; TcAdsSymbolInfo parentInfo; WoopsaValueType propertyType; string[] path = symbol.Name.Split('.'); string name = path[path.Length - 1]; bool isProperties = BeckhoffToWoopsaValueType(symbol.Type, out propertyType); if (symbol.Parent != null) { parentInfo = symbol.Parent; if (_woopsaObjects.ContainsKey(parentInfo.Name)) { if (isProperties) { newProperty = new WoopsaAdsProperty(_woopsaObjects[parentInfo.Name], name, propertyType, _woopsaAdsPropertyGet, _woopsaAdsPropertySet, symbol); } else { newObject = new WoopsaObject(_woopsaObjects[parentInfo.Name], name); } } else { throw new Exception("Parent WoopsaObject not found !"); } } else { if (isProperties) { newProperty = new WoopsaAdsProperty(root, name, propertyType, _woopsaAdsPropertyGet, _woopsaAdsPropertySet, symbol); } else { newObject = new WoopsaObject(root, name); } } if (isProperties) { _woopsaProperties.Add(symbol.Name, newProperty); } else { _woopsaObjects.Add(symbol.Name, newObject); } } }catch (Exception e) { DiagnosticWindow.AddToDebug(e.Message); } isHierarchieLoaded = true; }
/// <summary> /// Parses an PLC array of type T. Supports pointered arrays (POINTER TO ...). /// In case of pointered array it will skipp NULL pointers and import only valid instances. /// </summary> /// <typeparam name="T"> /// Marshall type representation in .NET. See Beckhoff TwinCat 3 manual for an example. /// </typeparam> /// <param name="plcPath">The path in PLC to the array.</param> /// <param name="symbolLoader">The symbol loader instance.</param> /// <param name="twinCatClient">The adsClient instance.</param> /// <returns> /// Dictionary of imported and converted (.NET type) array elements and their pathes. /// </returns> public static IDictionary <string, T> GetArrayElementsWithPathes <T>(this TcAdsClient twinCatClient, TcAdsSymbolInfoLoader symbolLoader, string plcPath) { IDictionary <string, T> array = new Dictionary <string, T>(); TcAdsSymbolInfo arraySymbol = symbolLoader.FindSymbol(plcPath); if (arraySymbol == null) { return(array); } var stream = new AdsStream(8); var reader = new AdsBinaryReader(stream); TcAdsSymbolInfo elementSymbol = arraySymbol.FirstSubSymbol; while (elementSymbol != null) { stream.Position = 0; twinCatClient.Read(elementSymbol.IndexGroup, elementSymbol.IndexOffset, stream); var pointerValue = PlcSystem.IsX64Mode ? reader.ReadInt64() : reader.ReadInt32(); if (pointerValue != 0) { string plcArrayElementPath = elementSymbol.Name; if (elementSymbol.IsPointer) { plcArrayElementPath = string.Format("{0}^", plcArrayElementPath); } var handle = twinCatClient.CreateVariableHandle(plcArrayElementPath); try { var element = (T)twinCatClient.ReadAny(handle, typeof(T)); array.Add(plcArrayElementPath, element); } finally { twinCatClient.DeleteVariableHandle(handle); } } elementSymbol = elementSymbol.NextSymbol; } return(array); }