// Token: 0x06000006 RID: 6 RVA: 0x00002170 File Offset: 0x00000370 public bool Read(string[] sItemIDArray, out object[] oValueArray, out short[] wQualityArray, out OpcRcw.Da.FILETIME[] fTimeArray, out int[] nErrorArray) { int num = sItemIDArray.Count <string>(); int[] array = new int[num]; for (int i = 0; i < num; i++) { array[i] = 0; } int[] array2 = new int[num]; oValueArray = new object[num]; wQualityArray = new short[num]; fTimeArray = new OpcRcw.Da.FILETIME[num]; nErrorArray = new int[num]; bool result; try { IOPCItemIO iopcitemIO = (IOPCItemIO)this.m_OPCServer; IntPtr intPtr; IntPtr intPtr2; IntPtr intPtr3; IntPtr intPtr4; iopcitemIO.Read(num, sItemIDArray, array, out intPtr, out intPtr2, out intPtr3, out intPtr4); IntPtr intPtr5 = intPtr; IntPtr ptr = intPtr3; Marshal.Copy(intPtr4, nErrorArray, 0, num); Marshal.Copy(intPtr2, wQualityArray, 0, num); for (int j = 0; j < num; j++) { if (array2[j] == 0) { oValueArray[j] = Marshal.GetObjectForNativeVariant(intPtr5); } else { oValueArray[j] = "Error Value"; } fTimeArray[j] = (OpcRcw.Da.FILETIME)Marshal.PtrToStructure(ptr, typeof(OpcRcw.Da.FILETIME)); DxpSimpleClass.VariantClear(intPtr5); Marshal.DestroyStructure(ptr, typeof(OpcRcw.Da.FILETIME)); intPtr5 = (IntPtr)(intPtr5.ToInt32() + 16); ptr = (IntPtr)(ptr.ToInt32() + Marshal.SizeOf(typeof(OpcRcw.Da.FILETIME))); } Marshal.FreeCoTaskMem(intPtr); Marshal.FreeCoTaskMem(intPtr3); Marshal.FreeCoTaskMem(intPtr4); Marshal.FreeCoTaskMem(intPtr2); result = true; } catch (Exception ex) { #if DEBUG Debug.WriteLine(ex); #endif result = false; } return(result); }
/// <summary> /// Reads the current values for a set of items. /// </summary> /// <param name="items">The set of items to read.</param> /// <returns>The results of the read operation for each item.</returns> public virtual TsCDaItemValueResult[] Read(TsCDaItem[] items) { if (items == null) { throw new ArgumentNullException(nameof(items)); } lock (this) { string methodName = "IOPCItemIO.Read"; if (m_server == null) { throw new NotConnectedException(); } int count = items.Length; if (count == 0) { throw new ArgumentOutOfRangeException(nameof(items.Length), "0"); } // initialize arguments. string[] itemIDs = new string[count]; int[] maxAges = new int[count]; for (int ii = 0; ii < count; ii++) { itemIDs[ii] = items[ii].ItemName; maxAges[ii] = (items[ii].MaxAgeSpecified) ? items[ii].MaxAge : 0; } IntPtr pValues = IntPtr.Zero; IntPtr pQualities = IntPtr.Zero; IntPtr pTimestamps = IntPtr.Zero; IntPtr pErrors = IntPtr.Zero; // invoke COM method. try { IOPCItemIO server = BeginComCall <IOPCItemIO>(methodName, true); server.Read( count, itemIDs, maxAges, out pValues, out pQualities, out pTimestamps, out pErrors); } catch (Exception e) { ComCallError(methodName, e); throw Technosoftware.DaAeHdaClient.Com.Interop.CreateException(methodName, e); } finally { EndComCall(methodName); } // unmarshal results. object[] values = Technosoftware.DaAeHdaClient.Com.Interop.GetVARIANTs(ref pValues, count, true); short[] qualities = Technosoftware.DaAeHdaClient.Com.Interop.GetInt16s(ref pQualities, count, true); DateTime[] timestamps = Technosoftware.DaAeHdaClient.Com.Interop.GetFILETIMEs(ref pTimestamps, count, true); int[] errors = Technosoftware.DaAeHdaClient.Com.Interop.GetInt32s(ref pErrors, count, true); // pre-fetch the current locale to use for data conversions. string locale = GetLocale(); // construct result array. TsCDaItemValueResult[] results = new TsCDaItemValueResult[count]; for (int ii = 0; ii < results.Length; ii++) { results[ii] = new TsCDaItemValueResult(items[ii]); results[ii].ServerHandle = null; results[ii].Value = values[ii]; results[ii].Quality = new TsCDaQuality(qualities[ii]); results[ii].QualitySpecified = true; results[ii].Timestamp = timestamps[ii]; results[ii].TimestampSpecified = timestamps[ii] != DateTime.MinValue; results[ii].Result = Technosoftware.DaAeHdaClient.Utilities.Interop.GetResultID(errors[ii]); results[ii].DiagnosticInfo = null; // convert COM code to unified DA code. if (errors[ii] == Result.E_BADRIGHTS) { results[ii].Result = new OpcResult(OpcResult.Da.E_WRITEONLY, Result.E_BADRIGHTS); } // convert the data type since the server does not support the feature. if (results[ii].Value != null && items[ii].ReqType != null) { try { results[ii].Value = ChangeType(values[ii], items[ii].ReqType, locale); } catch (Exception e) { results[ii].Value = null; results[ii].Quality = TsCDaQuality.Bad; results[ii].QualitySpecified = true; results[ii].Timestamp = DateTime.MinValue; results[ii].TimestampSpecified = false; if (e.GetType() == typeof(OverflowException)) { results[ii].Result = Technosoftware.DaAeHdaClient.Utilities.Interop.GetResultID(Result.E_RANGE); } else { results[ii].Result = Technosoftware.DaAeHdaClient.Utilities.Interop.GetResultID(Result.E_BADTYPE); } } } // apply request options. if ((filters_ & (int)TsCDaResultFilter.ItemName) == 0) { results[ii].ItemName = null; } if ((filters_ & (int)TsCDaResultFilter.ItemPath) == 0) { results[ii].ItemPath = null; } if ((filters_ & (int)TsCDaResultFilter.ClientHandle) == 0) { results[ii].ClientHandle = null; } if ((filters_ & (int)TsCDaResultFilter.ItemTime) == 0) { results[ii].Timestamp = DateTime.MinValue; results[ii].TimestampSpecified = false; } } // return results. return(results); } }