private void Cleanup() { this._datatypeTable.Clear(); if (this._symbolTable.Count > 0) { uint[] numArray = new uint[this._symbolTable.Count]; int index = 0; SymbolInfoTable table = this; lock (table) { foreach (KeyValuePair <string, TcAdsSymbol> pair in this._symbolTable) { if (index < numArray.Length) { if (pair.Value.IndexGroup == 0xf005L) { index++; numArray[index] = (uint)pair.Value.IndexOffset; continue; } index++; numArray[index] = 0; } } this._symbolTable.Clear(); } for (int i = 0; i < index; i++) { this._adsClient.RawInterface.Write(0xf006, 0, numArray[i], false); } } }
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); }