Пример #1
0
        public object ReadArrayElement(IArrayInstance symbol, int[] indices, out DateTime utcReadTime)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }
            if (indices == null)
            {
                throw new ArgumentNullException("indices");
            }
            if (indices.Length == 0)
            {
                throw new ArgumentOutOfRangeException("indices");
            }
            int    num    = 0;
            object result = null;
            string str    = string.Join <int>(",", indices);

            num = this.tryReadValue(symbol, indices, out result, out utcReadTime);
            if (num == 0)
            {
                return(true);
            }
            Exception ex = new SymbolException($"Could not read ArrayInstance '{symbol.InstancePath}[{str}]'! Error: {num}", symbol);

            Module.Trace.TraceError(ex);
            throw ex;
        }
Пример #2
0
        public virtual void WriteValue(ISymbol symbol, object value, out DateTime utcWriteTime)
        {
            AdsErrorCode code = (AdsErrorCode)this.TryWriteValue(symbol, value, out utcWriteTime);

            if (code != AdsErrorCode.NoError)
            {
                SymbolException ex = null;
                ex = new SymbolException($"Could not write Symbol '{symbol} '! Error: {code}", symbol);
                Module.Trace.TraceError(ex);
                throw ex;
            }
        }
Пример #3
0
        public object ReadValue(ISymbol symbol, out DateTime utcReadTime)
        {
            object       obj2 = null;
            AdsErrorCode code = (AdsErrorCode)this.TryReadValue(symbol, out obj2, out utcReadTime);

            if (code == AdsErrorCode.NoError)
            {
                return(obj2);
            }
            SymbolException ex = null;

            ex = new SymbolException($"Could not read Symbol '{symbol}'! Error: {code}", symbol, AdsErrorException.Create(code));
            Module.Trace.TraceError(ex);
            throw ex;
        }
Пример #4
0
        public override void WriteValue(ISymbol symbol, object value, out DateTime utcWriteTime)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            int             num      = 0;
            ISymbol         symbol2  = symbol;
            IDataType       dataType = symbol2.DataType;
            IResolvableType type2    = dataType as IResolvableType;

            if (type2 != null)
            {
                dataType = type2.ResolveType(DataTypeResolveStrategy.AliasReference);
            }
            utcWriteTime = DateTime.MinValue;
            if (dataType.IsBitType)
            {
                num = this.tryWriteValue(symbol2, BitTypeConverter.Marshal(dataType.BitSize, value), 0, out utcWriteTime);
            }
            else if (!symbol2.IsPrimitiveType)
            {
                DynamicValue value2 = (DynamicValue)value;
                num = this.TryWriteValue(value2, out utcWriteTime);
            }
            else if (((dataType.Category == DataTypeCategory.Primitive) || (dataType.Category == DataTypeCategory.SubRange)) || (dataType.Category == DataTypeCategory.Pointer))
            {
                num = this.tryWriteValue(symbol2, PrimitiveTypeConverter.Default.Marshal(symbol2.DataType, value), 0, out utcWriteTime);
            }
            else if (dataType.Category == DataTypeCategory.String)
            {
                IStringType type3   = (IStringType)symbol2.DataType;
                byte[]      buffer3 = new PrimitiveTypeConverter(type3.Encoding).Marshal(symbol2.DataType, value);
                if (buffer3.Length >= type3.Size)
                {
                    Exception ex = new AdsErrorException($"String is too large for symbol '{symbol2.InstancePath}' (Type: {symbol2.TypeName}).", AdsErrorCode.DeviceInvalidSize);
                    Module.Trace.TraceError(ex);
                    throw ex;
                }
                num = this.tryWriteValue(symbol2, buffer3, 0, out utcWriteTime);
            }
            else if (dataType.Category == DataTypeCategory.Array)
            {
                IArrayType type4 = (IArrayType)symbol2.DataType;
                num = this.tryWriteValue(symbol2, PrimitiveTypeConverter.Default.Marshal(symbol2.DataType, value), 0, out utcWriteTime);
            }
            else
            {
                if (dataType.Category != DataTypeCategory.Enum)
                {
                    Exception ex = new SymbolException($"Could not write Symbol '{symbol2.InstancePath}' (Type: {symbol2.TypeName}). Category mismatch!", symbol2);
                    Module.Trace.TraceError(ex);
                    throw ex;
                }
                IEnumType type5 = (IEnumType)symbol2.DataType;
                num = this.tryWriteValue(symbol2, PrimitiveTypeConverter.Default.Marshal(symbol2.DataType, value), 0, out utcWriteTime);
            }
            if (num != 0)
            {
                Exception ex = new SymbolException($"Could not write Symbol '{symbol2.InstancePath}' (Type: {symbol2.TypeName})! Error: {num}", symbol2);
                Module.Trace.TraceError(ex);
                throw ex;
            }
        }