Ejemplo n.º 1
0
        internal AdsSymbolLoader(IAdsConnection connection, SymbolLoaderSettings settings, IAccessorRawValue accessor, ISession session, SymbolUploadInfo symbolsInfo)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (accessor == null)
            {
                throw new ArgumentNullException("accessor");
            }
            if (symbolsInfo == null)
            {
                throw new ArgumentNullException("symbolsInfo");
            }
            ISymbolFactory symbolFactory = null;

            this._connection       = connection;
            this._symbolUploadInfo = symbolsInfo;
            symbolFactory          = (settings.SymbolsLoadMode != SymbolsLoadMode.DynamicTree) ? ((ISymbolFactory) new TwinCAT.Ads.TypeSystem.SymbolFactory(settings.NonCachedArrayElements)) : ((ISymbolFactory) new DynamicSymbolFactory(new TwinCAT.Ads.TypeSystem.SymbolFactory(settings.NonCachedArrayElements), settings.NonCachedArrayElements));
            this._settings         = settings;
            AdsBinder binder = new AdsBinder(this._connection.Address, this, symbolFactory, this.UseVirtualInstances);

            this._symbolFactorServices = new SymbolFactoryServices(binder, symbolFactory, accessor, session);
            symbolFactory.Initialize(this._symbolFactorServices);
            this._rootNamespace = this._connection.Address.ToString();
            this._namespaces    = new NamespaceCollection();
        }
Ejemplo n.º 2
0
        internal static SymbolUploadInfo readSymbolUploadInfo(IAdsConnection connection)
        {
            SymbolUploadInfo uploadInfo   = null;
            AdsErrorCode     adsErrorCode = AdsSymbolLoader.loadUploadInfo(connection, TimeSpan.FromMilliseconds((double)connection.Timeout), out uploadInfo);

            if (adsErrorCode != AdsErrorCode.NoError)
            {
                AdsErrorException ex = AdsErrorException.Create(adsErrorCode);
                Module.Trace.TraceWarning("Could not load Symbol Upload info", ex);
                uploadInfo = new SymbolUploadInfo();
            }
            return(uploadInfo);
        }
Ejemplo n.º 3
0
 internal TcAdsSymbolInfoLoader(TcAdsClient adsClient, SymbolUploadInfo symbolInfo)
 {
     if (adsClient == null)
     {
         throw new ArgumentNullException("adsClient");
     }
     if (symbolInfo == null)
     {
         throw new ArgumentNullException("symbolInfo");
     }
     this._adsClient  = adsClient;
     this._symbols    = null;
     this._symbolInfo = symbolInfo;
 }
Ejemplo n.º 4
0
 private bool initializeUploadSymbols(bool forceReload)
 {
     if (forceReload || (this._symbolParser == null))
     {
         this._symbols    = null;
         this._dataTypes  = null;
         this._symbolInfo = null;
         this.onUploadSymbols();
     }
     if (this._symbolParser == null)
     {
         return(false);
     }
     this._symbols   = new TcAdsSymbolInfoCollection(this._symbolParser);
     this._dataTypes = this._symbolParser.GetDataTypes();
     return(true);
 }
Ejemplo n.º 5
0
 private void onUploadSymbols()
 {
     using (new MethodTrace())
     {
         this._symbolParser  = null;
         this._isEnumerating = false;
         try
         {
             int timeout = this._adsClient.Timeout;
             this._adsClient.Timeout = 0x7530;
             try
             {
                 if (this._symbolInfo == null)
                 {
                     this._symbolInfo = this.readUploadInfo();
                 }
                 bool containsBaseTypes = this._symbolInfo.ContainsBaseTypes;
                 Module.Trace.TraceInformation(this._symbolInfo.Dump());
                 AdsStream symbolStream = new AdsStream(this._symbolInfo.SymbolsBlockSize);
                 this.readSymbols(symbolStream, this._symbolInfo, 0x10000);
                 Module.Trace.TraceInformation("Symbols uploaded successfully!");
                 AdsStream datatypeStream = new AdsStream(this._symbolInfo.DataTypesBlockSize);
                 this.readDataTypes(datatypeStream, this._symbolInfo, 0x10000);
                 Module.Trace.TraceInformation("DataTypes uploaded successfully!");
                 this._symbolParser = new AdsParseSymbols(this._symbolInfo.TargetPointerSize, this._symbolInfo.ContainsBaseTypes, this._symbolInfo.StringEncoding);
                 this._symbolParser.TypeResolveError += new EventHandler <DataTypeNameEventArgs>(this._symbolParser_ResolveError);
                 this._symbolParser.TypesGenerated   += new EventHandler <DataTypeEventArgs>(this._symbolParser_TypesGenerated);
                 this._symbolParser.Parse(symbolStream, datatypeStream, this._adsClient);
             }
             finally
             {
                 this._adsClient.Timeout = timeout;
             }
         }
         catch (Exception exception)
         {
             Module.Trace.TraceError(exception);
             throw;
         }
     }
 }
Ejemplo n.º 6
0
        private SymbolUploadInfo readUploadInfo()
        {
            AdsStream dataStream = new AdsStream(0x40);

            try
            {
                int version = SymbolUploadInfo.CalcVersion(this._adsClient.Read(0xf00f, 0, dataStream));
                dataStream.Position = 0L;
                return(new SymbolUploadInfo(new BinaryReader(dataStream), version));
            }
            catch (AdsErrorException exception1)
            {
                if (exception1.ErrorCode != AdsErrorCode.DeviceServiceNotSupported)
                {
                    throw;
                }
                int version = SymbolUploadInfo.CalcVersion(this._adsClient.Read(0xf00c, 0, dataStream));
                dataStream.Position = 0L;
                return(new SymbolUploadInfo(new BinaryReader(dataStream), version));
            }
        }
Ejemplo n.º 7
0
        public static ISymbolLoader Create(IConnection connection, ISymbolLoaderSettings settings)
        {
            SymbolUploadInfo symbolsInfo = readSymbolUploadInfo((IAdsConnection)connection);

            return(new AdsSymbolLoader((IAdsConnection)connection, (SymbolLoaderSettings)settings, createValueAccessor((IAdsConnection)connection, (SymbolLoaderSettings)settings), ((IAdsConnection)connection).Session, symbolsInfo));
        }
Ejemplo n.º 8
0
        private unsafe void readSymbols(AdsStream symbolStream, SymbolUploadInfo info, int initialBlockSize)
        {
            int num = initialBlockSize;

            if (info.SymbolsBlockSize < num)
            {
                this._adsClient.Read(0xf00b, 0, symbolStream);
            }
            else
            {
                uint         num2   = 0;
                int          num3   = 0;
                int          num4   = 0;
                int          num5   = 0;
                int          length = 0;
                BinaryReader reader = new BinaryReader(symbolStream);
                while (true)
                {
                    int dataRead = 0;
                    while (true)
                    {
                        byte[] buffer;
                        length = ((num3 + num) <= symbolStream.Length) ? num : (((int)symbolStream.Length) - num3);
                        if (((buffer = symbolStream.GetBuffer()) == null) || (buffer.Length == 0))
                        {
                            numRef = null;
                        }
                        else
                        {
                            numRef = buffer;
                        }
                        AdsErrorCode adsErrorCode = this._adsClient.RawInterface.Read(0xf00b, 0x80000000 | num2, length, (void *)(numRef + num3), false, out dataRead);
                        fixed(byte *numRef = null)
                        {
                            if (adsErrorCode != AdsErrorCode.NoError)
                            {
                                if (adsErrorCode == AdsErrorCode.DeviceInvalidSize)
                                {
                                    num *= 4;
                                }
                                else
                                {
                                    TcAdsDllWrapper.ThrowAdsException(adsErrorCode);
                                }
                            }
                            if (adsErrorCode == AdsErrorCode.NoError)
                            {
                                num  = initialBlockSize;
                                num4 = num3;
                                num5 = 0;
                                symbolStream.Position = num3;
                                num5 = reader.ReadInt32();
                                while (true)
                                {
                                    if ((num5 > 0) && (num2 < info.SymbolCount))
                                    {
                                        num4 += num5;
                                        symbolStream.Position = num4;
                                        num2++;
                                        if ((num4 < (num3 + num)) && (num4 < symbolStream.Length))
                                        {
                                            num5 = reader.ReadInt32();
                                            continue;
                                        }
                                    }
                                    num3 = num4;
                                    if ((num2 < info.SymbolCount) && (num3 < symbolStream.Length))
                                    {
                                        break;
                                    }
                                    symbolStream.Position = 0L;
                                    return;
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }