private void calcArrayElementIndexGroupIndexOffset(int subIndex, TcAdsSymbolInfo arrayInstance, int elementSize, out uint indexGroup, out uint indexOffset) { TcAdsDataType dataType = (TcAdsDataType)arrayInstance.DataType; bool isBitType = arrayInstance.IsBitType; if ((dataType.Flags & (AdsDataTypeFlags.None | AdsDataTypeFlags.PropItem)) == (AdsDataTypeFlags.None | AdsDataTypeFlags.PropItem)) { indexGroup = 0xf017; indexOffset = dataType.TypeHashValue; } else if (isBitType) { this.calcBitAccessAddress(arrayInstance, 0, out indexGroup, out indexOffset); } else if (arrayInstance.IsReference || arrayInstance.IsDereferencedReference) { indexGroup = 0xf016; indexOffset = 0; } else { indexGroup = (uint)arrayInstance.IndexGroup; indexOffset = ((uint)arrayInstance.IndexOffset) + ((uint)(elementSize * subIndex)); } }
public WoopsaAdsProperty(WoopsaObject container, string name, WoopsaValueType type, WoopsaPropertyGet get, WoopsaPropertySet set, TcAdsSymbolInfo adsInfo) : base(container, name, type, get, set) { string[] path = adsInfo.Name.Split('.'); RootName = path[0]; AdsInfo = adsInfo; }
internal TcAdsSymbolInfo CreateReferenceSymbol(TcAdsSymbolInfo parent, int subIndex) { if (parent == null) { throw new ArgumentNullException("parent"); } TcAdsSymbolInfo subSymbol = null; if (subIndex == 0) { TcAdsDataType dataType = (TcAdsDataType)parent.DataType; string referencedType = string.Empty; if (DataTypeStringParser.TryParseReference(parent.DataType.Name, out referencedType)) { TcAdsDataType typeByName = (TcAdsDataType)this._parser.GetTypeByName(referencedType); if (typeByName != null) { subSymbol = new TcAdsSymbolInfo(this._parser, parent, subIndex, typeByName); this.calcFieldAddress(parent, subSymbol, null, out subSymbol.indexGroup, out subSymbol.indexOffset); } else { object[] args = new object[] { referencedType }; Module.Trace.TraceWarning("Cannot create Reference Symbol. Dereferenced Type '{0}' not found!", args); } } } return(subSymbol); }
public TcAdsSymbolInfo GetSymbol(string symbolName) { TcAdsSymbolInfo symbol = null; int index = symbolName.IndexOf('.'); string str = null; do { char[] anyOf = new char[] { '.', '[' }; int length = symbolName.IndexOfAny(anyOf, index + 1); str = (length == -1) ? symbolName : symbolName.Substring(0, length); symbol = this.CreateSymbolInfo(str); if ((symbol != null) && (length != -1)) { symbol = this.GetSubSymbol(symbol, symbolName, length); break; } index = symbolName.IndexOf('.', index + 1); }while (index >= 0); if (symbol == null) { symbol = this.CreateSymbolInfo(symbolName); } return(symbol); }
internal TcAdsSymbolInfo CreatePointerSymbol(TcAdsSymbolInfo parent, TcAdsDataType referencedType) { if (parent == null) { throw new ArgumentNullException("parent"); } if (referencedType == null) { throw new ArgumentNullException("referencedType"); } return(new TcAdsSymbolInfo(this._parser, parent, 0) { indexGroup = !referencedType.IsBitType ? 0xf014 : 0xf01a, indexOffset = 0, size = (uint)referencedType.Size, typeName = referencedType.Name, dataTypeId = referencedType.DataTypeId, comment = string.Empty, instancePath = parent.instancePath + "^", shortName = parent.shortName + "^", typeEntryFlags = parent.typeEntryFlags, flags = parent.flags, arrayInfo = parent.arrayInfo }); }
internal TcAdsSymbolInfo GetSubSymbol(TcAdsSymbolInfo parent, int subIndex, bool dereference) { if (parent == null) { throw new ArgumentNullException("parent"); } TcAdsSymbolInfo info = null; try { ITcAdsDataType dataType = parent.DataType; ITcAdsDataType type2 = null; if (dataType != null) { type2 = (ITcAdsDataType)dataType.ResolveType(DataTypeResolveStrategy.AliasReference); } if (type2 != null) { int count = parent.SubSymbols.Count; if (((type2 != null) && (type2.SubItems.Count > 0)) && (subIndex < type2.SubItems.Count)) { info = this._subSymbolFactory.CreateSubSymbol(parent, subIndex); } else if ((type2 != null) && ((type2.Dimensions.Count > 0) || DataTypeStringParser.IsArray(type2.Name))) { info = this._subSymbolFactory.CreateArrayElement(parent, (TcAdsDataType)type2, subIndex); } else if ((type2 != null) && type2.IsReference) { this.SetPlatformPointerSize(type2.Size); } else if ((subIndex == 0) && type2.IsPointer) { this.SetPlatformPointerSize(type2.Size); if (dereference) { string str; DataTypeStringParser.TryParsePointer(type2.Name, out str); TcAdsDataType referencedType = (TcAdsDataType)this.ResolveDataType(str); if ((referencedType != null) & dereference) { bool flag = (referencedType.Flags & AdsDataTypeFlags.AnySizeArray) == AdsDataTypeFlags.AnySizeArray; if ((referencedType.Size > 0) | flag) { info = this._subSymbolFactory.CreatePointerSymbol(parent, referencedType); } } } } } } catch (Exception exception) { Module.Trace.TraceError($"ParentSymbol: {parent.Name}", exception); throw; } return(info); }
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); } }
private TcAdsSymbolInfo CreateSymbolInfo(string symbolName) { TcAdsSymbolInfo info = null; IList <AdsSymbolEntry> entry = null; if (this._symbolTable.TryGetSymbol(symbolName, out entry)) { int index = this._symbolTable.IndexOf(entry[0]); info = this.CreateSymbolInfo(entry[0], index); } return(info); }
internal TcAdsSymbolInfo CreateSubSymbol(TcAdsSymbolInfo parent, int subIndex) { if (parent == null) { throw new ArgumentNullException("parent"); } ITcAdsDataType dataType = parent.DataType; if (dataType == null) { throw new ArgumentException("DataType not specified", "parent"); } if (((subIndex < 0) || (dataType.SubItems == null)) || (subIndex >= dataType.SubItems.Count)) { throw new ArgumentOutOfRangeException("subIndex"); } TcAdsSymbolInfo subSymbol = null; if (parent.IsPointer && (subIndex > 0)) { throw new ArgumentOutOfRangeException("subIndex"); } TcAdsSubItem typeSubEntry = (TcAdsSubItem)dataType.SubItems[subIndex]; TcAdsDataType typeByName = (TcAdsDataType)this._parser.GetTypeByName(typeSubEntry.Name); if (typeSubEntry != null) { if (typeByName != null) { typeSubEntry.AlignSubItemToType(typeByName); } subSymbol = new TcAdsSymbolInfo(this._parser, parent, subIndex) { size = (uint)typeSubEntry.Size, dataTypeId = typeSubEntry.DataTypeId, typeEntryFlags = this.createTypeEntryFlags(parent, typeSubEntry), flags = this.createSubSymbolFlags(parent, typeSubEntry), shortName = typeSubEntry.SubItemName }; subSymbol.instancePath = $"{parent.instancePath}.{subSymbol.shortName}"; subSymbol.typeName = typeSubEntry.Name; subSymbol.comment = typeSubEntry.Comment; subSymbol.arrayInfo = typeSubEntry.ArrayInfo; subSymbol.attributes = typeSubEntry.Attributes; this.calcFieldAddress(parent, subSymbol, typeSubEntry, out subSymbol.indexGroup, out subSymbol.indexOffset); } return(subSymbol); }
private AdsSymbolFlags createElementSymbolFlags(TcAdsSymbolInfo arrayInstance, TcAdsDataType elementType) { AdsSymbolFlags none = AdsSymbolFlags.None; if (elementType != null) { none = DataTypeFlagConverter.Convert(elementType.Flags); } none = (none & (AdsSymbolFlags.Attributes | AdsSymbolFlags.BitValue | AdsSymbolFlags.ExtendedFlags | AdsSymbolFlags.InitOnReset | AdsSymbolFlags.ItfMethodAccess | AdsSymbolFlags.MethodDeref | AdsSymbolFlags.Persistent | AdsSymbolFlags.ReadOnly | AdsSymbolFlags.ReferenceTo | AdsSymbolFlags.Static | AdsSymbolFlags.TComInterfacePtr | AdsSymbolFlags.TypeGuid)) | (AdsSymbolFlags.ContextMask & arrayInstance.flags); if (arrayInstance.IsBitType) { none |= AdsSymbolFlags.BitValue; } if (arrayInstance.IsPersistent) { none |= AdsSymbolFlags.None | AdsSymbolFlags.Persistent; } return(none); }
/// <summary> /// Reads an elements array of type TElement. Supports pointered arrays (POINTER TO ...). /// </summary> /// <typeparam name="TElement">Marshall type representation in .NET. See Beckhoff TwinCat 3 manual for an example.</typeparam> /// <param name="elementsArrayPath">The path in PLC to the array.</param> /// <returns> /// A dictionary of imported and converted (.NET type) array elements (value) sorted by their pathes (key). /// </returns> public IDictionary <string, TElement> ReadElementsArrayWithPathes <TElement>(string elementsArrayPath) { _logger.Debug(string.Format("Read elements array of type '{0}' from path '{1}' on '{2}'.", typeof(TElement).Name, elementsArrayPath, this)); IDictionary <string, TElement> array = new Dictionary <string, TElement>(); var arraySymbol = _symbolLoader.FindSymbol(elementsArrayPath); 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 element = ReadElement <TElement>(plcArrayElementPath); array.Add(plcArrayElementPath, element); } elementSymbol = elementSymbol.NextSymbol; } _logger.Debug(string.Format("Finished read of elements array of type '{0}' from path '{1}' on '{2}'.", typeof(TElement).Name, elementsArrayPath, this)); return(array); }
private int calcElementBaseSize(TcAdsSymbolInfo parentArrayInstance) { TcAdsDataType type = (TcAdsDataType)parentArrayInstance.DataType.ResolveType(DataTypeResolveStrategy.AliasReference); int size = type.Size; bool isBitType = parentArrayInstance.IsBitType; ReadOnlyDimensionCollection dimensions = type.Dimensions; for (int i = type.Dimensions.Count - 1; i >= 0; i--) { if (isBitType) { size = 1; } else if (dimensions[i].ElementCount > 0) { size /= dimensions[i].ElementCount; } } return(size); }
public WoopsaAdsProperty(WoopsaObject container, string name, WoopsaValueType type, WoopsaPropertyGet get, TcAdsSymbolInfo adsInfo) : this(container, name, type, get, null, adsInfo) { }