Exemplo n.º 1
0
        internal static AdsSymbolFlags Convert(AdsDataTypeFlags dataTypeFlags)
        {
            AdsSymbolFlags none = AdsSymbolFlags.None;

            if ((dataTypeFlags & (AdsDataTypeFlags.None | AdsDataTypeFlags.ReferenceTo)) == (AdsDataTypeFlags.None | AdsDataTypeFlags.ReferenceTo))
            {
                none |= AdsSymbolFlags.None | AdsSymbolFlags.ReferenceTo;
            }
            if ((dataTypeFlags & (AdsDataTypeFlags.None | AdsDataTypeFlags.TComInterfacePtr)) == (AdsDataTypeFlags.None | AdsDataTypeFlags.TComInterfacePtr))
            {
                none |= AdsSymbolFlags.None | AdsSymbolFlags.TComInterfacePtr;
            }
            if ((dataTypeFlags & AdsDataTypeFlags.BitValues) == AdsDataTypeFlags.BitValues)
            {
                none |= AdsSymbolFlags.BitValue;
            }
            if ((dataTypeFlags & (AdsDataTypeFlags.None | AdsDataTypeFlags.TypeGuid)) == (AdsDataTypeFlags.None | AdsDataTypeFlags.TypeGuid))
            {
                none |= AdsSymbolFlags.None | AdsSymbolFlags.TypeGuid;
            }
            if ((dataTypeFlags & (AdsDataTypeFlags.None | AdsDataTypeFlags.Persistent)) == (AdsDataTypeFlags.None | AdsDataTypeFlags.Persistent))
            {
                none |= AdsSymbolFlags.None | AdsSymbolFlags.Persistent;
            }
            return(none);
        }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 private void SetBitType(bool bitType)
 {
     if (bitType)
     {
         this.flags |= AdsSymbolFlags.BitValue;
     }
     else
     {
         this.flags &= AdsSymbolFlags.Attributes | AdsSymbolFlags.ContextMask | AdsSymbolFlags.ExtendedFlags | AdsSymbolFlags.InitOnReset | AdsSymbolFlags.ItfMethodAccess | AdsSymbolFlags.MethodDeref | AdsSymbolFlags.Persistent | AdsSymbolFlags.ReadOnly | AdsSymbolFlags.ReferenceTo | AdsSymbolFlags.Static | AdsSymbolFlags.TComInterfacePtr | AdsSymbolFlags.TypeGuid;
     }
 }
Exemplo n.º 4
0
        protected void SetContextMask(byte contextMask)
        {
            if (contextMask > 15)
            {
                throw new ArgumentOutOfRangeException("contextMask");
            }
            AdsSymbolFlags flags = ((AdsSymbolFlags)((ushort)(contextMask << 8))) & AdsSymbolFlags.ContextMask;

            this.flags &= AdsSymbolFlags.Attributes | AdsSymbolFlags.BitValue | AdsSymbolFlags.ExtendedFlags | AdsSymbolFlags.InitOnReset | AdsSymbolFlags.ItfMethodAccess | AdsSymbolFlags.MethodDeref | AdsSymbolFlags.Persistent | AdsSymbolFlags.ReadOnly | AdsSymbolFlags.ReferenceTo | AdsSymbolFlags.Static | AdsSymbolFlags.TComInterfacePtr | AdsSymbolFlags.TypeGuid;
            this.flags |= flags;
        }
Exemplo n.º 5
0
 public AdsSymbolEntryHeader(Type type)
 {
     EntryLength   = 0;
     IndexGroup    = 61445;
     IndexOffset   = 0; //to supply
     Size          = type == typeof(string) ? 81 : (uint)Marshal.SizeOf(type);
     DataType      = type.ToAdsDatatypeId();
     Flags         = AdsSymbolFlags.None;
     ArrayDim      = 0;
     NameLength    = 0; //to supply
     TypeLength    = (ushort)type.ToAdsDatatypeName().Length;
     CommentLength = 0;
 }
Exemplo n.º 6
0
 internal Instance(AdsSymbolEntry symbol)
 {
     this.comment      = symbol.comment;
     this.instanceName = symbol.name;
     this.size         = (int)symbol.size;
     this.typeName     = AlignTypeName(symbol.type);
     this.dataTypeId   = (AdsDatatypeId)symbol.dataType;
     this.flags        = symbol.flags;
     if ((symbol.attributeCount > 0) && (symbol.attributes != null))
     {
         this.attributes = new TypeAttributeCollection(symbol.attributes);
     }
 }
Exemplo n.º 7
0
 internal Instance(AdsFieldEntry subEntry)
 {
     this.comment       = subEntry.comment;
     this.instanceName  = subEntry.entryName;
     this.size          = (int)subEntry.size;
     this.typeName      = AlignTypeName(subEntry.typeName);
     this.dataTypeId    = subEntry.baseTypeId;
     this.flags         = DataTypeFlagConverter.Convert(subEntry.flags);
     this.staticAddress = (subEntry.flags & (AdsDataTypeFlags.None | AdsDataTypeFlags.Static)) != AdsDataTypeFlags.None;
     if (subEntry.HasAttributes && (subEntry.attributes != null))
     {
         this.attributes = new TypeAttributeCollection(subEntry.attributes);
     }
 }
Exemplo n.º 8
0
        public void Read(long parentEndPosition, Encoding encoding, AdsBinaryReader reader)
        {
            long position = reader.BaseStream.Position;

            this.entryLength = reader.ReadUInt32();
            long num2 = position + this.entryLength;

            this.indexGroup  = reader.ReadUInt32();
            this.indexOffset = reader.ReadUInt32();
            this.size        = reader.ReadUInt32();
            this.dataType    = reader.ReadUInt32();
            ushort num3 = reader.ReadUInt16();

            this.flags         = (AdsSymbolFlags)num3;
            this.arrayDim      = reader.ReadUInt16();
            this.nameLength    = reader.ReadUInt16();
            this.typeLength    = reader.ReadUInt16();
            this.commentLength = reader.ReadUInt16();
            this.name          = reader.ReadPlcString(this.nameLength + 1, encoding);
            this.type          = reader.ReadPlcString(this.typeLength + 1, encoding);
            this.comment       = reader.ReadPlcString(this.commentLength + 1, encoding);
            this.array         = SubStructureReader <AdsDatatypeArrayInfo> .Read(this.arrayDim, num2, encoding, reader);

            if (this.flags.HasFlag(AdsSymbolFlags.None | AdsSymbolFlags.TypeGuid))
            {
                this.typeGuid = new Guid(reader.ReadBytes(0x10));
            }
            if (this.flags.HasFlag(AdsSymbolFlags.Attributes))
            {
                this.attributeCount = reader.ReadUInt16();
                this.attributes     = SubStructureReader <AdsAttributeEntry> .Read(this.attributeCount, num2, encoding, reader);
            }
            if (this.flags.HasFlag(AdsSymbolFlags.ExtendedFlags))
            {
                this.extendedFlags = reader.ReadUInt32();
            }
            if (reader.BaseStream.Position != num2)
            {
                if (reader.BaseStream.Position <= num2)
                {
                    this.reserved = reader.ReadBytes((int)(num2 - reader.BaseStream.Position));
                }
                else
                {
                    object[] args = new object[] { this.name, this.type };
                    Module.Trace.TraceError("Reading Symbol entry for '{0}:{1}' failed!", args);
                    reader.BaseStream.Position = num2;
                }
            }
        }
Exemplo n.º 9
0
        private AdsSymbolFlags getSymbolFlags(ISymbol arrayParent, DataType elementType)
        {
            AdsSymbolFlags none = AdsSymbolFlags.None;
            ArrayType      type = (ArrayType)((DataType)arrayParent.DataType).ResolveType(DataTypeResolveStrategy.AliasReference);

            if (elementType != null)
            {
                none = DataTypeFlagConverter.Convert(elementType.Flags);
            }
            else if (type.ElementTypeId == AdsDatatypeId.ADST_BIT)
            {
                none |= AdsSymbolFlags.BitValue;
            }
            return(none | (((ISymbolFlagProvider)Unwrap(arrayParent)).Flags & (AdsSymbolFlags.None | AdsSymbolFlags.Persistent)));
        }
Exemplo n.º 10
0
 internal TcAdsSymbolInfo(AdsParseSymbols symbolParser, TcAdsSymbolInfo parent, int subIndex, AdsSymbolEntry symbolEntry, TcAdsDataType typeEntry) : this(symbolParser, parent, subIndex)
 {
     if (symbolEntry == null)
     {
         throw new ArgumentNullException("symbolEntry");
     }
     this.indexGroup  = symbolEntry.indexGroup;
     this.indexOffset = symbolEntry.indexOffset;
     this.size        = symbolEntry.size;
     this.dataTypeId  = (AdsDatatypeId)symbolEntry.dataType;
     if (typeEntry != null)
     {
         this.typeEntryFlags = typeEntry.Flags;
     }
     if (this.typeEntryFlags.HasFlag(AdsDataTypeFlags.None | AdsDataTypeFlags.Static))
     {
         this.indexGroup  = 0xf019;
         this.indexOffset = 0;
     }
     this.flags        = symbolEntry.flags;
     this.instancePath = symbolEntry.name;
     this.shortName    = symbolEntry.name;
     this.typeName     = symbolEntry.type;
     this.comment      = symbolEntry.comment;
     this.dataType     = typeEntry;
     if (((symbolEntry.array != null) || (typeEntry == null)) || !typeEntry.IsArray)
     {
         this.arrayInfo = symbolEntry.array;
     }
     else
     {
         this.arrayInfo = typeEntry.Dimensions.ToArray();
         if (typeEntry.Size != this.size)
         {
             this.size = (uint)typeEntry.Size;
         }
     }
     if (symbolEntry.attributes != null)
     {
         this.attributes = new TypeAttributeCollection(symbolEntry.attributes).AsReadOnly();
     }
     else
     {
         this.attributes = null;
     }
 }
Exemplo n.º 11
0
            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);
            }
Exemplo n.º 12
0
 internal TcAdsSymbolInfo(AdsParseSymbols symbolParser, TcAdsSymbolInfo parent, int subIndex, TcAdsDataType typeEntry) : this(symbolParser, parent, subIndex)
 {
     if (typeEntry == null)
     {
         throw new ArgumentNullException("typeEntry");
     }
     this.indexGroup     = (uint)parent.IndexGroup;
     this.indexOffset    = (uint)parent.IndexOffset;
     this.size           = (uint)typeEntry.Size;
     this.dataTypeId     = typeEntry.DataTypeId;
     this.typeEntryFlags = typeEntry.Flags;
     this.flags          = DataTypeFlagConverter.Convert(typeEntry.Flags);
     this.instancePath   = parent.Name;
     this.shortName      = parent.ShortName;
     this.typeName       = typeEntry.Name;
     this.comment        = typeEntry.Comment;
     this.dataType       = typeEntry;
     this.arrayInfo      = typeEntry.ArrayInfo;
     this.attributes     = typeEntry.Attributes;
 }
Exemplo n.º 13
0
        private void calcAccess(ISymbol parent, DataType memberType, int offset, AdsSymbolFlags symbolFlags, AdsDataTypeFlags flags, out uint indexGroup, out uint indexOffset)
        {
            ISymbol symbol    = Unwrap(parent);
            bool    isBitType = false;

            if (memberType != null)
            {
                isBitType = memberType.IsBitType;
            }
            bool flag2 = flags.HasFlag(AdsDataTypeFlags.None | AdsDataTypeFlags.Static);

            if ((flags & (AdsDataTypeFlags.None | AdsDataTypeFlags.PropItem)) == (AdsDataTypeFlags.None | AdsDataTypeFlags.PropItem))
            {
                indexGroup  = 0xf017;
                indexOffset = 0;
            }
            else if (flag2)
            {
                indexGroup  = 0xf019;
                indexOffset = 0;
            }
            else if (symbol.IsBitType | isBitType)
            {
                this.calcBitAccess(symbol, offset, symbolFlags, flags, out indexGroup, out indexOffset);
            }
            else if (this.IsDereferencedPointer)
            {
                indexGroup  = !isBitType ? 0xf014 : 0xf01a;
                indexOffset = 0;
            }
            else if (base.IsReference || this.IsDereferencedReference)
            {
                indexGroup  = !isBitType ? 0xf016 : 0xf01b;
                indexOffset = 0;
            }
            else
            {
                indexGroup  = ((IAdsSymbol)symbol).IndexGroup;
                indexOffset = ((IAdsSymbol)symbol).IndexOffset + ((uint)offset);
            }
        }
Exemplo n.º 14
0
        //array
        //guid
        //attributeCount
        //attributes
        //extended flags
        //reserve

        public AdsSymbolEntry(Unit unit)
        {
            EntryLength   = (uint)new AdsSymbolEntry().GetSize();
            IndexGroup    = 61445;
            IndexOffset   = 0;
            Size          = 1;
            DataType      = AdsDatatypeId.ADST_UINT8;
            Flags         = AdsSymbolFlags.None;
            ArrayDim      = 0;
            NameLength    = 4;
            TypeLength    = 4;
            CommentLength = 0;

            Name    = new byte[5];
            Type    = new byte[5];
            Comment = new byte[81];

            var nameBytes = Encoding.ASCII.GetBytes("Test");
            var typeBytes = Encoding.ASCII.GetBytes("BYTE");

            Array.Copy(nameBytes, Name, nameBytes.Length);
            Array.Copy(typeBytes, Type, typeBytes.Length);
        }
Exemplo n.º 15
0
 internal Instance()
 {
     this.flags = AdsSymbolFlags.None;
 }
Exemplo n.º 16
0
        private void calcBitAccess(ISymbol parent, int bitOffset, AdsSymbolFlags symbolFlags, AdsDataTypeFlags flags, out uint indexGroup, out uint indexOffset)
        {
            ISymbol symbol = Unwrap(parent);
            uint    num    = ((IAdsSymbol)symbol).IndexGroup;
            uint    num2   = ((IAdsSymbol)symbol).IndexOffset;

            if (!this.IsDereferencedPointer)
            {
                if (base.IsReference)
                {
                    goto TR_0002;
                }
                else if (!this.IsDereferencedReference)
                {
                    if (num > 0x4020)
                    {
                        if (num > 0x4040)
                        {
                            if ((num != 0xf020) && (num != 0xf030))
                            {
                                goto TR_0003;
                            }
                        }
                        else if ((num != 0x4030) && (num != 0x4040))
                        {
                            goto TR_0003;
                        }
                        goto TR_0004;
                    }
                    else if (((num == 0x4000) || (num == 0x4010)) || (num == 0x4020))
                    {
                        goto TR_0004;
                    }
                }
                else
                {
                    goto TR_0002;
                }
            }
            else
            {
                num  = 0xf01a;
                num2 = 0;
                goto TR_0000;
            }
            goto TR_0003;
TR_0000:
            indexGroup  = num;
            indexOffset = num2;
            return;

TR_0002:
            num  = 0xf01b;
            num2 = 0;
            goto TR_0000;
TR_0003:
            num2 = (num <= 0x100000) ? (num2 + ((uint)bitOffset)) : calcPidBitAddressing(num2, bitOffset);
            goto TR_0000;
TR_0004:
            num++;
            num2 = (num2 * 8) + ((uint)bitOffset);
            goto TR_0000;
        }