ClientSession Class
Constructor
ClientSession
-
conditionId
-
eventId
-
comment
-
callback
Parameters:
-
conditionId
NodeId -
eventId
Buffer -
comment
String | LocalizedText -
callback
Function-
err
Error | 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:
-
nodeToBrowse
String | BrowseDescription -
callback
Function-
err
Error | Null -
browseResult
BrowseResult
-
-
nodesToBrowse
Array -
callback
Function-
Error | Null
-
Array
an array containing the BrowseResult of each BrowseDescription.
-
-
nodesToBrowse
Array -
nodeToBrowse
String | 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:
-
methodToCall
CallMethodRequestthe call method request
-
callback
Function-
err
Error | Null -
response
CallMethodResult
-
-
methodsToCall
CallMethodRequest[]the call method request array
-
callback
Function-
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 -
callback
Function
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:
-
conditionId
Object -
eventId
Object -
comment
Object -
callback
Object
createMonitoredItems
-
options
-
callback
Parameters:
-
options
CreateMonitoredItemsRequest -
callback
Function-
err
Error | Null- the Error if the async method has failed
-
response
CreateMonitoredItemsResponse- the response
-
createSubscription
-
options
-
callback
Parameters:
-
options
CreateSubscriptionRequest-
requestedPublishingInterval
Duration -
requestedLifetimeCount
Counter -
requestedMaxKeepAliveCount
Counter -
maxNotificationsPerPublish
Counter -
publishingEnabled
Boolean -
priority
Byte
-
-
callback
Function-
err
Error | Null- the Error if the async method has failed
-
response
CreateSubscriptionResponse- the response
-
Example:
:
session.createSubscription(request,function(err,response) {} );
deleteMonitoredItems
-
options
-
callback
Parameters:
-
options
DeleteMonitoredItemsRequest -
callback
Function-
err
Error | Null- the Error if the async method has failed
-
deleteSubscriptions
-
options
-
callback
Parameters:
-
options
DeleteSubscriptionsRequest -
callback
Function-
err
Error | Null- the Error if the async method has failed
-
response
DeleteSubscriptionsResponse- the response
-
Example:
:
session.deleteSubscriptions(request,function(err,response) {} );
findMethodId
-
nodeId
-
methodName
-
callback
Parameters:
-
nodeId
Object -
methodName
Object -
callback
Object
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:
-
nodeId
NodeIdthe node id of the variable to query
-
callback
Functionthe callback function
-
err
-
result
DataType
-
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:
-
subscriptionId
UInt32the subscription Id to return
-
callback
Function-
err
Error -
monitoredItems
the monitored Items
-
monitoredItems
the monitored Items
-
hasBeenClosed
()
Boolean
Returns:
modifyMonitoredItems
-
options
-
callback
Parameters:
-
options
ModifyMonitoredItemsRequest -
callback
Function-
err
Error | Null- the Error if the async method has failed
-
response
ModifyMonitoredItemsResponse- the response
-
modifySubscription
-
options
-
callback
Parameters:
-
options
ModifySubscriptionRequest -
callback
Function-
err
Error | Null- the Error if the async method has failed
-
response
ModifySubscriptionResponse- the response
-
publish
-
options
-
callback
Parameters:
-
options
PublishRequest -
callback
Function-
err
Error | Null- the Error if the async method has failed
-
response
PublishResponse- the response
-
queryFirst
-
queryFirstRequest
-
callback
Parameters:
-
queryFirstRequest
QueryFirstRequest -
callback
Function-
err
Error | Null -
response
QueryFirstResponse
-
read_form4
-
nodeToRead
-
[maxAge]
-
callback
-
nodesToRead
-
[maxAge]
-
callback
-
nodeToRead
-
[maxAge]
-
nodesToRead
-
[maxAge]
Parameters:
-
nodeToRead
ReadValueId-
nodeId
NodeId | String -
attributeId
AttributeIds
-
-
[maxAge]
Number optional -
callback
Function- the callback function
-
err
Error | Null- the error or null if the transaction was OK}
-
dataValue
DataValue
-
nodesToRead
Array- an array of nodeId to read or a ReadValueId
-
[maxAge]
Number optional -
callback
Function- the callback function
-
Error | Null
- the error or null if the transaction was OK}
-
Array
-
nodeToRead
ReadValueId-
NodeId | String
-
AttributeIds
-
-
[maxAge]
Number optional -
nodesToRead
Array -
[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:
-
nodes
ReadValueId[]- the read value id
-
start
Object- the starttime in UTC format
-
end
Object- the endtime in UTC format
-
callback
Function- the callback function
-
err
Object | Nullthe error if write has failed or null if OK
-
results
DataValue[]- 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:
-
node
NodeId- the nodeId of the value to read
-
callback
Function- the callback function
-
err
Error | Null- the error if write has failed or null if OK
-
dataValue
DataValue- the dataValue
-
nodes
Array- an array of node to Read
-
callback
Function- the callback function
-
Error | Null
- the error if write has failed or null if OK
-
Array
- an array of dataValue each read
-
node
NodeId | String- the nodeId of the UAVariable to read
-
nodes
Array- 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:
-
options
RepublishRequest -
callback
Function-
err
Error | Null- the Error if the async method has failed
-
response
RepublishResponse- the response
-
setPublishingMode
-
publishingEnabled
-
subscriptionIds
-
callback
Parameters:
-
publishingEnabled
Boolean -
subscriptionIds
Array -
callback
Function-
err
Error | Null- the Error if the async method has failed
-
transferSubscriptions
-
options
-
callback
Parameters:
-
options
TransferSubscriptionsRequest -
callback
Function-
err
Error | Null- the Error if the async method has failed
-
response
TransferSubscriptionsResponse- the response
-
translateBrowsePath
-
browsePath
-
callback
Parameters:
-
browsePath
BrowsePath | Array -
callback
Function-
err
Error | Null -
response
BrowsePathResult | Array
-
write
-
nodesToWrite
-
callback
-
nodeToWrite
-
callback
-
nodeToWrite
-
nodesToWrite
Parameters:
-
nodesToWrite
WriteValue[]- the array of value to write. One or more elements.
-
callback
Function- the callback function
-
err
Object | Nullthe error if write has failed or null if OK
-
statusCodes
StatusCode[]- an array of status code of each write
-
nodeToWrite
WriteValue- the value to write
-
callback
Function- the callback function
-
Object | Null
the error if write has failed or null if OK
-
StatusCodes
- the status code of the write
-
nodeToWrite
WriteValue- the value to write
-
nodesToWrite
Array- 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:
-
nodeId
NodeId- the node id of the node to write
-
value
Variant- the value to write
-
callback
Function-
err
Object | Nullthe error if write has failed or null if OK
-
statusCode
StatusCode- the status code of the write
-
-
nodeId
NodeId- the node id of the node to write
-
value
Variant- 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)