UAVariable Class
A OPCUA Variable Node
Constructor
UAVariable
-
options
Parameters:
-
options
Object-
value
-
browseName
String -
dataType
NodeId | String -
valueRank
Int32 -
arrayDimensions
Null | Array -
accessLevel
AccessLevel -
userAccessLevel
AccessLevel -
[minimumSamplingInterval= -1]
optional -
[historizing= false]
Boolean optional -
[permissions]
optional -
parentNodeId
NodeIdThe AccessLevel Attribute is used to indicate how the Value of a Variable can be accessed (read/write) and if it contains current and/or historic data. The AccessLevel does not take any user access rights into account, i.e. although the Variable is writable this may be restricted to a certain user / user group. The AccessLevel is an 8-bit unsigned integer with the structure defined in the following table:
Field Bit Description CurrentRead 0 Indicates if the current value is readable (0 means not readable, 1 means readable). CurrentWrite 1 Indicates if the current value is writable (0 means not writable, 1 means writable). HistoryRead 2 Indicates if the history of the value is readable (0 means not readable, 1 means readable). HistoryWrite 3 Indicates if the history of the value is writable (0 means not writable, 1 means writable). SemanticChange 4 Indicates if the Variable used as Property generates SemanticChangeEvents (see 9.31). Reserved 5:7 Reserved for future use. Shall always be zero.
The first two bits also indicate if a current value of this Variable is available and the second two bits indicates if the history of the Variable is available via the OPC UA server.
-
Item Index
Methods
- bindExtensionObject
- bindVariable
- isReadable
- isUserReadable
- isUserWritable
- isValueInRange note: this method is overridden in address-space-data-access
- isWritable
- readAttribute
- readValue
- readValueAsync
- setValueFromSource
- touchValue touch the source timestamp of a Variable and cascade up the change to the parent variable if any.
- writeAttribute
- writeEnumValue
- writeValue
Methods
bindExtensionObject
-
[optionalExtensionObject=null]
Parameters:
-
[optionalExtensionObject=null]
ExtensionObject optional
Returns:
bindVariable
-
options
-
[overwrite = false]
bind a variable with a get and set functions.
Parameters:
-
options
Object-
[dataType=null]
DataType optionalthe nodeId of the dataType
-
[accessLevel]
Number optionalAccessLevelFlagItem
-
[userAccessLevel]
Number optionalAccessLevelFlagItem
-
[set]
Function optionalthe variable setter function
-
[get]
Function optionalthe variable getter function. the function must return a Variant or a status code
-
[timestamped_get]
Function optionalthe getter function. this function must return a object with the following
-
[historyRead]
Function optionalproperties:
- value: a Variant or a status code
- sourceTimestamp
- sourcePicoseconds
-
[timestamped_set]
Function optional -
[refreshFunc]
Function optionalthe variable asynchronous getter function.
-
-
[overwrite = false]
Boolean optionalset overwrite to true to overwrite existing binding
Returns:
void
Providing read access to the underlying value
Variation 1
In this variation, the user provides a function that returns a Variant with the current value.
The sourceTimestamp will be set automatically.
The get function is called synchronously.
Example:
...
var options = {
get : function() {
return new Variant({...});
},
set : function(variant) {
// store the variant somewhere
return StatusCodes.Good;
}
};
...
engine.bindVariable(nodeId,options):
...
Variation 2:
This variation can be used when the user wants to specify a specific '''sourceTimestamp''' associated with the current value of the UAVariable.
The provided timestamped_get
function should return an object with three properties:
- value: containing the variant value or a error StatusCode,
- sourceTimestamp
- sourcePicoseconds
...
var myDataValue = new DataValue({
value: {dataType: DataType.Double , value: 10.0},
sourceTimestamp : new Date(),
sourcePicoseconds: 0
});
...
var options = {
timestamped_get : function() { return myDataValue; }
};
...
engine.bindVariable(nodeId,options):
...
// record a new value
myDataValue.value.value = 5.0;
myDataValue.sourceTimestamp = new Date();
...
Variation 3:
This variation can be used when the value associated with the variables requires a asynchronous function call to be
extracted. In this case, the user should provide an async method refreshFunc
.
The refreshFunc
shall do whatever is necessary to fetch the most up to date version of the variable value, and
call the callback
function when the data is ready.
The callback
function follow the standard callback function signature:
- the first argument shall be null or Error, depending of the outcome of the fetch operation,
- the second argument shall be a DataValue with the new UAVariable Value, a StatusCode, and time stamps.
Optionally, it is possible to pass a sourceTimestamp and a sourcePicoseconds value as a third and fourth arguments of the callback. When sourceTimestamp and sourcePicoseconds are missing, the system will set their default value to the current time..
...
var options = {
refreshFunc : function(callback) {
... do_some_async_stuff_to_get_the_new_variable_value
var dataValue = new DataValue({
value: new Variant({...}),
statusCode: StatusCodes.Good,
sourceTimestamp: new Date()
});
callback(null,dataValue);
}
};
...
variable.bindVariable(nodeId,options):
...
Providing write access to the underlying value
Variation1 - provide a simple synchronous set function
Notes
to do : explain return StatusCodes.GoodCompletesAsynchronously;
isReadable
-
context
Parameters:
-
context
SesionContext
Returns:
isUserReadable
-
context
Parameters:
-
context
SesionContext
Returns:
readAttribute
-
context
-
attributeId
-
indexRange
-
dataEncoding
Parameters:
-
context
SessionContext -
attributeId
AttributeIdsthe attributeId to read
-
indexRange
NumericRange | null -
dataEncoding
String
Returns:
readValue
-
[context]
-
[indexRange]
-
[dataEncoding]
Parameters:
-
[context]
SessionContext optional -
[indexRange]
NumericRange | Null optional -
[dataEncoding]
String optional
Returns:
from OPC.UA.Spec 1.02 part 4 5.10.2.4 StatusCodes Table 51 defines values for the operation level statusCode contained in the DataValue structure of each values element. Common StatusCodes are defined in Table 166. Table 51 Read Operation Level Result Codes Symbolic Id Description BadNodeIdInvalid The syntax of the node id is not valid. BadNodeIdUnknown The node id refers to a node that does not exist in the server address space. BadAttributeIdInvalid Bad_AttributeIdInvalid The attribute is not supported for the specified node. BadIndexRangeInvalid The syntax of the index range parameter is invalid. BadIndexRangeNoData No data exists within the range of indexes specified. BadDataEncodingInvalid The data encoding is invalid. This result is used if no dataEncoding can be applied because an Attribute other than Value was requested or the DataType of the Value Attribute is not a subtype of the Structure DataType. BadDataEncodingUnsupported The server does not support the requested data encoding for the node. This result is used if a dataEncoding can be applied but the passed data encoding is not known to the Server. BadNotReadable The access level does not allow reading or subscribing to the Node. BadUserAccessDenied User does not have permission to perform the requested operation. (table 165)
readValueAsync
-
context
-
callback
Parameters:
-
context
SessionContext -
callback
Function-
err
Null | Error -
dataValue
DataValue | Nullthe value read
-
setValueFromSource
-
variant
-
[statusCode = StatusCodes.Good]
-
[sourceTimestamp= Now]
setValueFromSource is used to let the device sets the variable values this method also records the current time as sourceTimestamp and serverTimestamp. the method broadcasts an "value_changed" event
Parameters:
-
variant
Variant -
[statusCode = StatusCodes.Good]
StatusCode optional -
[sourceTimestamp= Now]
Object optional
touchValue
touch the source timestamp of a Variable and cascade up the change
to the parent variable if any.
-
[optionalNow=null]
Parameters:
-
[optionalNow=null]
Object optional-
timestamp
Date -
picoseconds
Number
-
writeAttribute
-
context
-
writeValue
-
callback
Parameters:
-
context
SessionContext -
writeValue
WriteValue -
callback
Function-
err
Error | Null -
statusCode
StatusCode
-
writeEnumValue
-
value
Parameters:
-
value
String | Number
writeValue
-
context
-
dataValue
-
[indexRange]
-
callback
Parameters:
-
context
SessionContext -
dataValue
DataValue -
[indexRange]
NumericRange optional -
callback
Function-
err
Error | Null -
statusCode
StatusCode
-
Properties
accessLevel
number
The AccessLevel Attribute is used to indicate how the Value of a Variable can be accessed
(read/write) and if it contains current and/or historic data. The AccessLevel does not take
any user access rights into account, i.e. although the Variable is writable this may be
restricted to a certain user / user group. The AccessLevelType is defined in 8.57.
arrayDimensions
number UInt32
The Attribute is intended to describe the capability of the Variable, not the current size.
The number of elements shall be equal to the value of the ValueRank Attribute. Shall be null
if ValueRank ? 0.
A value of 0 for an individual dimension indicates that the dimension has a variable length.
For example, if a Variable is defined by the following C array:
Int32 myArray[346];
then this Variables DataType would point to an Int32, the Variable�s ValueRank has the
value 1 and the ArrayDimensions is an array with one entry having the value 346.
Note that the maximum length of an array transferred on the wire is 2147483647 (max Int32)
and a multidimentional array is encoded as a one dimensional array.
This Attribute specifies the length of each dimension for an array value. T
historizing
Boolean
This differs from the AccessLevel Attribute which identifies if the
Variable has any historical data. A value of TRUE indicates that the Server is actively
collecting data. A value of FALSE indicates the Server is not actively collecting data.
Default value is FALSE.
The Historizing Attribute indicates whether the Server is actively collecting data for the history of the Variable.
minimumSamplingInterval
number Optional
It specifies (in milliseconds) how fast the Server can reasonably sample the value
for changes (see Part 4 for a detailed description of sampling interval).
A MinimumSamplingInterval of 0 indicates that the Server is to monitor the item continuously.
A MinimumSamplingInterval of -1 means indeterminate.
The MinimumSamplingInterval Attribute indicates how 'current' the Value of the Variable will be kept.