コード例 #1
0
 internal TcAdsSymbol(AdsSymbolEntry symbolEntry, TcAdsDataType typeEntry)
 {
     if (symbolEntry == null)
     {
         throw new ArgumentNullException("symbolEntry");
     }
     if (typeEntry == null)
     {
         object[] args = new object[] { symbolEntry.name };
         Module.Trace.TraceWarning("No data type found for AdsSymbolEntry '{0}'", args);
     }
     this._indexGroup      = symbolEntry.indexGroup;
     this._indexOffset     = symbolEntry.indexOffset;
     this._size            = symbolEntry.size;
     this._typeId          = (AdsDatatypeId)symbolEntry.dataType;
     this._typeEntryFlags  = typeEntry.Flags;
     this._flags           = symbolEntry.flags;
     this._name            = symbolEntry.name;
     this._typeName        = symbolEntry.type;
     this._comment         = symbolEntry.comment;
     this._arrayDimensions = symbolEntry.arrayDim;
     this._arrayInfos      = symbolEntry.array;
     this._attributeCount  = symbolEntry.attributeCount;
     this._attributes      = symbolEntry.attributes;
     this._dataType        = typeEntry;
 }
コード例 #2
0
        private TcAdsSymbolInfo CreateSymbolInfo(AdsSymbolEntry symbolEntry, int index)
        {
            ITcAdsDataType typeByName = this.GetTypeByName(symbolEntry.type);

            if (typeByName == null)
            {
                typeByName = (ITcAdsDataType)this.ResolveDataType(symbolEntry.type);
            }
            return(new TcAdsSymbolInfo(this, null, index, symbolEntry, (TcAdsDataType)typeByName));
        }
コード例 #3
0
        public AdsErrorCode TryGetSymbol(string symbolPath, bool bLookup, out ITcAdsSymbol symbol)
        {
            if (string.IsNullOrEmpty(symbolPath))
            {
                throw new ArgumentOutOfRangeException("name");
            }
            symbol = null;
            SymbolInfoTable table = this;

            lock (table)
            {
                if (bLookup)
                {
                    TcAdsSymbol symbol2 = null;
                    if (this._symbolTable.TryGetValue(symbolPath, out symbol2))
                    {
                        symbol = symbol2;
                        return(AdsErrorCode.NoError);
                    }
                }
            }
            AdsErrorCode deviceSymbolNotFound = AdsErrorCode.DeviceSymbolNotFound;
            AdsStream    stream = new AdsStream(symbolPath.Length + 1);

            using (AdsBinaryWriter writer = new AdsBinaryWriter(stream))
            {
                writer.WritePlcAnsiString(symbolPath, symbolPath.Length + 1);
                AdsStream rdDataStream = new AdsStream(0xffff);
                int       readBytes    = 0;
                deviceSymbolNotFound = this._adsClient.TryReadWrite(0xf009, 0, rdDataStream, 0, (int)rdDataStream.Length, stream, 0, (int)stream.Length, out readBytes);
                if (deviceSymbolNotFound == AdsErrorCode.NoError)
                {
                    using (AdsBinaryReader reader = new AdsBinaryReader(rdDataStream))
                    {
                        AdsSymbolEntry symbolEntry = new AdsSymbolEntry(-1L, this._encoding, reader);
                        bool           flag2       = true;
                        flag2  = StringComparer.OrdinalIgnoreCase.Compare(symbolPath, symbolEntry.name) == 0;
                        symbol = new TcAdsSymbol(symbolEntry, (TcAdsDataType)this._datatypeTable.ResolveDataType(symbolEntry.type));
                        SymbolInfoTable table2 = this;
                        lock (table2)
                        {
                            this._symbolTable[symbolPath] = (TcAdsSymbol)symbol;
                            if (!flag2 && !this._symbolTable.ContainsKey(symbol.Name))
                            {
                                this._symbolTable[symbol.Name] = (TcAdsSymbol)symbol;
                                string message = $"InstancePath Ambiguity '{symbolPath}' and '{symbol.Name}'!";
                                TwinCAT.Ads.Module.Trace.TraceWarning(message);
                            }
                        }
                    }
                }
            }
            return(deviceSymbolNotFound);
        }
コード例 #4
0
        private SymbolEntryCollection fillSymbolTables(AdsBinaryReader symbolReader, int symbolCount, out uint[] symbolEntryOffsets)
        {
            symbolEntryOffsets = new uint[symbolCount];
            SymbolEntryCollection entrys = new SymbolEntryCollection(symbolCount);
            uint      num        = 0;
            AdsStream baseStream = (AdsStream)symbolReader.BaseStream;

            baseStream.Position = 0L;
            while (num < baseStream.Length)
            {
                AdsSymbolEntry item = new AdsSymbolEntry((long)num, this._symbolEncoding, symbolReader);
                num += item.entryLength;
                try
                {
                    entrys.Add(item);
                }
                catch (Exception exception)
                {
                    Module.Trace.TraceError($"Cannot add symbol '{item.name}'. {exception.Message}", exception);
                }
            }
            return(entrys);
        }
コード例 #5
0
        public TcAdsSymbolInfo GetSymbol(int symbolIndex)
        {
            AdsSymbolEntry entry = null;

            return(!this._symbolTable.TryGetSymbol(symbolIndex, out entry) ? null : this.CreateSymbolInfo(entry, symbolIndex));
        }