public void                                     modifyItem(DataItem aItem, string aNewTagName)
        {
            if (aItem.mTagName.Equals(aNewTagName, StringComparison.Ordinal) == false)
            {
                SDataValue lSDValue = new SDataValue();
                lSDValue.Type = EPrimitiveDataType.Unspecific;

                if (mConnected)
                {
                    try
                    {
                        lSDValue = mPLC.Read(aNewTagName);
                    }
                    catch (SimulationRuntimeException lExc)
                    {
                        throw new InvalidOperationException(ErrorCodeMessage(lExc.RuntimeErrorCode), lExc);
                    }

                    if (lSDValue.Type == EPrimitiveDataType.Struct ||
                        lSDValue.Type == EPrimitiveDataType.Unspecific)
                    {
                        throw new InvalidOperationException("Type is not supported. ");
                    }
                }

                mItemListLock.EnterWriteLock();
                //========================================
                try
                {
                    aItem.mTagName   = aNewTagName;
                    mItemListChanged = true;
                }
                finally
                {
                    //========================================
                    mItemListLock.ExitWriteLock();
                }

                aItem.raisePropertiesChanged();
                if (lSDValue.Type != EPrimitiveDataType.Unspecific)
                {
                    aItem.setValue(lSDValue);
                }
            }
        }
示例#2
0
        public SDataValue           getValue()
        {
            var lValue = new SDataValue();

            lValue.Type = mPDataType;

            switch (mPDataType)
            {
            case EPrimitiveDataType.Bool:   lValue.Bool = (bool)mValue; break;

            case EPrimitiveDataType.Int8:   lValue.Int8 = (sbyte)mValue; break;

            case EPrimitiveDataType.Int16:  lValue.Int16 = (short)mValue; break;

            case EPrimitiveDataType.Int32:  lValue.Int32 = (int)mValue; break;

            case EPrimitiveDataType.Int64:  lValue.Int64 = (long)mValue; break;

            case EPrimitiveDataType.UInt8:  lValue.UInt8 = (byte)mValue; break;

            case EPrimitiveDataType.UInt16: lValue.UInt16 = (ushort)mValue; break;

            case EPrimitiveDataType.UInt32: lValue.UInt32 = (uint)mValue; break;

            case EPrimitiveDataType.UInt64: lValue.UInt64 = (ulong)mValue; break;

            case EPrimitiveDataType.Float:  lValue.Float = (float)mValue; break;

            case EPrimitiveDataType.Double: lValue.Double = (double)mValue; break;

            case EPrimitiveDataType.Char:   lValue.Char = (sbyte)mValue; break;

            case EPrimitiveDataType.WChar:  lValue.WChar = (char)mValue; break;

            default:                        throw new InvalidOperationException("Type is not supported. ");
            }

            return(lValue);
        }
示例#3
0
        public void                 setValue(SDataValue aValue)
        {
            if (mNeedWrite)
            {
                return;
            }

            mPDataType = aValue.Type;

            object lNewValue;

            switch (aValue.Type)
            {
            case EPrimitiveDataType.Bool:   lNewValue = aValue.Bool; break;

            case EPrimitiveDataType.Int8:   lNewValue = aValue.Int8; break;

            case EPrimitiveDataType.Int16:  lNewValue = aValue.Int16; break;

            case EPrimitiveDataType.Int32:  lNewValue = aValue.Int32; break;

            case EPrimitiveDataType.Int64:  lNewValue = aValue.Int64; break;

            case EPrimitiveDataType.UInt8:  lNewValue = aValue.UInt8; break;

            case EPrimitiveDataType.UInt16: lNewValue = aValue.UInt16; break;

            case EPrimitiveDataType.UInt32: lNewValue = aValue.UInt32; break;

            case EPrimitiveDataType.UInt64: lNewValue = aValue.UInt64; break;

            case EPrimitiveDataType.Float:  lNewValue = aValue.Float; break;

            case EPrimitiveDataType.Double: lNewValue = aValue.Double; break;

            case EPrimitiveDataType.Char:   lNewValue = aValue.Char; break;

            case EPrimitiveDataType.WChar:  lNewValue = aValue.WChar; break;

            default:                        throw new InvalidOperationException("Type is not supported. ");
            }

            bool lValueChanged = false;

            Monitor.Enter(mValueLock);
            //=========================================
            try
            {
                if (mNeedWrite)
                {
                    return;
                }

                if (ValuesCompare.isNotEqual(mValue, lNewValue))
                {
                    mValue        = lNewValue;
                    lValueChanged = true;
                }
            }
            finally
            {
                //=========================================
                Monitor.Exit(mValueLock);
            }

            if (lValueChanged)
            {
                raiseValueChanged();
            }
        }