ClientSession Class
Constructor
ClientSession
-
conditionId -
eventId -
comment -
callback
Parameters:
-
conditionIdNodeId -
eventIdBuffer -
commentString | LocalizedText -
callbackFunction-
errError | Null
-
Item Index
Methods
- addCommentCondition The AddComment Method is used to apply a comment to a specific state of a Condition instance. Normally, the NodeId of the object instance as the ObjectId is passed to the Call Service. However, some Servers do not expose Condition instances in the AddressSpace. Therefore all Servers shall also allow Clients to call the AddComment Method by specifying ConditionId as the ObjectId. The Method cannot be called with an ObjectId of the ConditionType Node. Notes: Comments are added to Event occurrences identified via an EventId. EventIds where the related EventType is not a ConditionType (or subtype of it) and thus does not support Comments are rejected. A ConditionEvent – where the Comment Variable contains this text – will be sent for the identified state. If a comment is added to a previous state (i.e. a state for which the Server has created a branch), the BranchId and all Condition values of this branch will be reported/.
- browse
- call
- close
- confirmCondition from Spec 1.03 Part 9 : page 27 The Confirm Method is used to confirm an Event Notifications for a Condition instance state where ConfirmedState is FALSE. Normally, the NodeId of the object instance as the ObjectId is passed to the Call Service. However, some Servers do not expose Condition instances in the AddressSpace. Therefore all Servers shall also allow Clients to call the Confirm Method by specifying ConditionId as the ObjectId. The Method cannot be called with an ObjectId of the AcknowledgeableConditionType Node.
- createMonitoredItems
- createSubscription
- deleteMonitoredItems
- deleteSubscriptions
- findMethodId
- getArgumentDefinition
- getBuiltInDataType retrieve the built-in DataType of a Variable, from its DataType attribute useful to determine which DataType to use when constructing a Variant
- getMonitoredItems
- getPublishEngine
- hasBeenClosed
- modifyMonitoredItems
- modifySubscription
- publish
- queryFirst
- read_form4
- readAllAttributes
- readHistoryValue
- readVariableValue
- republish
- setPublishingMode
- transferSubscriptions
- translateBrowsePath
- write
- writeSingleNode
Properties
Methods
browse
-
nodeToBrowse -
callback -
nodesToBrowse -
callback -
nodesToBrowse -
nodeToBrowse
Parameters:
-
nodeToBrowseString | BrowseDescription -
callbackFunction-
errError | Null -
browseResultBrowseResult
-
-
nodesToBrowseArray -
callbackFunction-
Error | Null -
Arrayan array containing the BrowseResult of each BrowseDescription.
-
-
nodesToBrowseArray -
nodeToBrowseString | BrowseDescription
Returns:
Example:
session.browse("RootFolder",function(err,browseResult) {
if(err) return callback(err);
console.log(browseResult.toString());
callback();
} );
const browseDescription = {
nodeId: "ObjectsFolder",
referenceTypeId: "Organizes",
browseDirection: BrowseDirection.Inverse,
includeSubtypes: true,
nodeClassMask: 0,
resultMask: 63
}
session.browse(browseDescription,function(err, browseResult) {
if(err) return callback(err);
console.log(browseResult.toString());
callback();
});
session.browse([ "RootFolder", "ObjectsFolder"],function(err, browseResults) {
assert(browseResults.length === 2);
});
const browseDescriptions = [
{
nodeId: "ObjectsFolder",
referenceTypeId: "Organizes",
browseDirection: BrowseDirection.Inverse,
includeSubtypes: true,
nodeClassMask: 0,
resultMask: 63
},
// {...}
]
session.browse(browseDescriptions,function(err, browseResults) {
});
call
-
methodToCall -
callback -
methodsToCall -
callback
Parameters:
-
methodToCallCallMethodRequestthe call method request
-
callbackFunction-
errError | Null -
responseCallMethodResult
-
-
methodsToCallCallMethodRequest[]the call method request array
-
callbackFunction-
Error | Null -
CallMethodResult[]
-
Example:
: const methodToCall = { objectId: "ns=2;i=12", methodId: "ns=2;i=13", inputArguments: [ new Variant({...}), new Variant({...}), ] } session.call(methodToCall,function(err,callResult) { if (!err) { console.log(" statusCode = ",callResult.statusCode); console.log(" inputArgumentResults[0] = ",callResult.inputArgumentResults[0].toString()); console.log(" inputArgumentResults[1] = ",callResult.inputArgumentResults[1].toString()); console.log(" outputArgument[0] = ",callResult.outputArgument[0].toString()); // array of variant } });
: const methodsToCall = [ { objectId: "ns=2;i=12", methodId: "ns=2;i=13", inputArguments: [ new Variant({...}), new Variant({...}), ] }]; session.call(methodsToCall,function(err,callResutls) { if (!err) { const callResult = callResutls[0]; console.log(" statusCode = ",rep.statusCode); console.log(" inputArgumentResults[0] = ",callResult.inputArgumentResults[0].toString()); console.log(" inputArgumentResults[1] = ",callResult.inputArgumentResults[1].toString()); console.log(" outputArgument[0] = ",callResult.outputArgument[0].toString()); // array of variant } });
close
-
[deleteSubscription=true] -
callback
Parameters:
-
[deleteSubscription=true]Boolean optional -
callbackFunction
confirmCondition
from Spec 1.03 Part 9 : page 27
The Confirm Method is used to confirm an Event Notifications for a Condition instance state
where ConfirmedState is FALSE.
Normally, the NodeId of the object instance as the ObjectId is passed to the Call Service.
However, some Servers do not expose Condition instances in the AddressSpace.
Therefore all Servers shall also allow Clients to call the Confirm Method by specifying ConditionId as the ObjectId.
The Method cannot be called with an ObjectId of the AcknowledgeableConditionType Node.
-
conditionId -
eventId -
comment -
callback
Parameters:
-
conditionIdObject -
eventIdObject -
commentObject -
callbackObject
createMonitoredItems
-
options -
callback
Parameters:
-
optionsCreateMonitoredItemsRequest -
callbackFunction-
errError | Null- the Error if the async method has failed
-
responseCreateMonitoredItemsResponse- the response
-
createSubscription
-
options -
callback
Parameters:
-
optionsCreateSubscriptionRequest-
requestedPublishingIntervalDuration -
requestedLifetimeCountCounter -
requestedMaxKeepAliveCountCounter -
maxNotificationsPerPublishCounter -
publishingEnabledBoolean -
priorityByte
-
-
callbackFunction-
errError | Null- the Error if the async method has failed
-
responseCreateSubscriptionResponse- the response
-
Example:
:
session.createSubscription(request,function(err,response) {} );
deleteMonitoredItems
-
options -
callback
Parameters:
-
optionsDeleteMonitoredItemsRequest -
callbackFunction-
errError | Null- the Error if the async method has failed
-
deleteSubscriptions
-
options -
callback
Parameters:
-
optionsDeleteSubscriptionsRequest -
callbackFunction-
errError | Null- the Error if the async method has failed
-
responseDeleteSubscriptionsResponse- the response
-
Example:
:
session.deleteSubscriptions(request,function(err,response) {} );
findMethodId
-
nodeId -
methodName -
callback
Parameters:
-
nodeIdObject -
methodNameObject -
callbackObject
getArgumentDefinition
-
methodId -
callback -
[object} -
methodId
Parameters:
Returns:
{inputArguments: .., outputArguments: ...}
getBuiltInDataType
retrieve the built-in DataType of a Variable, from its DataType attribute
useful to determine which DataType to use when constructing a Variant
-
nodeId -
callback
Parameters:
-
nodeIdNodeIdthe node id of the variable to query
-
callbackFunctionthe callback function
-
err -
resultDataType
-
Example:
const session = ...; // ClientSession
const nodeId = opcua.VariableIds.Server_ServerStatus_CurrentTime;
session.getBuildInDataType(nodeId,function(err,dataType) {
assert(dataType === opcua.DataType.DateTime);
});
// or
nodeId = opcua.coerceNodeId("ns=2;s=Scalar_Static_ImagePNG");
session.getBuildInDataType(nodeId,function(err,dataType) {
assert(dataType === opcua.DataType.ByteString);
});
getMonitoredItems
-
subscriptionId -
callback
Parameters:
-
subscriptionIdUInt32the subscription Id to return
-
callbackFunction-
errError -
monitoredItemsthe monitored Items
-
monitoredItemsthe monitored Items
-
hasBeenClosed
()
Boolean
Returns:
modifyMonitoredItems
-
options -
callback
Parameters:
-
optionsModifyMonitoredItemsRequest -
callbackFunction-
errError | Null- the Error if the async method has failed
-
responseModifyMonitoredItemsResponse- the response
-
modifySubscription
-
options -
callback
Parameters:
-
optionsModifySubscriptionRequest -
callbackFunction-
errError | Null- the Error if the async method has failed
-
responseModifySubscriptionResponse- the response
-
publish
-
options -
callback
Parameters:
-
optionsPublishRequest -
callbackFunction-
errError | Null- the Error if the async method has failed
-
responsePublishResponse- the response
-
queryFirst
-
queryFirstRequest -
callback
Parameters:
-
queryFirstRequestQueryFirstRequest -
callbackFunction-
errError | Null -
responseQueryFirstResponse
-
read_form4
-
nodeToRead -
[maxAge] -
callback -
nodesToRead -
[maxAge] -
callback -
nodeToRead -
[maxAge] -
nodesToRead -
[maxAge]
Parameters:
-
nodeToReadReadValueId-
nodeIdNodeId | String -
attributeIdAttributeIds
-
-
[maxAge]Number optional -
callbackFunction- the callback function
-
errError | Null- the error or null if the transaction was OK}
-
dataValueDataValue
-
nodesToReadArray- an array of nodeId to read or a ReadValueId
-
[maxAge]Number optional -
callbackFunction- the callback function
-
Error | Null- the error or null if the transaction was OK}
-
Array
-
nodeToReadReadValueId-
NodeId | String -
AttributeIds
-
-
[maxAge]Number optional -
nodesToReadArray -
[maxAge]Number optional
Returns:
Example:
`javascript
`
form1: reading a single node
const nodeToRead = {
nodeId: "ns=2;s=Furnace_1.Temperature",
attributeId: AttributeIds.BrowseName
};
session.read(nodeToRead,function(err,dataValue) {
if (!err) {
console.log(dataValue.toString());
}
});
const nodesToRead = [
{
nodeId: "ns=2;s=Furnace_1.Temperature",
attributeId: AttributeIds.BrowseName
}
];
session.read(nodesToRead,function(err,dataValues) {
if (!err) {
dataValues.forEach(dataValue=>console.log(dataValue.toString()));
}
});
readAllAttributes
-
nodes -
callback
Parameters:
Example:
session.readAllAttributes("ns=2;s=Furnace_1.Temperature",function(err,data) {
if(data.statusCode === StatusCode.Good) {
console.log(" nodeId = ",data.nodeId.toString());
console.log(" browseName = ",data.browseName.toString());
console.log(" description = ",data.description.toString());
console.log(" value = ",data.value.toString()));
}
});
readHistoryValue
-
nodes -
start -
end -
callback
Parameters:
-
nodesReadValueId[]- the read value id
-
startObject- the starttime in UTC format
-
endObject- the endtime in UTC format
-
callbackFunction- the callback function
-
errObject | Nullthe error if write has failed or null if OK
-
resultsDataValue[]- an array of dataValue each read
Example:
session.readHistoryValue("ns=5;s=Simulation Examples.Functions.Sine1","2015-06-10T09:00:00.000Z","2015-06-10T09:01:00.000Z",function(err,dataValues) {} );
readVariableValue
-
node -
callback -
nodes -
callback -
node -
nodes
Parameters:
-
nodeNodeId- the nodeId of the value to read
-
callbackFunction- the callback function
-
errError | Null- the error if write has failed or null if OK
-
dataValueDataValue- the dataValue
-
nodesArray- an array of node to Read
-
callbackFunction- the callback function
-
Error | Null- the error if write has failed or null if OK
-
Array- an array of dataValue each read
-
nodeNodeId | String- the nodeId of the UAVariable to read
-
nodesArray- an array of node to Read
Returns:
Example:
session.readVariableValue("ns=2;s=Furnace_1.Temperature",function(err,dataValue) {
if(err) { return callback(err); }
if (dataValue.statusCode === opcua.StatusCodes.Good) {
}
console.log(dataValue.toString());
callback();
});
session.readVariableValue(["ns=0;i=2257","ns=0;i=2258"],function(err,dataValues) { if (!err) { console.log(dataValues[0].toString()); console.log(dataValues[1].toString()); } });
const dataValue = await session.readVariableValue("ns=1;s=Temperature");
const dataValues = await session.readVariableValue(["ns=1;s=Temperature","ns=1;s=Pressure"]);
republish
-
options -
callback
Parameters:
-
optionsRepublishRequest -
callbackFunction-
errError | Null- the Error if the async method has failed
-
responseRepublishResponse- the response
-
setPublishingMode
-
publishingEnabled -
subscriptionIds -
callback
Parameters:
-
publishingEnabledBoolean -
subscriptionIdsArray -
callbackFunction-
errError | Null- the Error if the async method has failed
-
transferSubscriptions
-
options -
callback
Parameters:
-
optionsTransferSubscriptionsRequest -
callbackFunction-
errError | Null- the Error if the async method has failed
-
responseTransferSubscriptionsResponse- the response
-
translateBrowsePath
-
browsePath -
callback
Parameters:
-
browsePathBrowsePath | Array -
callbackFunction-
errError | Null -
responseBrowsePathResult | Array
-
write
-
nodesToWrite -
callback -
nodeToWrite -
callback -
nodeToWrite -
nodesToWrite
Parameters:
-
nodesToWriteWriteValue[]- the array of value to write. One or more elements.
-
callbackFunction- the callback function
-
errObject | Nullthe error if write has failed or null if OK
-
statusCodesStatusCode[]- an array of status code of each write
-
nodeToWriteWriteValue- the value to write
-
callbackFunction- the callback function
-
Object | Nullthe error if write has failed or null if OK
-
StatusCodes- the status code of the write
-
nodeToWriteWriteValue- the value to write
-
nodesToWriteArray- the value to write
Returns:
Example:
const nodesToWrite = [
{
nodeId: "ns=1;s=SetPoint1",
attributeId: opcua.AttributeIds.Value,
value: {
statusCode: Good,
value: {
dataType: opcua.DataType.Double,
value: 100.0
}
}
},
{
nodeId: "ns=1;s=SetPoint2",
attributeIds opcua.AttributeIds.Value,
value: {
statusCode: Good,
value: {
dataType: opcua.DataType.Double,
value: 45.0
}
}
}
];
session.write(nodesToWrite,function (err,statusCodes) {
if(err) { return callback(err);}
//
});
const nodeToWrite = {
nodeId: "ns=1;s=SetPoint",
attributeId: opcua.AttributeIds.Value,
value: {
statusCode: Good,
value: {
dataType: opcua.DataType.Double,
value: 100.0
}
}
};
session.write(nodeToWrite,function (err,statusCode) {
if(err) { return callback(err);}
//
});
session.write(nodeToWrite).then(function(statusCode) { });
const statusCode = await session.write(nodeToWrite);
session.write(nodesToWrite).then(function(statusCodes) { });
const statusCodes = await session.write(nodesToWrite);
writeSingleNode
-
nodeId -
value -
callback -
nodeId -
value
Parameters:
-
nodeIdNodeId- the node id of the node to write
-
valueVariant- the value to write
-
callbackFunction-
errObject | Nullthe error if write has failed or null if OK
-
statusCodeStatusCode- the status code of the write
-
-
nodeIdNodeId- the node id of the node to write
-
valueVariant- the value to write
Returns:
- the status code of the write
Properties
Events
keepalive
keepalive_failure
raised when a keep-alive request has failed on the session, may be the session has timeout unexpectidaly on the server side, may be the connection is broken.
session_closed
send when the session has been closed by the server ( probably due to inactivity and timeout)
The NodeOPCUA API