internal static OPCITEMPROPERTY GetItemProperty(ItemProperty input) { OPCITEMPROPERTY result = default(OPCITEMPROPERTY); if (input != null) { result.dwPropertyID = input.ID.Code; result.szDescription = input.Description; result.vtDataType = (short)OpcCom.Interop.GetType(input.DataType); result.vValue = MarshalPropertyValue(input.ID, input.Value); result.wReserved = 0; result.hrErrorID = OpcCom.Interop.GetResultID(input.ResultID); PropertyDescription propertyDescription = PropertyDescription.Find(input.ID); if (propertyDescription != null) { result.vtDataType = (short)OpcCom.Interop.GetType(propertyDescription.Type); } if (input.ResultID == ResultID.Da.E_WRITEONLY) { result.hrErrorID = -1073479674; } } return(result); }
/// <summary> /// Allocates and marshals an arary of OPCITEMPROPERTY structures. /// </summary> internal static OpcRcw.Da.OPCITEMPROPERTY GetItemProperty(ItemProperty input) { OpcRcw.Da.OPCITEMPROPERTY output = new OpcRcw.Da.OPCITEMPROPERTY(); if (input != null) { output.dwPropertyID = input.ID.Code; output.szDescription = input.Description; output.vtDataType = (short)OpcCom.Interop.GetType(input.DataType); output.vValue = MarshalPropertyValue(input.ID, input.Value); output.wReserved = 0; output.hrErrorID = OpcCom.Interop.GetResultID(input.ResultID); // set the property data type. PropertyDescription description = PropertyDescription.Find(input.ID); if (description != null) { output.vtDataType = (short)OpcCom.Interop.GetType(description.Type); } // convert unified DA code to COM DA code. if (input.ResultID == ResultID.Da.E_WRITEONLY) { output.hrErrorID = ResultIDs.E_BADRIGHTS; } } return(output); }
/// <summary> /// static function that read item property collection for selected item /// </summary> /// <param name="ItemName">item name to be read</param> /// <param name="ds">data set with settings</param> /// <returns>collection of properties</returns> public static ItemPropertyCollection GetItemPropertiesCollection(string ItemName, ItemDecriberDataSet ds) { ItemPropertyCollection _ret = null; if (ds != null) { _ret = new ItemPropertyCollection(); foreach (ItemDecriberDataSet.ItemsRow _row in ds.Items.Rows) { if (_row.ItemName == ItemName) { foreach (ItemDecriberDataSet.ItemPropertyRow row_property in _row.GetItemPropertyRows()) { PropertyDescription prop_dsc = PropertyDescription.Find(new PropertyID(row_property.PropertyCode)); ItemProperty itemprop = new ItemProperty { ID = prop_dsc.ID, Value = row_property.Value }; _ret.Add(itemprop); } break; } } } return(_ret); }
public void QueryAvailableProperties(string szItemID, out int pdwCount, out IntPtr ppPropertyIDs, out IntPtr ppDescriptions, out IntPtr ppvtDataTypes) { OpcCom.Da.Wrapper.Server server; Monitor.Enter(server = this); try { if ((szItemID == null) || (szItemID.Length == 0)) { throw new ExternalException("QueryAvailableProperties", -2147024809); } ItemIdentifier[] itemIDs = new ItemIdentifier[] { new ItemIdentifier(szItemID) }; ItemPropertyCollection[] propertysArray = this.m_server.GetProperties(itemIDs, null, false); if ((propertysArray == null) || (propertysArray.Length != 1)) { throw new ExternalException("LookupItemIDs", -2147467259); } if (propertysArray[0].ResultID.Failed()) { throw new ResultIDException(propertysArray[0].ResultID); } int[] input = new int[propertysArray[0].Count]; string[] values = new string[propertysArray[0].Count]; short[] numArray2 = new short[propertysArray[0].Count]; for (int i = 0; i < propertysArray[0].Count; i++) { ItemProperty property = propertysArray[0][i]; if (property.ResultID.Succeeded()) { input[i] = property.ID.Code; PropertyDescription description = PropertyDescription.Find(property.ID); if (description != null) { values[i] = description.Name; numArray2[i] = (short)OpcCom.Interop.GetType(description.Type); } } } pdwCount = input.Length; ppPropertyIDs = OpcCom.Interop.GetInt32s(input); ppDescriptions = OpcCom.Interop.GetUnicodeStrings(values); ppvtDataTypes = OpcCom.Interop.GetInt16s(numArray2); } catch (Exception exception) { throw CreateException(exception); } finally { Monitor.Exit(server); } }
/// <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; } } }
internal static OPCITEMPROPERTY GetItemProperty(ItemProperty input) { OPCITEMPROPERTY opcitemproperty = new OPCITEMPROPERTY(); if (input != null) { opcitemproperty.dwPropertyID = input.ID.Code; opcitemproperty.szDescription = input.Description; opcitemproperty.vtDataType = (short)OpcCom.Interop.GetType(input.DataType); opcitemproperty.vValue = MarshalPropertyValue(input.ID, input.Value); opcitemproperty.wReserved = 0; opcitemproperty.hrErrorID = OpcCom.Interop.GetResultID(input.ResultID); PropertyDescription description = PropertyDescription.Find(input.ID); if (description != null) { opcitemproperty.vtDataType = (short)OpcCom.Interop.GetType(description.Type); } if (input.ResultID == ResultID.Da.E_WRITEONLY) { opcitemproperty.hrErrorID = -1073479674; } } return(opcitemproperty); }
/// <summary> /// Tag constructor /// </summary> /// <param name="myDSC">parameters from Tags table</param> /// <param name="myStation">pointer to interface that allow to change priority of the station</param> internal Tag(ComunicationNet.TagsRow myDSC, IStationState myStation) : base(myDSC.Name, null, qualityBits.badNotConnected, (ItemAccessRights)myDSC.AccessRights, GetDataTypeFromConfig(myDSC)) { switch ((StateTrigger)myDSC.StateTrigger) { case StateTrigger.StateHigh: stateHihgTriger = true; break; case StateTrigger.StateLow: stateLowTriger = true; break; default: break; } stateMask = (int)myDSC.StateMask; this.myStation = myStation; this.EuType = Opc.Da.euType.noEnum; ItemPropertyCollection itemPropertyCollection = new ItemPropertyCollection(); foreach (ComunicationNet.ItemPropertiesTableRow row_property in myDSC.GetItemPropertiesTableRows()) { try { PropertyDescription prop_dsc = PropertyDescription.Find( new PropertyID( new XmlQualifiedName(row_property.ID_Name_Name, row_property.ID_Name_Namespace) )); ItemProperty _itemProperty = new ItemProperty { ID = prop_dsc.ID, Value = row_property.Value }; if (prop_dsc.ID != Opc.Da.Property.DATATYPE) //this property is managed differently // as GetDataTypeFromConfig( myDSC ) // at the constructor { if (prop_dsc.ID == Opc.Da.Property.HI_LIMIT || prop_dsc.ID == Opc.Da.Property.LO_LIMIT || prop_dsc.ID == Opc.Da.Property.HIHI_LIMIT || prop_dsc.ID == Opc.Da.Property.LOLO_LIMIT || prop_dsc.ID == Opc.Da.Property.LOWEU || prop_dsc.ID == Opc.Da.Property.HIGHEU || prop_dsc.ID == Opc.Da.Property.SCANRATE ) { // this property contains double value if (double.TryParse(row_property.Value, out double prop_value)) _itemProperty.Value = prop_value; } if (prop_dsc.ID == Opc.Da.Property.EUTYPE) { _itemProperty.Value = Opc.Da.euType.noEnum; // this property contains vale from enum: Opc.Da.euType foreach (Opc.Da.euType NEWeuType in Enum.GetValues(typeof(Opc.Da.euType))) { if (NEWeuType.ToString() == row_property.Value) _itemProperty.Value = NEWeuType; } } if (prop_dsc.ID == Opc.Da.Property.EUINFO) { //I assume that this is table of strings spited by ; _itemProperty.Value = row_property.Value.Split(';'); } itemPropertyCollection.Add(_itemProperty); } } catch (Exception ex) { CommServerComponent.Tracer.TraceInformation(290, "DataBlock.Tag", "Problem with property for item : " + myDSC.Name + ": " + TraceEvent.GetMessageWithExceptionNameFromExceptionIncludingInnerException(ex)); } } try { this.AddProperties(itemPropertyCollection); } catch (Exception ex) { CommServerComponent.Tracer.TraceInformation(290, "DataBlock.Tag", "Problem with many properties for item : " + myDSC.Name + ": " + TraceEvent.GetMessageWithExceptionNameFromExceptionIncludingInnerException(ex)); } }
/// <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); }
/// <summary> /// Returns the specified properties for the specified item. /// </summary> public Opc.Da.ItemPropertyCollection GetAvailableProperties( PropertyID[] propertyIDs, bool returnValues) { // initialize property collection. ItemPropertyCollection properties = new ItemPropertyCollection(); properties.ItemName = m_itemID; properties.ItemPath = null; properties.ResultID = ResultID.S_OK; properties.DiagnosticInfo = null; // fetch information for each requested property. foreach (PropertyID propertyID in propertyIDs) { ItemProperty property = new ItemProperty(); property.ID = propertyID; // read the property value. if (returnValues) { ItemValueResult result = Read(propertyID); if (result.ResultID.Succeeded()) { property.Value = result.Value; } property.ResultID = result.ResultID; property.DiagnosticInfo = result.DiagnosticInfo; } // just validate the property id. else { property.ResultID = ValidatePropertyID(propertyID, accessRights.readWritable); } // set status if one or more errors occur. if (property.ResultID.Failed()) { properties.ResultID = ResultID.S_FALSE; } else { // set property description. PropertyDescription description = PropertyDescription.Find(propertyID); if (description != null) { property.Description = description.Name; property.DataType = description.Type; } // set property item id. if (propertyID.Code >= ENGINEERINGUINTS && propertyID.Code <= TIMEZONE) { property.ItemName = m_itemID + ":" + propertyID.Code.ToString(); property.ItemPath = null; } } // add to collection. properties.Add(property); } // return collection. return(properties); }
/// <summary> /// Writes the value of the specified item property. /// </summary> protected IdentifiedResult Write(PropertyID propertyID, ItemValue value, bool validate) { // initialize result and validate property. IdentifiedResult result = new IdentifiedResult { ItemName = ItemID, ItemPath = null }; if (validate) { result.ResultID = ValidatePropertyID(propertyID, accessRights.writable); } else { result.ResultID = ResultID.S_OK; } result.DiagnosticInfo = null; //MP return if modification is not allowed //MPNI zg³osiæ Rendy'iemu if (result.ResultID.Failed()) { //nieudalo dodac sie property: #if DEBUG //tutaj chyba wyswietla wlasnie te co dodal System.Console.WriteLine( "|problem with the property (Write fails) : " + ToString() + ":" + propertyID.ToString().Replace(Opc.Namespace.OPC_DATA_ACCESS, "") + " "); #endif return(result); } // handle value writes. if (propertyID == Property.VALUE) { if (!UpdateRemote(value.Value))//MZTD: sprawdzic czy symulator bedzie dzialac (bylo przekazywane cale Opc.Da.ItemValue a teraz idzie tylko value z Opc.Da.ItemValue value) { result.ResultID = ResultID.E_TIMEDOUT; result.DiagnosticInfo = "communication error while writing to the device"; return(result); } lock (this) { m_value = value.Value; //MPTD sprawdziæ po co on to kopiuje // copy value. //m_value = Opc.Convert.Clone(value.Value); // update quality if specified. if (value.QualitySpecified) { m_quality = value.Quality; } // update time-stamp 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); } if (!validate) { //mamy doczynienia z dodawaniem nie validowanych properties i trzeba przekonwertowac je do odpowiedniego typu switch (propertyID.Code) { // standard properties. case DATATYPE: value.Value = System.Type.GetType(System.Convert.ToString(value.Value)); break; case QUALITY: value.Value = System.Convert.ToInt16(value.Value); break; case TIMESTAMP: value.Value = System.Convert.ToDateTime(value.Value); break; case ACCESSRIGHTS: value.Value = System.Convert.ToInt16(value.Value); break; case SCANRATE: value.Value = System.Convert.ToDouble(value.Value); break; case EUTYPE: if (System.Convert.ToString(value.Value).ToLower().Equals(euType.analog.ToString().ToLower())) { value.Value = euType.analog; } else if (System.Convert.ToString(value.Value).ToLower().Equals(euType.noEnum.ToString().ToLower())) { value.Value = euType.noEnum; } else if (System.Convert.ToString(value.Value).ToLower().Equals(euType.enumerated.ToString().ToLower())) { value.Value = euType.enumerated; } else { value.Value = (int)0; } break; case EUINFO: string[] temp_euinfo = new string[1]; temp_euinfo[0] = System.Convert.ToString(value.Value); value.Value = temp_euinfo; break; case HIHI_LIMIT: case LOLO_LIMIT: case HI_LIMIT: case LO_LIMIT: case LOWEU: case HIGHEU: value.Value = System.Convert.ToDouble(value.Value); break; default: //do nothing break; } } // check data-type. if (!property.Type.IsInstanceOfType(value.Value)) { #if DEBUG //tutaj chyba wyswietla wlasnie te co dodal System.Console.WriteLine( "|problem with the property (Write fails) : " + ToString() + ":" + propertyID.ToString().Replace(Opc.Namespace.OPC_DATA_ACCESS, "") + " "); #endif 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); } //Write