internal static OpcDaItemValue[] Create(OpcDaGroup opcDaGroup, OPCITEMSTATE[] ppItemValues, HRESULT[] ppErrors) { try { var result = new OpcDaItemValue[ppItemValues.Length]; for (var i = 0; i < result.Length; i++) { result[i] = new OpcDaItemValue { Timestamp = FileTimeConverter.FromFileTime(ppItemValues[i].ftTimeStamp), Value = ppItemValues[i].vDataValue, Quality = ppItemValues[i].wQuality, Error = ppErrors[i], Item = opcDaGroup.GetItem(ppItemValues[i].hClient) }; } return result; } catch (Exception ex) { Log.Error("Cannot create OpcDaItemValue object.", ex); return new OpcDaItemValue[0]; } }
internal static OpcDaItemValue[] Create(OpcDaGroup opcDaGroup, int dwCount, int[] phClientItems, object[] pvValues, short[] pwQualities, FILETIME[] pftTimeStamps, HRESULT[] pErrors) { try { var values = new OpcDaItemValue[dwCount]; for (var i = 0; i < values.Length; i++) { values[i] = new OpcDaItemValue { Value = pvValues[i], Item = opcDaGroup.GetItem(phClientItems[i]), Quality = pwQualities[i], Timestamp = FileTimeConverter.FromFileTime(pftTimeStamps[i]), Error = pErrors[i] }; } return values; } catch (Exception ex) { Log.Error("Cannot create OpcDaItemValue object.", ex); return new OpcDaItemValue[0]; } }
internal static OpcDaItemValue[] Create(OpcDaGroup opcDaGroup, int dwCount, int[] phClientItems, object[] pvValues, short[] pwQualities, FILETIME[] pftTimeStamps, HRESULT[] pErrors) { try { var values = new OpcDaItemValue[dwCount]; for (var i = 0; i < values.Length; i++) { values[i] = new OpcDaItemValue { Value = pvValues[i], Item = opcDaGroup.GetItem(phClientItems[i]), Quality = pwQualities[i], Timestamp = FileTimeConverter.FromFileTime(pftTimeStamps[i]), Error = pErrors[i] }; } return(values); } catch (Exception ex) { Log.Error("Cannot create OpcDaItemValue object.", ex); return(new OpcDaItemValue[0]); } }
internal static OpcDaItemValue[] Create(IList<OpcDaItem> items, object[] ppvValues, OpcDaQuality[] ppwQualities, DateTimeOffset[] ppftTimeStamps, HRESULT[] ppErrors) { try { var result = new OpcDaItemValue[items.Count]; for (var i = 0; i < ppvValues.Length; i++) { var tagValue = new OpcDaItemValue { Value = ppvValues[i], Quality = ppwQualities[i], Timestamp = ppftTimeStamps[i], Error = ppErrors[i], Item = items[i] }; result[i] = tagValue; } return result; } catch (Exception ex) { Log.Error("Cannot create OpcDaItemValue object.", ex); return new OpcDaItemValue[0]; } }
internal static OpcDaItemValue[] Create(OpcDaGroup opcDaGroup, OPCITEMSTATE[] ppItemValues, HRESULT[] ppErrors) { try { var result = new OpcDaItemValue[ppItemValues.Length]; for (var i = 0; i < result.Length; i++) { result[i] = new OpcDaItemValue { Timestamp = FileTimeConverter.FromFileTime(ppItemValues[i].ftTimeStamp), Value = ppItemValues[i].vDataValue, Quality = ppItemValues[i].wQuality, Error = ppErrors[i], Item = opcDaGroup.GetItem(ppItemValues[i].hClient) }; } return(result); } catch (Exception ex) { Log.Error("Cannot create OpcDaItemValue object.", ex); return(new OpcDaItemValue[0]); } }
internal static OpcDaItemValue[] Create(IList <OpcDaItem> items, object[] ppvValues, OpcDaQuality[] ppwQualities, DateTimeOffset[] ppftTimeStamps, HRESULT[] ppErrors) { try { var result = new OpcDaItemValue[items.Count]; for (var i = 0; i < ppvValues.Length; i++) { var tagValue = new OpcDaItemValue { Value = ppvValues[i], Quality = ppwQualities[i], Timestamp = ppftTimeStamps[i], Error = ppErrors[i], Item = items[i] }; result[i] = tagValue; } return(result); } catch (Exception ex) { Log.Error("Cannot create OpcDaItemValue object.", ex); return(new OpcDaItemValue[0]); } }
/// <summary> /// Reads the specified group items. /// </summary> /// <param name="items">The group items.</param> /// <param name="dataSource">The data source.</param> /// <returns> /// The values of the group items. /// </returns> public OpcDaItemValue[] Read(IList <OpcDaItem> items, OpcDaDataSource dataSource = OpcDaDataSource.Cache) { CheckItems(items); CheckSupported(OpcDaGroupFeatures.Read); int[] serverHandles = ArrayHelpers.GetServerHandles(items); HRESULT[] ppErrors; OPCITEMSTATE[] ppItemValues = As <OpcSyncIO>().Read((OPCDATASOURCE)dataSource, serverHandles, out ppErrors); OpcDaItemValue[] result = OpcDaItemValue.Create(this, ppItemValues, ppErrors); OnValuesChanged(new OpcDaItemValuesChangedEventArgs(result)); return(result); }
/// <summary> /// Reads the specified group items using MaxAge. If the information in the cache is within the MaxAge, then the data /// will be obtained from the cache, otherwise the server must access the device for the requested information. /// </summary> /// <param name="items">The group items.</param> /// <param name="maxAge">The list of MaxAges for the group items.</param> /// <returns> /// The values of the group items. /// </returns> /// <exception cref="System.ArgumentException">Invalid size of maxAge;maxAge</exception> public OpcDaItemValue[] ReadMaxAge(IList <OpcDaItem> items, IList <TimeSpan> maxAge) { CheckSupported(OpcDaGroupFeatures.ReadMaxAge); CheckItems(items); int[] serverHandles = ArrayHelpers.GetServerHandles(items); if (serverHandles.Length != maxAge.Count) { throw new ArgumentException("Invalid size of maxAge", "maxAge"); } // int[] intMaxAge = ArrayHelpers.CreateMaxAgeArray(maxAge, items.Count); DateTimeOffset[] timestamps; HRESULT[] errors; OpcDaQuality[] qualities; object[] ppvValues = As <OpcSyncIO2>() .ReadMaxAge(serverHandles, maxAge, out qualities, out timestamps, out errors); OpcDaItemValue[] result = OpcDaItemValue.Create(items, ppvValues, qualities, timestamps, errors); OnValuesChanged(new OpcDaItemValuesChangedEventArgs(result)); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="OpcDaItemValuesChangedEventArgs"/> class. /// </summary> /// <param name="values">The changed item values.</param> public OpcDaItemValuesChangedEventArgs(OpcDaItemValue[] values) { Values = values; }
public void Test_WriteVQT() { string[] itemIds = new[] { "Write Only.Int1", "Write Only.Int2" }; OpcDaItemValue[] values = new OpcDaItemValue[] { new OpcDaItemValue() { Value = 0, Quality = (short) OPC_QUALITY_STATUS.BAD }, new OpcDaItemValue() { Value = 0, Timestamp = DateTimeOffset.Now-TimeSpan.FromHours(1) }, }; HRESULT[] errors = _server.WriteVQT(itemIds, values); errors.Should().OnlyContain(hres => hres.Succeeded); }