public void OnReadAnnotations(int dwTransactionID, int hrStatus, int dwNumItems, OPCHDA_ANNOTATION[] pAnnotationValues, int[] phrErrors) { try { lock (this) { Request request = (Request)this.m_requests[dwTransactionID]; if (request != null) { AnnotationValueCollection[] results = new AnnotationValueCollection[pAnnotationValues.Length]; for (int i = 0; i < pAnnotationValues.Length; i++) { results[i] = OpcCom.Hda.Interop.GetAnnotationValueCollection(pAnnotationValues[i], false); results[i].ServerHandle = pAnnotationValues[i].hClient; results[i].ResultID = OpcCom.Interop.GetResultID(phrErrors[i]); } if (request.InvokeCallback(results)) { this.m_requests.Remove(request.RequestID); } } } } catch (Exception exception) { this.HandleException(dwTransactionID, exception); } }
/// <summary> /// Unmarshals and deallocates an array of OPCHDA_ANNOTATION structures. /// </summary> internal static AnnotationValueCollection[] GetAnnotationValueCollections(ref IntPtr pInput, int count, bool deallocate) { AnnotationValueCollection[] output = null; if (pInput != IntPtr.Zero && count > 0) { output = new AnnotationValueCollection[count]; IntPtr pos = pInput; for (int ii = 0; ii < count; ii++) { output[ii] = GetAnnotationValueCollection(pos, deallocate); pos = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(OpcRcw.Hda.OPCHDA_ANNOTATION))); } if (deallocate) { Marshal.FreeCoTaskMem(pInput); pInput = IntPtr.Zero; } } return(output); }
/// <summary> /// Unmarshals and deallocates an OPCHDA_ANNOTATION structure. /// </summary> internal static AnnotationValueCollection GetAnnotationValueCollection(OpcRcw.Hda.OPCHDA_ANNOTATION input, bool deallocate) { AnnotationValueCollection output = new AnnotationValueCollection(); output.ClientHandle = input.hClient; DateTime[] timestamps = OpcCom.Interop.GetFILETIMEs(ref input.ftTimeStamps, input.dwNumValues, deallocate); string[] annotations = OpcCom.Interop.GetUnicodeStrings(ref input.szAnnotation, input.dwNumValues, deallocate); DateTime[] creationTimes = OpcCom.Interop.GetFILETIMEs(ref input.ftAnnotationTime, input.dwNumValues, deallocate); string[] users = OpcCom.Interop.GetUnicodeStrings(ref input.szUser, input.dwNumValues, deallocate); for (int ii = 0; ii < input.dwNumValues; ii++) { AnnotationValue value = new AnnotationValue(); value.Timestamp = timestamps[ii]; value.Annotation = annotations[ii]; value.CreationTime = creationTimes[ii]; value.User = users[ii]; output.Add(value); } return(output); }
internal static AnnotationValueCollection GetAnnotationValueCollection(IntPtr pInput, bool deallocate) { AnnotationValueCollection annotationValueCollection = null; if (pInput != IntPtr.Zero) { annotationValueCollection = GetAnnotationValueCollection((OPCHDA_ANNOTATION)Marshal.PtrToStructure(pInput, typeof(OPCHDA_ANNOTATION)), deallocate); if (deallocate) { Marshal.DestroyStructure(pInput, typeof(OPCHDA_ANNOTATION)); } } return(annotationValueCollection); }
/// <summary> /// Unmarshals and deallocates an OPCHDA_ANNOTATION structure. /// </summary> internal static AnnotationValueCollection GetAnnotationValueCollection(IntPtr pInput, bool deallocate) { AnnotationValueCollection output = null; if (pInput != IntPtr.Zero) { object item = Marshal.PtrToStructure(pInput, typeof(OpcRcw.Hda.OPCHDA_ANNOTATION)); output = GetAnnotationValueCollection((OpcRcw.Hda.OPCHDA_ANNOTATION)item, deallocate); if (deallocate) { Marshal.DestroyStructure(pInput, typeof(OpcRcw.Hda.OPCHDA_ANNOTATION)); } } return(output); }
/// <summary> /// Called when an asynchronous read annotations request completes. /// </summary> public void OnReadAnnotations( int dwTransactionID, int hrStatus, int dwNumItems, OPCHDA_ANNOTATION[] pAnnotationValues, int[] phrErrors) { try { lock (this) { // lookup request transaction. Request request = (Request)m_requests[dwTransactionID]; if (request == null) { return; } // unmarshal results. AnnotationValueCollection[] results = new AnnotationValueCollection[pAnnotationValues.Length]; for (int ii = 0; ii < pAnnotationValues.Length; ii++) { results[ii] = Interop.GetAnnotationValueCollection(pAnnotationValues[ii], false); results[ii].ServerHandle = pAnnotationValues[ii].hClient; results[ii].ResultID = OpcCom.Interop.GetResultID(phrErrors[ii]); } // invoke callback - remove request if all results arrived. if (request.InvokeCallback(results)) { m_requests.Remove(request.RequestID); } } } catch (Exception exception) { HandleException(dwTransactionID, exception); } }
internal static AnnotationValueCollection[] GetAnnotationValueCollections(ref IntPtr pInput, int count, bool deallocate) { AnnotationValueCollection[] valuesArray = null; if ((pInput != IntPtr.Zero) && (count > 0)) { valuesArray = new AnnotationValueCollection[count]; IntPtr ptr = pInput; for (int i = 0; i < count; i++) { valuesArray[i] = GetAnnotationValueCollection(ptr, deallocate); ptr = (IntPtr)(ptr.ToInt32() + Marshal.SizeOf(typeof(OPCHDA_ANNOTATION))); } if (deallocate) { Marshal.FreeCoTaskMem(pInput); pInput = IntPtr.Zero; } } return(valuesArray); }
internal static AnnotationValueCollection GetAnnotationValueCollection(OPCHDA_ANNOTATION input, bool deallocate) { AnnotationValueCollection values = new AnnotationValueCollection { ClientHandle = input.hClient }; DateTime[] timeArray = OpcCom.Interop.GetFILETIMEs(ref input.ftTimeStamps, input.dwNumValues, deallocate); string[] strArray = OpcCom.Interop.GetUnicodeStrings(ref input.szAnnotation, input.dwNumValues, deallocate); DateTime[] timeArray2 = OpcCom.Interop.GetFILETIMEs(ref input.ftAnnotationTime, input.dwNumValues, deallocate); string[] strArray2 = OpcCom.Interop.GetUnicodeStrings(ref input.szUser, input.dwNumValues, deallocate); for (int i = 0; i < input.dwNumValues; i++) { AnnotationValue value2 = new AnnotationValue { Timestamp = timeArray[i], Annotation = strArray[i], CreationTime = timeArray2[i], User = strArray2[i] }; values.Add(value2); } return(values); }