本文整理汇总了Java中org.eclipse.milo.opcua.stack.core.types.builtin.DataValue.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java DataValue.getValue方法的具体用法?Java DataValue.getValue怎么用?Java DataValue.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.milo.opcua.stack.core.types.builtin.DataValue
的用法示例。
在下文中一共展示了DataValue.getValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeDataValue
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; //导入方法依赖的package包/类
public void writeDataValue(DataValue value) throws UaSerializationException {
if (value == null) {
buffer.writeByte(0);
} else {
int mask = 0x00;
if (value.getValue() != null && value.getValue().isNotNull()) mask |= 0x01;
if (!StatusCode.GOOD.equals(value.getStatusCode())) mask |= 0x02;
if (!DateTime.MIN_VALUE.equals(value.getSourceTime())) mask |= 0x04;
if (!DateTime.MIN_VALUE.equals(value.getServerTime())) mask |= 0x08;
buffer.writeByte(mask);
if ((mask & 0x01) == 0x01) writeVariant(value.getValue());
if ((mask & 0x02) == 0x02) writeStatusCode(value.getStatusCode());
if ((mask & 0x04) == 0x04) writeDateTime(value.getSourceTime());
if ((mask & 0x08) == 0x08) writeDateTime(value.getServerTime());
}
}
示例2: run
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; //导入方法依赖的package包/类
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
registerCustomCodec();
// synchronous connect
client.connect().get();
// synchronous read request via VariableNode
VariableNode node = client.getAddressSpace().createVariableNode(
new NodeId(2, "HelloWorld/CustomDataTypeVariable"));
logger.info("DataType={}", node.getDataType().get());
DataValue value = node.readValue().get();
logger.info("Value={}", value);
Variant variant = value.getValue();
ExtensionObject xo = (ExtensionObject) variant.getValue();
CustomDataType decoded = xo.decode();
logger.info("Decoded={}", decoded);
future.complete(client);
}
示例3: read
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; //导入方法依赖的package包/类
@Override
public void read(ReadContext context, Double maxAge, TimestampsToReturn timestamps, List<ReadValueId> readValueIds) {
List<DataValue> results = Lists.newArrayListWithCapacity(readValueIds.size());
for (ReadValueId id : readValueIds) {
ServerNode node = nodeManager.get(id.getNodeId());
if (node != null) {
DataValue value = node.readAttribute(
new AttributeContext(context),
id.getAttributeId(),
timestamps,
id.getIndexRange()
);
if (logger.isTraceEnabled()) {
Variant variant = value.getValue();
Object o = variant != null ? variant.getValue() : null;
logger.trace("Read value={} from attributeId={} of {}",
o, id.getAttributeId(), id.getNodeId());
}
results.add(value);
} else {
results.add(new DataValue(new StatusCode(StatusCodes.Bad_NodeIdUnknown)));
}
}
context.complete(results);
}
示例4: extract
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T extract(DataValue value) throws UaException {
Variant variant = value.getValue();
if (variant == null) return null;
Object o = variant.getValue();
if (o == null) return null;
try {
return (T) o;
} catch (ClassCastException e) {
throw new UaException(StatusCodes.Bad_TypeMismatch);
}
}
示例5: validateDataType
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; //导入方法依赖的package包/类
static DataValue validateDataType(ExpandedNodeId dataType, DataValue value) throws UaException {
Variant variant = value.getValue();
if (variant == null) return value;
Object o = variant.getValue();
if (o == null) throw new UaException(StatusCodes.Bad_TypeMismatch);
Class<?> expected = TypeUtil.getBackingClass(dataType);
Class<?> actual = o.getClass().isArray() ?
o.getClass().getComponentType() : o.getClass();
if (expected == null) {
throw new UaException(StatusCodes.Bad_TypeMismatch);
} else {
if (!expected.isAssignableFrom(actual)) {
/*
* Writing a ByteString to a UByte[] is explicitly allowed by the spec.
*/
if (o instanceof ByteString && expected == UByte.class) {
ByteString byteString = (ByteString) o;
return new DataValue(
new Variant(byteString.uBytes()),
value.getStatusCode(),
value.getSourceTime(),
value.getServerTime());
} else if (expected == Variant.class) {
// allow to write anything to a Variant
return value;
} else {
throw new UaException(StatusCodes.Bad_TypeMismatch);
}
}
}
return value;
}
示例6: toVariant
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; //导入方法依赖的package包/类
@Converter
public static Variant toVariant(final DataValue value) {
return value.getValue();
}