コード例 #1
0
        /// <summary>
        /// Initializes the object with its item id and device.
        /// </summary>
        public CacheItem(string itemID, IDevice device)
        {
            if (itemID == null) throw new ArgumentNullException("itemID");
            if (device == null) throw new ArgumentNullException("device");

            m_itemID = itemID;
            m_device = device;

            m_datatype = (System.Type)ReadProperty(Property.DATATYPE);
            m_euType   = (euType)ReadProperty(Property.EUTYPE);

            if (m_euType == euType.enumerated)
            {
                m_euInfo = (string[])ReadProperty(Property.EUINFO);
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes the object with its item id and device.
        /// </summary>
        public SubscriptionItem(string itemID, Cache cache)
        {
            if (itemID == null) throw new ArgumentNullException("itemID");
            if (cache == null)  throw new ArgumentNullException("cache");

            m_itemID = itemID;
            m_cache  = cache;

            m_euType = (euType)m_cache.ReadProperty(m_itemID, Property.EUTYPE);

            if (m_euType == euType.analog)
            {
                m_maxValue = (double)m_cache.ReadProperty(m_itemID, Property.HIGHEU);
                m_minValue = (double)m_cache.ReadProperty(m_itemID, Property.LOWEU);
            }
        }
コード例 #3
0
        /// <summary>
        /// Reads an item property from an XML stream.
        /// </summary>
        private void ReadProperty(XmlTextReader reader)
        {
            // look up the property id.
            PropertyDescription property = null;

            if (reader.MoveToAttribute(PROPERTY_ID))
            {
                try
                {
                    property = PropertyDescription.Find(new PropertyID(((int)System.Convert.ToInt32(reader.Value))));
                }
                catch
                {
                    property = null;
                }
            }

            // ignore invalid properties.
            if (property == null)
            {
                return;
            }

            // read value.
            object value = ReadValue(reader, property.Type);

            switch (property.ID.Code)
            {
                case QUALITY:      { m_quality      = (Quality)value;         break; }
                case TIMESTAMP:    { m_timestamp    = (DateTime)value;        break; }
                case ACCESSRIGHTS: { m_accessRights = (accessRights)value;    break; }
                case SCANRATE:     { m_scanRate     = (float)value;           break; }
                case EUTYPE:       { m_euType       = (euType)((int)value+1); break; }
                case EUINFO:       { m_euInfo       = (string[])value;        break; }
                case HIGHEU:       { m_maxValue     = (double)value;          break; }
                case LOWEU:        { m_minValue     = (double)value;          break; }

                default:
                {
                    m_properties[property.ID] = value;
                    break;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Writes the value of the specified item property.
        /// </summary>
        public Opc.IdentifiedResult Write(
            PropertyID       propertyID,
            Opc.Da.ItemValue value)
        {
            // initialize result and validate property.
            IdentifiedResult result = new IdentifiedResult();

            result.ItemName       = m_itemID;
            result.ItemPath       = null;
            result.ResultID       = ValidatePropertyID(propertyID, accessRights.writable);
            result.DiagnosticInfo = null;

            // handle value writes.
            if (propertyID == Property.VALUE)
            {
                // copy value.
                m_value = Opc.Convert.Clone(value.Value);

                // update quality if specified.
                if (value.QualitySpecified)
                {
                    m_quality = value.Quality;
                }

                // update timestamp if specified.
                if (value.TimestampSpecified)
                {
                    m_timestamp = value.Timestamp;
                }

                // return results.
                return result;
            }

            // lookup property description.
            PropertyDescription property = PropertyDescription.Find(propertyID);

            if (property == null)
            {
                result.ResultID = ResultID.Da.E_INVALID_PID;
                return result;
            }

            // check datatype.
            if (!property.Type.IsInstanceOfType(value.Value))
            {
                result.ResultID = ResultID.Da.E_BADTYPE;
                return result;
            }

            // write non-value
            switch (propertyID.Code)
            {
                // standard properties.
                case DATATYPE:      { m_datatype     = (System.Type)value.Value;                 return result; }
                case QUALITY:       { m_quality      = (Quality)value.Value;                     return result; }
                case TIMESTAMP:     { m_timestamp    = (DateTime)value.Value;                    return result; }
                case ACCESSRIGHTS:  { m_accessRights = (accessRights)value.Value;                return result; }
                case SCANRATE:      { m_scanRate     = (float)value.Value;                       return result; }
                case EUTYPE:        { m_euType       = (euType)value.Value;                      return result; }
                case EUINFO:        { m_euInfo       = (string[])Opc.Convert.Clone(value.Value); return result; }
                case HIGHEU:        { m_maxValue     = (double)value.Value;                      return result; }
                case LOWEU:         { m_minValue     = (double)value.Value;                      return result; }

                // other defined properties.
                default:
                {
                    if (!m_properties.Contains(propertyID))
                    {
                        result.ResultID = ResultID.Da.E_INVALID_PID;
                        return result;
                    }

                    m_properties[propertyID] = Opc.Convert.Clone(value.Value);
                    break;
                }
            }

            // write complete.
            return result;
        }