本文整理匯總了TypeScript中node-opcua-client.ClientSession.read方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ClientSession.read方法的具體用法?TypeScript ClientSession.read怎麽用?TypeScript ClientSession.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類node-opcua-client.ClientSession
的用法示例。
在下文中一共展示了ClientSession.read方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: convertNodeIdToDataTypeAsync
/**
* @method convertNodeIdToDataTypeAsync
*
* @param session
* @param dataTypeId
* @param callback
* @param callback.err
* @param callback.dataType
*
* @example
*
* const dataTypeId ="ns=0;i=11"; // Double
* convertNodeIdToDataTypeAsync(session,dataTypeId,function(err,dataType) {
* assert(!err && dataType === DataType.Double);
* });
*
* const dataTypeId ="ns=0;i=290"; // Duration => SubTypeOf Double
* convertNodeIdToDataTypeAsync(session,dataTypeId,function(err,dataType) {
* assert(!err && dataType === DataType.Double);
* });
*
* see also AddressSpace#findCorrespondingBasicDataType
*/
function convertNodeIdToDataTypeAsync(
session: ClientSession,
dataTypeId: NodeId,
callback: Callback<DataType>
) {
const nodeToRead = {
attributeId: AttributeIds.BrowseName,
nodeId: dataTypeId,
};
session.read(nodeToRead, (err: Error | null, dataValue?: DataValue) => {
// istanbul ignore next
if (err) {
setImmediate(() => {
callback(err);
});
return;
}
dataValue = dataValue!;
let dataType: DataType;
// istanbul ignore next
if (dataValue.statusCode !== StatusCodes.Good) {
dataType = DataType.Null;
setImmediate(() => {
callback(null, dataType);
});
return;
}
const dataTypeName = dataValue.value.value;
if (dataTypeId.namespace === 0 && DataType[dataTypeId.value as number]) {
dataType = (DataType as any)[dataTypeId.value as number] as DataType;
setImmediate(() => {
callback(null, dataType);
});
return;
}
/// example => Duration (i=290) => Double (i=11)
// read subTypeOf
const nodeToBrowse = {
browseDirection: BrowseDirection.Inverse,
includeSubtypes: false,
nodeId: dataTypeId,
// BrowseDescription
referenceTypeId: makeRefId("HasSubtype"),
// xx nodeClassMask: makeNodeClassMask("ObjectType"),
resultMask
};
// tslint:disable:no-shadowed-variable
session.browse(nodeToBrowse, (err: Error | null, browseResult?: BrowseResult) => {
// istanbul ignore next
if (err) {
return callback(err);
}
const references = browseResult!.references;
if (!references || references.length !== 1) {
return callback(new Error("cannot find SuperType of " + dataTypeName.toString()));
}
const nodeId = references[0].nodeId;
return convertNodeIdToDataTypeAsync(session, nodeId, callback);
});
});
}