本文整理汇总了C#中Opc.Ua.DataValue类的典型用法代码示例。如果您正苦于以下问题:C# DataValue类的具体用法?C# DataValue怎么用?C# DataValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataValue类属于Opc.Ua命名空间,在下文中一共展示了DataValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PushRawValue
/// <summary>
/// Pushes the next raw value into the stream.
/// </summary>
/// <param name="value">The data value to append to the stream.</param>
/// <returns>True if successful, false if the source timestamp has been superceeded by values already in the stream.</returns>
public bool PushRawValue(DataValue value)
{
if (value == null)
{
return false;
}
if (CompareTimestamps(value.SourceTimestamp, m_lastRawTimestamp) < 0)
{
return false;
}
LinkedListNode<DataValue> node = m_values.AddLast(value);
m_lastRawTimestamp = value.SourceTimestamp;
if (IsGood(value))
{
if (CompareTimestamps(m_lastRawTimestamp, m_nextSlice.StartTime) <= 0)
{
m_nextSlice.EarlyBound = node;
}
if (CompareTimestamps(m_lastRawTimestamp, m_nextSlice.EndTime) >= 0)
{
m_nextSlice.LateBound = node;
m_nextSlice.Complete = true;
}
}
return true;
}
示例2: ReadModified
/// <summary>
/// Reads the raw modified data for an item.
/// </summary>
private StatusCode ReadModified(HdaHistoryReadRawModifiedRequest request)
{
string methodName = "IOPCHDA_SyncRead.ReadModified";
OPCHDA_TIME htStartTime = ConvertTime(request.StartTime);
OPCHDA_TIME htEndTime = ConvertTime(request.EndTime);
int maxReturnValues = request.MaxReturnValues;
if (m_maxReturnValues > 0 && maxReturnValues > m_maxReturnValues)
{
maxReturnValues = m_maxReturnValues;
}
IntPtr ppItemValues;
IntPtr ppErrors;
try
{
IOPCHDA_SyncRead server = BeginComCall<IOPCHDA_SyncRead>(methodName, true);
server.ReadModified(
ref htStartTime,
ref htEndTime,
maxReturnValues,
1,
new int[] { request.ServerHandle },
out ppItemValues,
out ppErrors);
}
catch (Exception e)
{
if (ComUtils.IsUnknownError(e, ResultIds.E_NOTIMPL))
{
ComCallError(methodName, e);
}
return StatusCodes.BadNoData;
}
finally
{
EndComCall(methodName);
}
// check for error.
int[] errors = ComUtils.GetInt32s(ref ppErrors, 1, true);
if (errors[0] < 0)
{
return StatusCodes.BadNodeIdUnknown;
}
// check if operation halted.
request.Completed = errors[0] != ResultIds.S_MOREDATA;
// unmarshal the results.
OPCHDA_MODIFIEDITEM result = (OPCHDA_MODIFIEDITEM)Marshal.PtrToStructure(ppItemValues, typeof(OPCHDA_MODIFIEDITEM));
if (result.dwCount > 0)
{
object[] values = ComUtils.GetVARIANTs(ref result.pvDataValues, result.dwCount, true);
int[] qualities = ComUtils.GetInt32s(ref result.pdwQualities, result.dwCount, true);
DateTime[] timestamps = ComUtils.GetDateTimes(ref result.pftTimeStamps, result.dwCount, true);
DateTime[] modificationTimes = ComUtils.GetDateTimes(ref result.pftModificationTime, result.dwCount, true);
string[] userNames = ComUtils.GetUnicodeStrings(ref result.szUser, result.dwCount, true);
int[] editTypes = ComUtils.GetInt32s(ref result.pEditType, result.dwCount, true);
request.Results = new DataValueCollection(result.dwCount);
request.ModificationInfos = new ModificationInfoCollection(result.dwCount);
for (int ii = 0; ii < result.dwCount; ii++)
{
DataValue value = new DataValue();
value.Value = ComUtils.ProcessComValue(values[ii]);
value.StatusCode = ComUtils.GetHdaQualityCode(Utils.ToUInt32(qualities[ii]));
value.SourceTimestamp = timestamps[ii];
request.Results.Add(value);
ModificationInfo modification = new ModificationInfo();
modification.ModificationTime = modificationTimes[ii];
modification.UpdateType = (HistoryUpdateType)editTypes[ii];
modification.UserName = userNames[ii];
request.ModificationInfos.Add(modification);
}
if (!request.Completed)
{
request.StartTime = request.Results[request.Results.Count-1].SourceTimestamp;
}
}
Marshal.FreeCoTaskMem(ppItemValues);
if (result.dwCount == 0)
{
return StatusCodes.GoodNoData;
}
//.........这里部分代码省略.........
示例3: ReadAtTime
/// <summary>
/// Reads the data for an item at the specified times.
/// </summary>
private StatusCode ReadAtTime(HdaHistoryReadAtTimeRequest request)
{
string methodName = "IOPCHDA_SyncRead.ReadAtTime";
IntPtr ppItemValues;
IntPtr ppErrors;
System.Runtime.InteropServices.ComTypes.FILETIME[] pTimestamps = new System.Runtime.InteropServices.ComTypes.FILETIME[request.ReqTimes.Count];
for (int ii = 0; ii < pTimestamps.Length; ii++)
{
pTimestamps[ii] = ComUtils.GetFILETIME(request.ReqTimes[ii]);
}
try
{
IOPCHDA_SyncRead server = BeginComCall<IOPCHDA_SyncRead>(methodName, true);
server.ReadAtTime(
pTimestamps.Length,
pTimestamps,
1,
new int[] { request.ServerHandle },
out ppItemValues,
out ppErrors);
}
catch (Exception e)
{
ComCallError(methodName, e);
return StatusCodes.BadUnexpectedError;
}
finally
{
EndComCall(methodName);
}
// check for error.
int[] errors = ComUtils.GetInt32s(ref ppErrors, 1, true);
if (errors[0] < 0)
{
return StatusCodes.BadNodeIdUnknown;
}
// check if operation halted.
request.Completed = true;
// unmarshal the results.
OPCHDA_ITEM result = (OPCHDA_ITEM)Marshal.PtrToStructure(ppItemValues, typeof(OPCHDA_ITEM));
if (result.dwCount > 0)
{
object[] values = ComUtils.GetVARIANTs(ref result.pvDataValues, result.dwCount, true);
int[] qualities = ComUtils.GetInt32s(ref result.pdwQualities, result.dwCount, true);
DateTime[] timestamps = ComUtils.GetDateTimes(ref result.pftTimeStamps, result.dwCount, true);
request.Results = new DataValueCollection(result.dwCount);
for (int ii = 0; ii < result.dwCount; ii++)
{
DataValue value = new DataValue();
value.Value = ComUtils.ProcessComValue(values[ii]);
value.StatusCode = ComUtils.GetHdaQualityCode(Utils.ToUInt32(qualities[ii]));
value.SourceTimestamp = timestamps[ii];
request.Results.Add(value);
}
}
Marshal.FreeCoTaskMem(ppItemValues);
if (result.dwCount == 0)
{
return StatusCodes.GoodNoData;
}
return StatusCodes.Good;
}
示例4: WriteDataValue
/// <summary>
/// Writes an DataValue array to the stream.
/// </summary>
public void WriteDataValue(string fieldName, DataValue value)
{
if (BeginField(fieldName, value == null, true))
{
PushNamespace(Namespaces.OpcUaXsd);
if (value != null)
{
WriteVariant("Value", value.WrappedValue);
WriteStatusCode("StatusCode", value.StatusCode);
WriteDateTime("SourceTimestamp", value.SourceTimestamp);
WriteUInt16("SourcePicoseconds", value.SourcePicoseconds);
WriteDateTime("ServerTimestamp", value.ServerTimestamp);
WriteUInt16("ServerPicoseconds", value.ServerPicoseconds);
}
PopNamespace();
EndField(fieldName);
}
}
示例5: ToString
public override string ToString(DataValue dv)
{
DateTime dt = DateTime.Parse(dv.ToString());
return dt.ToLocalTime().ToString();
}
示例6: DataValue
public DataValue() { m_value = new Opc.Ua.DataValue(); }
示例7: ReadDataValue
/// <summary>
/// Reads an DataValue from the stream.
/// </summary>
public DataValue ReadDataValue(string fieldName)
{
DataValue value = new DataValue();
if (BeginField(fieldName, true))
{
PushNamespace(Namespaces.OpcUaXsd);
value.WrappedValue = ReadVariant("Value");
value.StatusCode = ReadStatusCode("StatusCode");
value.SourceTimestamp = ReadDateTime("SourceTimestamp");
value.SourcePicoseconds = ReadUInt16("SourcePicoseconds");
value.ServerTimestamp = ReadDateTime("ServerTimestamp");
value.ServerPicoseconds = ReadUInt16("ServerPicoseconds");
PopNamespace();
EndField(fieldName);
}
return value;
}
示例8: Read
/// <summary>
/// Reads the value of a attribute.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="attributeId">The attribute id.</param>
/// <param name="value">The value.</param>
/// <returns>The result of read operation.</returns>
public ServiceResult Read(IOperationContext context, uint attributeId, DataValue value)
{
if (!SupportsAttribute(attributeId))
{
return StatusCodes.BadAttributeIdInvalid;
}
value.Value = Read(attributeId);
value.StatusCode = StatusCodes.Good;
if (attributeId == Attributes.Value)
{
value.SourceTimestamp = DateTime.UtcNow;
}
return ServiceResult.Good;
}
示例9: Write
/// <summary>
/// Writes the value of an attribute.
/// </summary>
/// <param name="attributeId">The attribute id.</param>
/// <param name="value">The value.</param>
/// <returns>The result of write operation.</returns>
public ServiceResult Write(uint attributeId, DataValue value)
{
if (!SupportsAttribute(attributeId))
{
return StatusCodes.BadAttributeIdInvalid;
}
// check for read only attributes.
switch (attributeId)
{
case Attributes.NodeId:
case Attributes.NodeClass:
{
return StatusCodes.BadNotWritable;
}
}
// check data type.
if (attributeId != Attributes.Value)
{
if (Attributes.GetDataTypeId(attributeId) != TypeInfo.GetDataTypeId(value))
{
return StatusCodes.BadTypeMismatch;
}
}
return Write(attributeId, value.Value);
}
示例10: GetDataValue
/// <summary>
/// Returns the data value displayed in the control.
/// </summary>
public DataValue GetDataValue()
{
DataValue value = new DataValue();
value.WrappedValue = GetValue();
if (ShowStatusTimestamp)
{
value.StatusCode = StatusCode;
value.SourceTimestamp = SourceTimestamp;
value.ServerTimestamp = ServerTimestamp;
}
return value;
}
示例11: SetDataValue
/// <summary>
/// Returns the data value displayed in the control.
/// </summary>
public void SetDataValue(DataValue value, TypeInfo targetType)
{
DataTypeCB.SelectedItem = BuiltInType.Null;
ValueRankCB.SelectedItem = ValueRankOptions.Scalar;
StatusCode = StatusCodes.Good;
SourceTimestamp = DateTime.MinValue;
ServerTimestamp = DateTime.MinValue;
if (value != null)
{
SetValue(value.WrappedValue);
StatusCode = value.StatusCode;
SourceTimestamp = value.SourceTimestamp;
ServerTimestamp = value.ServerTimestamp;
StatusCodeCK.Checked = true;
SourceTimestampCK.Checked = true;
ServerTimestampCK.Checked = true;
}
// allow data type to be changed by default.
DataTypeCB.Enabled = true;
if (targetType != null)
{
DataType = targetType.BuiltInType;
ValueRank = targetType.ValueRank;
DataTypeCB.Enabled = false;
ValueRankCB.Enabled = false;
}
}
示例12: ReadVariant
//.........这里部分代码省略.........
values[ii] = ReadQualifiedName(null);
}
array = values;
break;
}
case BuiltInType.LocalizedText:
{
LocalizedText[] values = new LocalizedText[length];
for (int ii = 0; ii < values.Length; ii++)
{
values[ii] = ReadLocalizedText(null);
}
array = values;
break;
}
case BuiltInType.ExtensionObject:
{
ExtensionObject[] values = new ExtensionObject[length];
for (int ii = 0; ii < values.Length; ii++)
{
values[ii] = ReadExtensionObject();
}
array = values;
break;
}
case BuiltInType.DataValue:
{
DataValue[] values = new DataValue[length];
for (int ii = 0; ii < values.Length; ii++)
{
values[ii] = ReadDataValue(null);
}
array = values;
break;
}
case BuiltInType.Variant:
{
Variant[] values = new Variant[length];
for (int ii = 0; ii < values.Length; ii++)
{
values[ii] = ReadVariant(null);
}
array = values;
break;
}
default:
{
throw new ServiceResultException(
StatusCodes.BadDecodingError,
Utils.Format("Cannot decode unknown type in Variant object (0x{0:X2}).", encodingByte));
}
}
示例13: ReadDataValue
/// <summary>
/// Reads an DataValue from the stream.
/// </summary>
public DataValue ReadDataValue(string fieldName)
{
// read the encoding byte.
byte encodingByte = m_reader.ReadByte();
DataValue value = new DataValue();
// read the fields of the DataValue structure.
if ((encodingByte & (byte)DataValueEncodingBits.Value) != 0)
{
value.WrappedValue = ReadVariant(null);
}
if ((encodingByte & (byte)DataValueEncodingBits.StatusCode) != 0)
{
value.StatusCode = ReadStatusCode(null);
}
if ((encodingByte & (byte)DataValueEncodingBits.SourceTimestamp) != 0)
{
value.SourceTimestamp = ReadDateTime(null);
}
if ((encodingByte & (byte)DataValueEncodingBits.SourcePicoseconds) != 0)
{
value.SourcePicoseconds = ReadUInt16(null);
}
if ((encodingByte & (byte)DataValueEncodingBits.ServerTimestamp) != 0)
{
value.ServerTimestamp = ReadDateTime(null);
}
if ((encodingByte & (byte)DataValueEncodingBits.ServerPicoseconds) != 0)
{
value.ServerPicoseconds = ReadUInt16(null);
}
return value;
}
示例14: UpdateRow
/// <summary>
/// Updates the row with the node to read.
/// </summary>
public void UpdateRow(DataRow row, DataValue value)
{
row[6] = value;
row[7] = (value.WrappedValue.TypeInfo != null) ? value.WrappedValue.TypeInfo.ToString() : String.Empty;
row[8] = value.WrappedValue;
row[9] = value.StatusCode;
row[10] = (value.SourceTimestamp != DateTime.MinValue) ? Utils.Format("{0:hh:mm:ss.fff}", value.SourceTimestamp.ToLocalTime()) : String.Empty;
row[11] = (value.ServerTimestamp != DateTime.MinValue) ? Utils.Format("{0:hh:mm:ss.fff}", value.ServerTimestamp.ToLocalTime()) : String.Empty;
}
示例15: GetAttributeValue
/// <summary cref="IFilterTarget.GetAttributeValue" />
public virtual object GetAttributeValue(
FilterContext context,
NodeId typeDefinitionId,
IList<QualifiedName> relativePath,
uint attributeId,
NumericRange indexRange)
{
// check the type definition.
if (!NodeId.IsNull(typeDefinitionId) && typeDefinitionId != ObjectTypes.BaseEventType)
{
if (!context.TypeTree.IsTypeOf(TypeDefinitionId, typeDefinitionId))
{
return null;
}
}
// read the child attribute.
DataValue dataValue = new DataValue();
ServiceResult result = ReadChildAttribute(
null,
relativePath,
0,
attributeId,
dataValue);
if (ServiceResult.IsBad(result))
{
return null;
}
// apply any index range.
object value = dataValue.Value;
if (value != null)
{
result = indexRange.ApplyRange(ref value);
if (ServiceResult.IsBad(result))
{
return null;
}
}
// return the result.
return value;
}