public void TestFilter() { var pro1 = new IdentifiedProtein("P1"); pro1.Peptides.Add(new IdentifiedPeptide(new IdentifiedSpectrum() { Charge = 1 })); pro1.Peptides.Add(new IdentifiedPeptide(new IdentifiedSpectrum() { Charge = 2 })); var pro2 = new IdentifiedProtein("P2"); pro2.Peptides.Add(new IdentifiedPeptide(new IdentifiedSpectrum() { Charge = 3 })); var g1 = new IdentifiedProteinGroup(); g1.Add(pro1); var g2 = new IdentifiedProteinGroup(); g2.Add(pro2); IdentifiedResult ir = new IdentifiedResult(); ir.Add(g1); ir.Add(g2); Assert.AreEqual(2, ir.Count); Assert.AreEqual(3, ir.GetSpectra().Count); ir.Filter(m => { return m.Spectrum.Query.Charge > 1; }); Assert.AreEqual(2, ir.Count); Assert.AreEqual(2, ir.GetSpectra().Count); ir.GetSpectra().All(m => { return m.Charge > 1; }); ir.Filter(m => { return m.Spectrum.Query.Charge > 2; }); Assert.AreEqual(1, ir.Count); Assert.AreEqual(1, ir.GetSpectra().Count); ir.GetSpectra().All(m => { return m.Charge > 2; }); Assert.AreEqual("P2", ir[0][0].Name); }
//====================================================================== // Write /// <summary> /// Writes the value, quality and timestamp for a set of items. /// </summary> /// <param name="items">The set of item values to write.</param> /// <returns>The results of the write operation for each item.</returns> public IdentifiedResult[] Write(ItemValue[] items) { if (items == null) { throw new ArgumentNullException("items"); } if (items.Length == 0) { return(new Opc.IdentifiedResult[0]); } lock (this) { ArrayList results = new ArrayList(items.Length); foreach (ItemValue item in items) { IdentifiedResult result = m_cache.Write(item.ItemName, m_culture.Name, item); if (result == null) { result = new IdentifiedResult(item, ResultID.E_FAIL); } result.ClientHandle = item.ClientHandle; results.Add(result); } return((IdentifiedResult[])results.ToArray(typeof(IdentifiedResult))); } }
protected override IdentifiedResult[] BeginRead(ItemIdentifier[] itemIDs, Item[] items, int requestID, out int cancelID) { try { int[] array = new int[itemIDs.Length]; for (int i = 0; i < itemIDs.Length; i++) { array[i] = (int)itemIDs[i].ServerHandle; } IntPtr ppErrors = IntPtr.Zero; ((IOPCAsyncIO2)m_group).Read(itemIDs.Length, array, requestID, out cancelID, out ppErrors); int[] int32s = Interop.GetInt32s(ref ppErrors, itemIDs.Length, deallocate: true); IdentifiedResult[] array2 = new IdentifiedResult[itemIDs.Length]; for (int j = 0; j < itemIDs.Length; j++) { array2[j] = new IdentifiedResult(itemIDs[j]); array2[j].ResultID = Interop.GetResultID(int32s[j]); array2[j].DiagnosticInfo = null; if (int32s[j] == -1073479674) { array2[j].ResultID = new ResultID(ResultID.Da.E_WRITEONLY, -1073479674L); } } return(array2); } catch (Exception e) { throw Interop.CreateException("IOPCAsyncIO2.Read", e); } }
public virtual IdentifiedResult[] Write(ItemValue[] items) { if (items == null) { throw new ArgumentNullException("items"); } lock (this) { if (base.m_server == null) { throw new NotConnectedException(); } int length = items.Length; if (length == 0) { throw new ArgumentOutOfRangeException("items.Length", "0"); } string[] pszItemIDs = new string[length]; for (int i = 0; i < length; i++) { pszItemIDs[i] = items[i].ItemName; } OPCITEMVQT[] oPCITEMVQTs = OpcCom.Da.Interop.GetOPCITEMVQTs(items); IntPtr zero = IntPtr.Zero; try { ((IOPCItemIO)base.m_server).WriteVQT(length, pszItemIDs, oPCITEMVQTs, out zero); } catch (Exception exception) { throw OpcCom.Interop.CreateException("IOPCItemIO.Read", exception); } int[] numArray = OpcCom.Interop.GetInt32s(ref zero, length, true); IdentifiedResult[] resultArray = new IdentifiedResult[length]; for (int j = 0; j < length; j++) { resultArray[j] = new IdentifiedResult(items[j]); resultArray[j].ServerHandle = null; resultArray[j].ResultID = OpcCom.Interop.GetResultID(numArray[j]); resultArray[j].DiagnosticInfo = null; if (numArray[j] == -1073479674) { resultArray[j].ResultID = new ResultID(ResultID.Da.E_READONLY, -1073479674L); } if ((this.m_filters & 1) == 0) { resultArray[j].ItemName = null; } if ((this.m_filters & 2) == 0) { resultArray[j].ItemPath = null; } if ((this.m_filters & 4) == 0) { resultArray[j].ClientHandle = null; } } return(resultArray); } }
protected override IdentifiedResult[] BeginRead(ItemIdentifier[] itemIDs, Item[] items, int requestID, out int cancelID) { IdentifiedResult[] resultArray2; try { int[] phServer = new int[itemIDs.Length]; for (int i = 0; i < itemIDs.Length; i++) { phServer[i] = (int)itemIDs[i].ServerHandle; } IntPtr zero = IntPtr.Zero; ((IOPCAsyncIO2)base.m_group).Read(itemIDs.Length, phServer, requestID, out cancelID, out zero); int[] numArray2 = OpcCom.Interop.GetInt32s(ref zero, itemIDs.Length, true); IdentifiedResult[] resultArray = new IdentifiedResult[itemIDs.Length]; for (int j = 0; j < itemIDs.Length; j++) { resultArray[j] = new IdentifiedResult(itemIDs[j]); resultArray[j].ResultID = OpcCom.Interop.GetResultID(numArray2[j]); resultArray[j].DiagnosticInfo = null; if (numArray2[j] == -1073479674) { resultArray[j].ResultID = new ResultID(ResultID.Da.E_WRITEONLY, -1073479674L); } } resultArray2 = resultArray; } catch (Exception exception) { throw OpcCom.Interop.CreateException("IOPCAsyncIO2.Read", exception); } return(resultArray2); }
public void TestKeepDistinctPeptideOnly() { var spectrum1 = new IdentifiedSpectrum(); var pep1 = spectrum1.NewPeptide(); var spectrum2 = new IdentifiedSpectrum(); var pep2 = spectrum2.NewPeptide(); var spectrum3 = new IdentifiedSpectrum(); var pep3 = spectrum3.NewPeptide(); var spectrum4 = new IdentifiedSpectrum(); var pep4 = spectrum4.NewPeptide(); var protein1 = new IdentifiedProtein(); protein1.Peptides.Add(pep1); protein1.Peptides.Add(pep2); var protein2 = new IdentifiedProtein(); protein2.Peptides.Add(pep1); protein2.Peptides.Add(pep3); var protein3 = new IdentifiedProtein(); protein3.Peptides.Add(pep2); protein3.Peptides.Add(pep4); var g1 = new IdentifiedProteinGroup(); g1.Add(protein1); var g2 = new IdentifiedProteinGroup(); g2.Add(protein2); var g3 = new IdentifiedProteinGroup(); g3.Add(protein3); IIdentifiedResult ir = new IdentifiedResult(); ir.Add(g1); ir.Add(g2); ir.Add(g3); new DistinctResultDistiller().KeepDistinctPeptideOnly(ir); Assert.AreEqual(2, ir.Count); Assert.AreEqual(g2, ir[0]); Assert.AreEqual(g3, ir[1]); Assert.AreEqual(1, ir[0].GetPeptides().Count); Assert.AreEqual(spectrum3, ir[0].GetPeptides()[0]); Assert.AreEqual(1, ir[1].GetPeptides().Count); Assert.AreEqual(spectrum4, ir[1].GetPeptides()[0]); }
protected override IdentifiedResult[] Write(ItemIdentifier[] itemIDs, ItemValue[] items) { IdentifiedResult[] array = new IdentifiedResult[itemIDs.Length]; ArrayList arrayList = new ArrayList(itemIDs.Length); ArrayList arrayList2 = new ArrayList(itemIDs.Length); for (int i = 0; i < items.Length; i++) { array[i] = new IdentifiedResult(itemIDs[i]); if (items[i].QualitySpecified || items[i].TimestampSpecified) { array[i].ResultID = ResultID.Da.E_NO_WRITEQT; array[i].DiagnosticInfo = null; } else { arrayList.Add(array[i]); arrayList2.Add(items[i]); } } if (arrayList.Count == 0) { return(array); } int[] array2 = new int[arrayList.Count]; object[] array3 = new object[arrayList.Count]; for (int j = 0; j < array2.Length; j++) { array2[j] = (int)((IdentifiedResult)arrayList[j]).ServerHandle; array3[j] = Interop.GetVARIANT(((ItemValue)arrayList2[j]).Value); } IntPtr ppErrors = IntPtr.Zero; try { ((IOPCSyncIO)m_group).Write(arrayList.Count, array2, array3, out ppErrors); } catch (Exception e) { throw Interop.CreateException("IOPCSyncIO.Write", e); } int[] int32s = Interop.GetInt32s(ref ppErrors, arrayList.Count, deallocate: true); for (int k = 0; k < arrayList.Count; k++) { IdentifiedResult identifiedResult = (IdentifiedResult)arrayList[k]; identifiedResult.ResultID = Interop.GetResultID(int32s[k]); identifiedResult.DiagnosticInfo = null; if (int32s[k] == -1073479674) { array[k].ResultID = new ResultID(ResultID.Da.E_READONLY, -1073479674L); } } return(array); }
protected override IdentifiedResult[] BeginWrite(ItemIdentifier[] itemIDs, ItemValue[] items, int requestID, out int cancelID) { cancelID = 0; ArrayList arrayList = new ArrayList(); ArrayList arrayList2 = new ArrayList(); IdentifiedResult[] array = new IdentifiedResult[itemIDs.Length]; for (int i = 0; i < itemIDs.Length; i++) { array[i] = new IdentifiedResult(itemIDs[i]); array[i].ResultID = ResultID.S_OK; array[i].DiagnosticInfo = null; if (items[i].QualitySpecified || items[i].TimestampSpecified) { array[i].ResultID = ResultID.Da.E_NO_WRITEQT; array[i].DiagnosticInfo = null; } else { arrayList.Add(array[i]); arrayList2.Add(Interop.GetVARIANT(items[i].Value)); } } if (arrayList.Count == 0) { return(array); } try { int[] array2 = new int[arrayList.Count]; for (int j = 0; j < arrayList.Count; j++) { array2[j] = (int)((IdentifiedResult)arrayList[j]).ServerHandle; } IntPtr ppErrors = IntPtr.Zero; ((IOPCAsyncIO2)m_group).Write(arrayList.Count, array2, (object[])arrayList2.ToArray(typeof(object)), requestID, out cancelID, out ppErrors); int[] int32s = Interop.GetInt32s(ref ppErrors, arrayList.Count, deallocate: true); for (int k = 0; k < arrayList.Count; k++) { IdentifiedResult identifiedResult = (IdentifiedResult)arrayList[k]; identifiedResult.ResultID = Interop.GetResultID(int32s[k]); identifiedResult.DiagnosticInfo = null; if (int32s[k] == -1073479674) { array[k].ResultID = new ResultID(ResultID.Da.E_READONLY, -1073479674L); } } return(array); } catch (Exception e) { throw Interop.CreateException("IOPCAsyncIO2.Write", e); } }
//====================================================================== // Write /// <summary> /// Writes the value, quality and timestamp for a set of items. /// </summary> /// <param name="items">The set of item values to write.</param> /// <returns>The results of the write operation for each item.</returns> public IdentifiedResult[] Write(ItemValue[] items) { if (items == null) { throw new ArgumentNullException("items"); } if (items.Length == 0) { return(new Opc.IdentifiedResult[0]); } lock (this) { if (m_proxy == null) { throw new NotConnectedException(); } ItemValueList list = new ItemValueList(); list.AddRange(items); OpcXml.Da10.RequestOptions options = OpcXml.Da10.Request.GetRequestOptions(m_options.Locale, m_options.Filters); OpcXml.Da10.WriteRequestItemList requestList = OpcXml.Da10.Request.GetItemValueList(list); OpcXml.Da10.ReplyItemList replyList = null; OpcXml.Da10.OPCError[] errors = null; OpcXml.Da10.ReplyBase reply = m_proxy.Write( options, requestList, false, out replyList, out errors); CacheResponse(m_options.Locale, reply, errors); ItemValueResultList valueList = OpcXml.Da10.Request.GetResultList(replyList); if (valueList == null) { throw new InvalidResponseException(); } IdentifiedResult[] results = new IdentifiedResult[valueList.Count]; for (int ii = 0; ii < valueList.Count; ii++) { ItemValueResult valueResult = valueList[ii]; results[ii] = new IdentifiedResult(valueResult); results[ii].ResultID = valueResult.ResultID; results[ii].DiagnosticInfo = valueResult.DiagnosticInfo; } return(results); } }
/// <summary> /// Begins an asynchronous read of a set of items using DA2.0 interfaces. /// </summary> protected override IdentifiedResult[] BeginRead( ItemIdentifier[] itemIDs, Item[] items, int requestID, out int cancelID) { try { // marshal input parameters. int[] serverHandles = new int[itemIDs.Length]; for (int ii = 0; ii < itemIDs.Length; ii++) { serverHandles[ii] = (int)itemIDs[ii].ServerHandle; } // initialize output parameters. IntPtr pErrors = IntPtr.Zero; ((IOPCAsyncIO2)m_group).Read( itemIDs.Length, serverHandles, requestID, out cancelID, out pErrors); // unmarshal output parameters. int[] errors = OpcCom.Interop.GetInt32s(ref pErrors, itemIDs.Length, true); // create item results. IdentifiedResult[] results = new IdentifiedResult[itemIDs.Length]; for (int ii = 0; ii < itemIDs.Length; ii++) { results[ii] = new IdentifiedResult(itemIDs[ii]); results[ii].ResultID = OpcCom.Interop.GetResultID(errors[ii]); results[ii].DiagnosticInfo = null; // convert COM code to unified DA code. if (errors[ii] == ResultIDs.E_BADRIGHTS) { results[ii].ResultID = new ResultID(ResultID.Da.E_WRITEONLY, ResultIDs.E_BADRIGHTS); } } // return results. return(results); } catch (Exception e) { throw OpcCom.Interop.CreateException("IOPCAsyncIO2.Read", e); } }
protected override IdentifiedResult[] BeginWrite(ItemIdentifier[] itemIDs, ItemValue[] items, int requestID, out int cancelID) { cancelID = 0; ArrayList list = new ArrayList(); ArrayList list2 = new ArrayList(); IdentifiedResult[] resultArray = new IdentifiedResult[itemIDs.Length]; for (int i = 0; i < itemIDs.Length; i++) { resultArray[i] = new IdentifiedResult(itemIDs[i]); resultArray[i].ResultID = ResultID.S_OK; resultArray[i].DiagnosticInfo = null; if (items[i].QualitySpecified || items[i].TimestampSpecified) { resultArray[i].ResultID = ResultID.Da.E_NO_WRITEQT; resultArray[i].DiagnosticInfo = null; } else { list.Add(resultArray[i]); list2.Add(OpcCom.Interop.GetVARIANT(items[i].Value)); } } if (list.Count != 0) { try { int[] phServer = new int[list.Count]; for (int j = 0; j < list.Count; j++) { phServer[j] = (int)((IdentifiedResult)list[j]).ServerHandle; } IntPtr zero = IntPtr.Zero; ((IOPCAsyncIO2)base.m_group).Write(list.Count, phServer, (object[])list2.ToArray(typeof(object)), requestID, out cancelID, out zero); int[] numArray2 = OpcCom.Interop.GetInt32s(ref zero, list.Count, true); for (int k = 0; k < list.Count; k++) { IdentifiedResult result = (IdentifiedResult)list[k]; result.ResultID = OpcCom.Interop.GetResultID(numArray2[k]); result.DiagnosticInfo = null; if (numArray2[k] == -1073479674) { resultArray[k].ResultID = new ResultID(ResultID.Da.E_READONLY, -1073479674L); } } } catch (Exception exception) { throw OpcCom.Interop.CreateException("IOPCAsyncIO2.Write", exception); } } return(resultArray); }
/// <summary> /// Writes the value of the specified item. /// </summary> public Opc.IdentifiedResult Write(string locale, Opc.Da.ItemValue value) { // write value. IdentifiedResult result = m_cache.Write(m_itemID, locale, value); if (result == null) { return(new IdentifiedResult(m_itemID, ResultID.E_FAIL)); } return(result); }
protected override IdentifiedResult[] Write(ItemIdentifier[] itemIDs, ItemValue[] items) { IdentifiedResult[] resultArray = new IdentifiedResult[itemIDs.Length]; ArrayList list = new ArrayList(itemIDs.Length); ArrayList list2 = new ArrayList(itemIDs.Length); for (int i = 0; i < items.Length; i++) { resultArray[i] = new IdentifiedResult(itemIDs[i]); if (items[i].QualitySpecified || items[i].TimestampSpecified) { resultArray[i].ResultID = ResultID.Da.E_NO_WRITEQT; resultArray[i].DiagnosticInfo = null; } else { list.Add(resultArray[i]); list2.Add(items[i]); } } if (list.Count != 0) { int[] phServer = new int[list.Count]; object[] pItemValues = new object[list.Count]; for (int j = 0; j < phServer.Length; j++) { phServer[j] = (int)((IdentifiedResult)list[j]).ServerHandle; pItemValues[j] = OpcCom.Interop.GetVARIANT(((ItemValue)list2[j]).Value); } IntPtr zero = IntPtr.Zero; try { ((IOPCSyncIO)base.m_group).Write(list.Count, phServer, pItemValues, out zero); } catch (Exception exception) { throw OpcCom.Interop.CreateException("IOPCSyncIO.Write", exception); } int[] numArray2 = OpcCom.Interop.GetInt32s(ref zero, list.Count, true); for (int k = 0; k < list.Count; k++) { IdentifiedResult result = (IdentifiedResult)list[k]; result.ResultID = OpcCom.Interop.GetResultID(numArray2[k]); result.DiagnosticInfo = null; if (numArray2[k] == -1073479674) { resultArray[k].ResultID = new ResultID(ResultID.Da.E_READONLY, -1073479674L); } } } return(resultArray); }
/// <remarks/> public IdentifiedResult[] Write(ItemValue[] items) { if (items == null) { throw new ArgumentNullException("items"); } lock (this) { // handle trivial case. if (items.Length == 0) { return(new IdentifiedResult[0]); } // create item results. IdentifiedResult[] results = new IdentifiedResult[items.Length]; for (int ii = 0; ii < items.Length; ii++) { // initialize result with item. results[ii] = new IdentifiedResult(items[ii]); // check for invalid handle. if (items[ii].ServerHandle == null) { results[ii].ResultID = ResultID.Da.E_INVALIDHANDLE; continue; } // lookup subscription item. SubscriptionItem item = (SubscriptionItem)m_items[items[ii].ServerHandle]; if (item == null) { results[ii].ResultID = ResultID.Da.E_INVALIDHANDLE; continue; } // write the item value. results[ii] = item.Write(m_state.Locale, items[ii]); results[ii].ServerHandle = items[ii].ServerHandle; } // apply result filters. ApplyFilters(m_filters, results); // return results. return(results); } }
/// <remarks/> public IdentifiedResult[] RemoveItems(ItemIdentifier[] items) { if (items == null) { throw new ArgumentNullException("items"); } lock (this) { // handle trivial case. if (items.Length == 0) { return(new IdentifiedResult[0]); } // create item results. IdentifiedResult[] results = new IdentifiedResult[items.Length]; for (int ii = 0; ii < items.Length; ii++) { // initialize result with item. results[ii] = new IdentifiedResult(items[ii]); // check for invalid handle. if (items[ii].ServerHandle == null) { results[ii].ResultID = ResultID.Da.E_INVALIDHANDLE; continue; } // lookup subscription item. SubscriptionItem item = (SubscriptionItem)m_items[items[ii].ServerHandle]; if (item == null) { results[ii].ResultID = ResultID.Da.E_INVALIDHANDLE; continue; } // remove item. m_items.Remove(items[ii].ServerHandle); results[ii].ResultID = ResultID.S_OK; } // return results. return(results); } }
/// <summary> /// 输出每次条件下,每个fraction的protein group文件 /// </summary> protected override void ExportIndividualFractionFile() { DirectoryInfo individualDir = new DirectoryInfo(resultDir.FullName + "\\individual"); FileInfo sourceFile = new FileInfo(option.SourceFileName); SequestResultTextFormat writeFormat = GetWriteFormat(); for (int iMinCount = option.FilterFrom; iMinCount <= option.FilterTo; iMinCount += option.FilterStep) { List <CalculationItem> currentItems = GetFilteredItems(iMinCount); if (!individualDir.Exists) { individualDir.Create(); } foreach (string keptClassifiedName in option.GetClassifiedNames()) { string result_file = MyConvert.Format(@"{0}\{1}.{2}.{3}{4}", individualDir.FullName, FileUtils.ChangeExtension(sourceFile.Name, ""), GetOptionCondition(iMinCount), keptClassifiedName, sourceFile.Extension); List <IIdentifiedProteinGroup> groups = new List <IIdentifiedProteinGroup>(); foreach (var item in currentItems) { if (item.GetClassifiedCount(keptClassifiedName) >= iMinCount) { IIdentifiedProteinGroup group = (IIdentifiedProteinGroup)item.Key; IIdentifiedProteinGroup clonedGroup = GetGroupContainClassifiedPeptideHitOnly(keptClassifiedName, group); groups.Add(clonedGroup); } } IdentifiedResult curResult = new IdentifiedResult(); curResult.AddRange(groups); curResult.Sort(); writeFormat.WriteToFile(result_file, curResult); } } }
public void TestFilter2() { var spectrum = new IdentifiedSpectrum(); spectrum.Query.FileScan.LongFileName = "ABDCDD.12.123.2.dat"; var pro1 = new IdentifiedProtein("P1"); pro1.Peptides.Add(new IdentifiedPeptide(spectrum) { Sequence = "AAAAAAA" }); var pro2 = new IdentifiedProtein("P2"); pro2.Peptides.Add(new IdentifiedPeptide(spectrum) { Sequence = "BBBBBBB" }); var g1 = new IdentifiedProteinGroup(); g1.Add(pro1); g1.Add(pro2); IdentifiedResult ir = new IdentifiedResult(); ir.Add(g1); Assert.AreEqual(1, ir.Count); Assert.AreEqual(2, ir[0].Count); Assert.AreEqual(1, ir.GetSpectra().Count); ir.Filter(m => { return m.Sequence.Contains('A'); }); Assert.AreEqual(1, ir.Count); Assert.AreEqual(1, ir[0].Count); Assert.AreEqual(1, ir.GetSpectra().Count); Assert.AreSame(pro1, ir[0][0]); ir.Filter(m => { return m.Sequence.Contains('C'); }); Assert.AreEqual(0, ir.Count); }
public override IdentifiedResult[] Write(ItemValue[] items) { if (items == null) { throw new ArgumentNullException("items"); } if (items.Length == 0) { return(new IdentifiedResult[0]); } lock (this) { if (m_server == null) { throw new NotConnectedException(); } Item[] array = new Item[items.Length]; for (int i = 0; i < items.Length; i++) { array[i] = new Item(items[i]); } IdentifiedResult[] array2 = AddItems(array); try { ArrayList arrayList = new ArrayList(items.Length); ArrayList arrayList2 = new ArrayList(items.Length); for (int j = 0; j < items.Length; j++) { if (!array2[j].ResultID.Failed()) { if (items[j].QualitySpecified || items[j].TimestampSpecified) { array2[j].ResultID = ResultID.Da.E_NO_WRITEQT; array2[j].DiagnosticInfo = null; } else { arrayList.Add(array2[j]); arrayList2.Add(items[j]); } } } if (arrayList.Count > 0) { int[] array3 = new int[arrayList.Count]; object[] array4 = new object[arrayList.Count]; for (int k = 0; k < array3.Length; k++) { array3[k] = (int)((IdentifiedResult)arrayList[k]).ServerHandle; array4[k] = Interop.GetVARIANT(((ItemValue)arrayList2[k]).Value); } IntPtr ppErrors = IntPtr.Zero; try { ((IOPCSyncIO)m_group).Write(arrayList.Count, array3, array4, out ppErrors); } catch (Exception e) { throw Interop.CreateException("IOPCSyncIO.Write", e); } int[] int32s = Interop.GetInt32s(ref ppErrors, arrayList.Count, deallocate: true); for (int l = 0; l < arrayList.Count; l++) { IdentifiedResult identifiedResult = (IdentifiedResult)arrayList[l]; identifiedResult.ResultID = Interop.GetResultID(int32s[l]); identifiedResult.DiagnosticInfo = null; if (int32s[l] == -1073479674) { array2[l].ResultID = new ResultID(ResultID.Da.E_READONLY, -1073479674L); } } } } finally { RemoveItems(array2); } return(array2); } }
public override IdentifiedResult[] Write(ItemValue[] items) { if (items == null) { throw new ArgumentNullException("items"); } if (items.Length == 0) { return(new IdentifiedResult[0]); } lock (this) { if (base.m_server == null) { throw new NotConnectedException(); } Item[] itemArray = new Item[items.Length]; for (int i = 0; i < items.Length; i++) { itemArray[i] = new Item(items[i]); } IdentifiedResult[] resultArray = this.AddItems(itemArray); try { ArrayList list = new ArrayList(items.Length); ArrayList list2 = new ArrayList(items.Length); for (int j = 0; j < items.Length; j++) { if (!resultArray[j].ResultID.Failed()) { if (items[j].QualitySpecified || items[j].TimestampSpecified) { resultArray[j].ResultID = ResultID.Da.E_NO_WRITEQT; resultArray[j].DiagnosticInfo = null; } else { list.Add(resultArray[j]); list2.Add(items[j]); } } } if (list.Count > 0) { int[] phServer = new int[list.Count]; object[] pItemValues = new object[list.Count]; for (int k = 0; k < phServer.Length; k++) { phServer[k] = (int)((IdentifiedResult)list[k]).ServerHandle; pItemValues[k] = OpcCom.Interop.GetVARIANT(((ItemValue)list2[k]).Value); } IntPtr zero = IntPtr.Zero; try { ((IOPCSyncIO)this.m_group).Write(list.Count, phServer, pItemValues, out zero); } catch (Exception exception) { throw OpcCom.Interop.CreateException("IOPCSyncIO.Write", exception); } int[] numArray2 = OpcCom.Interop.GetInt32s(ref zero, list.Count, true); for (int m = 0; m < list.Count; m++) { IdentifiedResult result = (IdentifiedResult)list[m]; result.ResultID = OpcCom.Interop.GetResultID(numArray2[m]); result.DiagnosticInfo = null; if (numArray2[m] == -1073479674) { resultArray[m].ResultID = new ResultID(ResultID.Da.E_READONLY, -1073479674L); } } } } finally { this.RemoveItems(resultArray); } return(resultArray); } }
//====================================================================== // Write /// <summary> /// Writes the value, quality and timestamp for a set of items. /// </summary> /// <param name="items">The set of item values to write.</param> /// <returns>The results of the write operation for each item.</returns> public IdentifiedResult[] Write(ItemValue[] items) { if (items == null) throw new ArgumentNullException("items"); if (items.Length == 0) { return new Opc.IdentifiedResult[0]; } lock (this) { ArrayList results = new ArrayList(items.Length); foreach (ItemValue item in items) { IdentifiedResult result = m_cache.Write(item.ItemName, m_culture.Name, item); if (result == null) { result = new IdentifiedResult(item, ResultID.E_FAIL); } result.ClientHandle = item.ClientHandle; results.Add(result); } return (IdentifiedResult[])results.ToArray(typeof(IdentifiedResult)); } }
private IdentifiedResult[] BeginWrite( ItemIdentifier[] itemIDs, ItemValue[] items, int requestID, out int cancelID) { cancelID = 0; ArrayList validItems = new ArrayList(); ArrayList validValues = new ArrayList(); // construct initial result list. IdentifiedResult[] results = new IdentifiedResult[itemIDs.Length]; for (int ii = 0; ii < itemIDs.Length; ii++) { results[ii] = new IdentifiedResult(itemIDs[ii]); results[ii].ResultID = ResultID.S_OK; results[ii].DiagnosticInfo = null; if (items[ii].QualitySpecified || items[ii].TimestampSpecified) { results[ii].ResultID = ResultID.Da.E_NO_WRITEQT; results[ii].DiagnosticInfo = null; continue; } validItems.Add(results[ii]); validValues.Add(HD.OPC.Client.Core.Com.Interop.GetVARIANT(items[ii].Value)); } // check if any valid items exist. if (validItems.Count == 0) { return(results); } try { // initialize input parameters. int[] serverHandles = new int[validItems.Count]; for (int ii = 0; ii < validItems.Count; ii++) { serverHandles[ii] = (int)((IdentifiedResult)validItems[ii]).ServerHandle; } // write to sever. IntPtr pErrors = IntPtr.Zero; ((IOPCAsyncIO2)m_group).Write( validItems.Count, serverHandles, (object[])validValues.ToArray(typeof(object)), requestID, out cancelID, out pErrors); // unmarshal results. int[] errors = HD.OPC.Client.Core.Com.Interop.GetInt32s(ref pErrors, validItems.Count, true); // create result list. for (int ii = 0; ii < validItems.Count; ii++) { IdentifiedResult result = (IdentifiedResult)validItems[ii]; result.ResultID = HD.OPC.Client.Core.Com.Interop.GetResultID(errors[ii]); result.DiagnosticInfo = null; // convert COM code to unified DA code. if (errors[ii] == ResultIDs.E_BADRIGHTS) { results[ii].ResultID = new ResultID(ResultID.Da.E_READONLY, ResultIDs.E_BADRIGHTS); } } } catch (Exception e) { throw HD.OPC.Client.Core.Com.Interop.CreateException("IOPCAsyncIO2.Write", e); } // return results. return(results); }
public virtual IdentifiedResult[] Write(ItemValue[] items) { if (items == null) { throw new ArgumentNullException("items"); } lock (this) { if (m_server == null) { throw new NotConnectedException(); } int num = items.Length; if (num == 0) { throw new ArgumentOutOfRangeException("items.Length", "0"); } string[] array = new string[num]; for (int i = 0; i < num; i++) { array[i] = items[i].ItemName; } OPCITEMVQT[] oPCITEMVQTs = Interop.GetOPCITEMVQTs(items); IntPtr ppErrors = IntPtr.Zero; try { ((IOPCItemIO)m_server).WriteVQT(num, array, oPCITEMVQTs, out ppErrors); } catch (Exception e) { throw OpcCom.Interop.CreateException("IOPCItemIO.Read", e); } int[] int32s = OpcCom.Interop.GetInt32s(ref ppErrors, num, deallocate: true); IdentifiedResult[] array2 = new IdentifiedResult[num]; for (int j = 0; j < num; j++) { array2[j] = new IdentifiedResult(items[j]); array2[j].ServerHandle = null; array2[j].ResultID = OpcCom.Interop.GetResultID(int32s[j]); array2[j].DiagnosticInfo = null; if (int32s[j] == -1073479674) { array2[j].ResultID = new ResultID(ResultID.Da.E_READONLY, -1073479674L); } if ((m_filters & 1) == 0) { array2[j].ItemName = null; } if ((m_filters & 2) == 0) { array2[j].ItemPath = null; } if ((m_filters & 4) == 0) { array2[j].ClientHandle = null; } } return(array2); } }
/// <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; }
public IdentifiedResult[] RemoveItems(object[] itemClientHandles) { if (itemClientHandles == null) { throw new ArgumentNullException("items"); } // check if nothing to do. if (itemClientHandles.Length == 0) { return(new IdentifiedResult[0]); } lock (this) { if (this.m_group == null) { // MessageBox.Show("No connection!"); return(new IdentifiedResult[0]); } // get item ids. ItemIdentifier[] itemIDs = null; lock (m_items) { itemIDs = m_items.GetItemIDs(itemClientHandles); } // fetch server handles. int count = itemClientHandles.Length; int[] serverHandles = new int[count]; for (int ii = 0; ii < count; ii++) { serverHandles[ii] = (int)itemIDs[ii].ServerHandle; } // initialize output parameters. IntPtr pErrors = IntPtr.Zero; try { ((IOPCItemMgt)this.m_group).RemoveItems(count, serverHandles, out pErrors); } catch (Exception e) { throw HD.OPC.Client.Core.Com.Interop.CreateException("IOPCItemMgt.RemoveItems", e); } // unmarshal output parameters. int[] errors = HD.OPC.Client.Core.Com.Interop.GetInt32s(ref pErrors, count, true); // process results. IdentifiedResult[] results = new IdentifiedResult[count]; lock (m_items) { for (int ii = 0; ii < count; ii++) { results[ii] = new IdentifiedResult(itemIDs[ii]); results[ii].ResultID = HD.OPC.Client.Core.Com.Interop.GetResultID(errors[ii]); results[ii].DiagnosticInfo = null; // flag item for removal from local list. if (results[ii].ResultID.Succeeded()) { m_items[results[ii].ClientHandle.GetHashCode()] = null; } } } return(results); } }
private IdentifiedResult[] AddItems(Item[] items) { int num = items.Length; OPCITEMDEF[] oPCITEMDEFs = OpcCom.Da.Interop.GetOPCITEMDEFs(items); for (int i = 0; i < oPCITEMDEFs.Length; i++) { oPCITEMDEFs[i].bActive = 0; } IntPtr ppAddResults = IntPtr.Zero; IntPtr ppErrors = IntPtr.Zero; int pdwLcid = 0; ((IOPCCommon)m_server).GetLocaleID(out pdwLcid); GCHandle gCHandle = GCHandle.Alloc(pdwLcid, GCHandleType.Pinned); try { int pRevisedUpdateRate = 0; ((IOPCGroupStateMgt)m_group).SetState(IntPtr.Zero, out pRevisedUpdateRate, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, gCHandle.AddrOfPinnedObject(), IntPtr.Zero); } catch (Exception e) { throw Interop.CreateException("IOPCGroupStateMgt.SetState", e); } finally { if (gCHandle.IsAllocated) { gCHandle.Free(); } } try { ((IOPCItemMgt)m_group).AddItems(num, oPCITEMDEFs, out ppAddResults, out ppErrors); } catch (Exception e2) { throw Interop.CreateException("IOPCItemMgt.AddItems", e2); } finally { if (gCHandle.IsAllocated) { gCHandle.Free(); } } int[] itemResults = OpcCom.Da.Interop.GetItemResults(ref ppAddResults, num, deallocate: true); int[] int32s = Interop.GetInt32s(ref ppErrors, num, deallocate: true); IdentifiedResult[] array = new IdentifiedResult[num]; for (int j = 0; j < num; j++) { array[j] = new IdentifiedResult(items[j]); array[j].ServerHandle = null; array[j].ResultID = Interop.GetResultID(int32s[j]); array[j].DiagnosticInfo = null; if (array[j].ResultID.Succeeded()) { array[j].ServerHandle = itemResults[j]; } } return(array); }
/// <summary> /// Begins an asynchronous write operation for a set of items. /// </summary> /// <param name="items">The set of item values to write (must include the server handle).</param> /// <param name="requestHandle">An identifier for the request assigned by the caller.</param> /// <param name="callback">A delegate used to receive notifications when the request completes.</param> /// <param name="request">An object that contains the state of the request (used to cancel the request).</param> /// <returns>A set of results containing any errors encountered when the server validated the items.</returns> public IdentifiedResult[] Write( ItemValue[] items, object requestHandle, WriteCompleteEventHandler callback, out IRequest request) { if (items == null) { throw new ArgumentNullException("items"); } lock (this) { request = null; // handle trivial case. if (items.Length == 0) { return(new IdentifiedResult[0]); } // validate the items. ArrayList validItems = new ArrayList(); IdentifiedResult[] results = new IdentifiedResult[items.Length]; for (int ii = 0; ii < items.Length; ii++) { // initialize result with item. results[ii] = new IdentifiedResult(items[ii]); // check for invalid handle. if (items[ii].ServerHandle == null) { results[ii].ResultID = ResultID.Da.E_INVALIDHANDLE; continue; } // lookup subscription item. SubscriptionItem item = (SubscriptionItem)m_items[items[ii].ServerHandle]; if (item == null) { results[ii].ResultID = ResultID.Da.E_INVALIDHANDLE; continue; } // at least one valid item exists. validItems.Add(items[ii]); } if (validItems.Count > 0) { request = new Opc.Da.Request(this, requestHandle); m_requests.Add(request, callback); m_writeQueue.Enqueue(new object[] { request, validItems.ToArray(typeof(ItemValue)) }); ThreadPool.QueueUserWorkItem(new WaitCallback(OnWrite)); } // apply result filters. ApplyFilters(m_filters, results); // return results. return(results); } }
/// <summary> /// Removes items from the subscription. /// </summary> /// <param name="items">The identifiers (i.e. server handles) for the items being removed.</param> /// <returns>The results of the remove item operation for each item.</returns> public IdentifiedResult[] RemoveItems(ItemIdentifier[] items) { if (items == null) { throw new ArgumentNullException("items"); } // check if nothing to do. if (items.Length == 0) { return(new IdentifiedResult[0]); } lock (this) { if (m_proxy == null) { throw new NotConnectedException(); } // initialize results list. IdentifiedResult[] results = new IdentifiedResult[items.Length]; // build the remaining list of items. ArrayList itemList = new ArrayList(items.Length); foreach (Item item in m_items) { // search the list of items to remove for a matching server handle. bool found = false; for (int ii = 0; ii < items.Length; ii++) { if (item.ServerHandle.Equals(items[ii].ServerHandle)) { results[ii] = new IdentifiedResult(items[ii]); found = true; break; } } // add copy to the item list. if (!found) { itemList.Add(item); } } // create a new subscription. ItemValueResultList resultList = Subscribe(itemList); // update remaining items. for (int ii = 0; ii < resultList.Count; ii++) { // the current item value result object. SubscribeItemValueResult result = (SubscribeItemValueResult)resultList[ii]; // the matching item object. Item item = (Item)itemList[ii]; // save revised sampling rates. item.SamplingRate = result.SamplingRate; item.SamplingRateSpecified = result.SamplingRateSpecified; } // look for uninitialized results - must have an invalid or duplicate server handles. for (int ii = 0; ii < results.Length; ii++) { if (results[ii] == null) { results[ii] = new IdentifiedResult(items[ii]); results[ii].ResultID = ResultID.Da.E_INVALIDHANDLE; results[ii].DiagnosticInfo = null; } } // save modified list of items. m_items = itemList; // send data change notifications. OnDataChange(resultList); // return results. return(results); } }
//====================================================================== // Write /// <summary> /// Writes the value, quality and timestamp for a set of items. /// </summary> /// <param name="items">The set of item values to write.</param> /// <returns>The results of the write operation for each item.</returns> public virtual IdentifiedResult[] Write(ItemValue[] items) { if (items == null) { throw new ArgumentNullException("items"); } lock (this) { if (m_server == null) { throw new NotConnectedException(); } int count = items.Length; if (count == 0) { throw new ArgumentOutOfRangeException("items.Length", "0"); } // initialize arguments. string[] itemIDs = new string[count]; for (int ii = 0; ii < count; ii++) { itemIDs[ii] = items[ii].ItemName; } OpcRcw.Da.OPCITEMVQT[] values = OpcCom.Da.Interop.GetOPCITEMVQTs(items); IntPtr pErrors = IntPtr.Zero; // invoke COM method. try { ((IOPCItemIO)m_server).WriteVQT( count, itemIDs, values, out pErrors); } catch (Exception e) { throw OpcCom.Interop.CreateException("IOPCItemIO.Read", e); } // unmarshal results. int[] errors = OpcCom.Interop.GetInt32s(ref pErrors, count, true); // construct result array. IdentifiedResult[] results = new IdentifiedResult[count]; for (int ii = 0; ii < count; ii++) { results[ii] = new IdentifiedResult(items[ii]); results[ii].ServerHandle = null; results[ii].ResultID = OpcCom.Interop.GetResultID(errors[ii]); results[ii].DiagnosticInfo = null; // convert COM code to unified DA code. if (errors[ii] == ResultIDs.E_BADRIGHTS) { results[ii].ResultID = new ResultID(ResultID.Da.E_READONLY, ResultIDs.E_BADRIGHTS); } // apply request options. if ((m_filters & (int)ResultFilter.ItemName) == 0) { results[ii].ItemName = null; } if ((m_filters & (int)ResultFilter.ItemPath) == 0) { results[ii].ItemPath = null; } if ((m_filters & (int)ResultFilter.ClientHandle) == 0) { results[ii].ClientHandle = null; } } // return results. return(results); } }
private IdentifiedResult[] AddItems(Item[] items) { int length = items.Length; OPCITEMDEF[] oPCITEMDEFs = OpcCom.Da.Interop.GetOPCITEMDEFs(items); for (int i = 0; i < oPCITEMDEFs.Length; i++) { oPCITEMDEFs[i].bActive = 0; oPCITEMDEFs[i].vtRequestedDataType = 0; } IntPtr zero = IntPtr.Zero; IntPtr ppErrors = IntPtr.Zero; int pdwLcid = 0; ((IOPCCommon)base.m_server).GetLocaleID(out pdwLcid); GCHandle handle = GCHandle.Alloc(pdwLcid, GCHandleType.Pinned); try { int pRevisedUpdateRate = 0; ((IOPCGroupStateMgt)this.m_group).SetState(IntPtr.Zero, out pRevisedUpdateRate, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, handle.AddrOfPinnedObject(), IntPtr.Zero); } catch (Exception exception) { throw OpcCom.Interop.CreateException("IOPCGroupStateMgt.SetState", exception); } finally { if (handle.IsAllocated) { handle.Free(); } } try { ((IOPCItemMgt)this.m_group).AddItems(length, oPCITEMDEFs, out zero, out ppErrors); } catch (Exception exception2) { throw OpcCom.Interop.CreateException("IOPCItemMgt.AddItems", exception2); } finally { if (handle.IsAllocated) { handle.Free(); } } int[] numArray = OpcCom.Da.Interop.GetItemResults(ref zero, length, true); int[] numArray2 = OpcCom.Interop.GetInt32s(ref ppErrors, length, true); IdentifiedResult[] resultArray = new IdentifiedResult[length]; for (int j = 0; j < length; j++) { resultArray[j] = new IdentifiedResult(items[j]); resultArray[j].ServerHandle = null; resultArray[j].ResultID = OpcCom.Interop.GetResultID(numArray2[j]); resultArray[j].DiagnosticInfo = null; if (resultArray[j].ResultID.Succeeded()) { resultArray[j].ServerHandle = numArray[j]; } } return(resultArray); }
/// <summary> /// Writes a set of items using DA2.0 interfaces. /// </summary> protected override IdentifiedResult[] Write(ItemIdentifier[] itemIDs, ItemValue[] items) { // create result list. IdentifiedResult[] results = new IdentifiedResult[itemIDs.Length]; // construct list of valid items to write. ArrayList writeItems = new ArrayList(itemIDs.Length); ArrayList writeValues = new ArrayList(itemIDs.Length); for (int ii = 0; ii < items.Length; ii++) { results[ii] = new IdentifiedResult(itemIDs[ii]); if (items[ii].QualitySpecified || items[ii].TimestampSpecified) { results[ii].ResultID = ResultID.Da.E_NO_WRITEQT; results[ii].DiagnosticInfo = null; continue; } writeItems.Add(results[ii]); writeValues.Add(items[ii]); } // check if there is nothing to do. if (writeItems.Count == 0) { return(results); } // initialize input parameters. int[] serverHandles = new int[writeItems.Count]; object[] values = new object[writeItems.Count]; for (int ii = 0; ii < serverHandles.Length; ii++) { serverHandles[ii] = (int)((IdentifiedResult)writeItems[ii]).ServerHandle; values[ii] = OpcCom.Interop.GetVARIANT(((ItemValue)writeValues[ii]).Value); } IntPtr pErrors = IntPtr.Zero; // write item values. try { ((IOPCSyncIO)m_group).Write( writeItems.Count, serverHandles, values, out pErrors); } catch (Exception e) { throw OpcCom.Interop.CreateException("IOPCSyncIO.Write", e); } // unmarshal results. int[] errors = OpcCom.Interop.GetInt32s(ref pErrors, writeItems.Count, true); for (int ii = 0; ii < writeItems.Count; ii++) { IdentifiedResult result = (IdentifiedResult)writeItems[ii]; result.ResultID = OpcCom.Interop.GetResultID(errors[ii]); result.DiagnosticInfo = null; // convert COM code to unified DA code. if (errors[ii] == ResultIDs.E_BADRIGHTS) { results[ii].ResultID = new ResultID(ResultID.Da.E_READONLY, ResultIDs.E_BADRIGHTS); } } // return results. return(results); }
/// <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); }
// handles asynchronous write complete events. public void OnWriteComplete( int dwTransid, int hGroup, int hrMastererror, int dwCount, int[] phClientItems, int[] pErrors) { try { OpcRequest request = null; IdentifiedResult[] results = null; lock (this) { // do nothing if no outstanding requests. request = (OpcRequest)m_requests[dwTransid]; if (request == null) { return; } // remove the request. m_requests.Remove(dwTransid); // contruct the item results. results = new IdentifiedResult[dwCount]; for (int ii = 0; ii < results.Length; ii++) { // lookup the external client handle. ItemIdentifier itemID = (ItemIdentifier)m_group.Items[phClientItems[ii]]; results[ii] = new IdentifiedResult(itemID); results[ii].ClientHandle = phClientItems[ii]; results[ii].ResultID = HD.OPC.Client.Core.Com.Interop.GetResultID(pErrors[ii]); results[ii].DiagnosticInfo = null; // convert COM code to unified DA code. if (pErrors[ii] == ResultIDs.E_BADRIGHTS) { results[ii].ResultID = new ResultID(ResultID.Da.E_READONLY, ResultIDs.E_BADRIGHTS); } } // apply request options. lock (m_group.Items) { m_group.Items.ApplyFilters(m_filters | (int)ResultFilter.ClientHandle, results); } } // end the request. lock (request) { request.EndRequest(results); } } catch (Exception e) { string stack = e.StackTrace; } }
/// <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