Exemple #1
0
 internal void Parse(AdsStream symbolStream, AdsStream dataTypeStream, TcAdsClient adsClient)
 {
     this._subSymbolFactory = new SubSymbolFactory(this);
     this._defaultTypes     = DataTypeInfoTable.GetDefaultTypes(this);
     this.OnTypesCreated(this._defaultTypes);
     object[] args = new object[] { adsClient.Address, symbolStream.Length, dataTypeStream.Length };
     Module.Trace.TraceInformation("Client: {0}, SymbolStream: {1} bytes, DataTypeStream: {2} bytes", args);
     this._adsClient = adsClient;
     using (AdsBinaryReader reader = new AdsBinaryReader(symbolStream))
     {
         using (AdsBinaryReader reader2 = new AdsBinaryReader(dataTypeStream))
         {
             uint[] numArray;
             uint[] numArray2;
             int    symbolCount = 0;
             symbolCount = this.countSymbols(reader);
             object[] objArray2 = new object[] { symbolCount };
             Module.Trace.TraceInformation("SymbolCount: {0}", objArray2);
             this._symbolTable = this.fillSymbolTables(reader, symbolCount, out numArray);
             int      dataTypeCount = this.countDataTypes(reader2);
             object[] objArray3     = new object[] { symbolCount };
             Module.Trace.TraceInformation("DataTypeCount: {0}", objArray3);
             Dictionary <string, int> dictionary = this.fillDataTypeTables(reader2, dataTypeCount, out numArray2);
             this._dataTypes = this.collectDataTypes(dataTypeCount, numArray2, reader2);
             this.expandDataTypes();
         }
     }
 }
        public void Clear()
        {
            DataTypeInfoTable table = this;

            lock (table)
            {
                this._dataTypes.Clear();
                this._dataTypes.AddRange(GetDefaultTypes(this));
            }
        }
Exemple #3
0
 internal SymbolInfoTable(IAdsConnection adsClient, Encoding symbolEncoding, int targetPointerSize)
 {
     if (adsClient == null)
     {
         throw new ArgumentNullException("adsClient");
     }
     if (symbolEncoding == null)
     {
         throw new ArgumentNullException("symbolEncoding");
     }
     this._adsClient     = adsClient;
     this._symbolTable   = new Dictionary <string, TcAdsSymbol>(StringComparer.OrdinalIgnoreCase);
     this._datatypeTable = new DataTypeInfoTable(adsClient, symbolEncoding, targetPointerSize);
     this._encoding      = symbolEncoding;
 }
        public AdsErrorCode TryLoadType(string name, bool lookup, out ITcAdsDataType type)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentOutOfRangeException("name");
            }
            if (lookup)
            {
                DataTypeInfoTable table = this;
                lock (table)
                {
                    if (this._dataTypes.TryGetDataType(name, out type))
                    {
                        return(AdsErrorCode.NoError);
                    }
                }
            }
            int  length    = 0;
            bool isUnicode = false;

            if (DataTypeStringParser.TryParseString(name, out length, out isUnicode))
            {
                int           byteCount = 0;
                AdsDatatypeId dataType  = AdsDatatypeId.ADST_VOID;
                if (isUnicode)
                {
                    char[] chars = new char[] { 'a' };
                    byteCount = Encoding.Unicode.GetByteCount(chars);
                    dataType  = AdsDatatypeId.ADST_WSTRING;
                }
                else
                {
                    char[] chars = new char[] { 'a' };
                    byteCount = Encoding.ASCII.GetByteCount(chars);
                    dataType  = AdsDatatypeId.ADST_STRING;
                }
                type = new TcAdsDataType(name, dataType, (uint)((length + 1) * byteCount), DataTypeCategory.String, typeof(string));
                DataTypeInfoTable table2 = this;
                lock (table2)
                {
                    this._dataTypes.Add(type);
                }
                this.OnTypeGenerated(type);
                return(AdsErrorCode.NoError);
            }
            AdsStream stream = new AdsStream(name.Length + 1);

            using (AdsBinaryWriter writer = new AdsBinaryWriter(stream))
            {
                writer.WritePlcString(name, name.Length + 1, this._encoding);
                AdsStream rdDataStream = new AdsStream(0xffff);
                try
                {
                    int num3 = this._adsClient.ReadWrite(0xf011, 0, rdDataStream, stream);
                }
                catch (AdsErrorException exception1)
                {
                    if (exception1.ErrorCode != AdsErrorCode.DeviceSymbolNotFound)
                    {
                        throw;
                    }
                    type = null;
                }
                using (AdsBinaryReader reader = new AdsBinaryReader(rdDataStream))
                {
                    AdsDataTypeEntry entry = new AdsDataTypeEntry(true, this._encoding, reader);
                    type = new TcAdsDataType(entry, this);
                    DataTypeInfoTable table3 = this;
                    lock (table3)
                    {
                        this._dataTypes.Add(type);
                    }
                }
            }
            if (type != null)
            {
                return(AdsErrorCode.NoError);
            }
            this.OnResolveError(name);
            return(AdsErrorCode.DeviceSymbolNotFound);
        }