Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!self.subscription) {
// some server do not provide subscription support, do not treat this as an error.
return callback(null); // new Error("No subscription"));
}
const itemToMonitor = { // ReadValueId
nodeId: proxyObject.nodeId,
attributeId: AttributeIds.Value
};
const monitoringParameters = { // MonitoringParameters
samplingInterval: 0, /* event-based */
discardOldest: true,
queueSize: 10
};
const requestedParameters = read_service.TimestampsToReturn.Both;
const monitoredItem = self.subscription.monitor(itemToMonitor, monitoringParameters, requestedParameters, callback);
// console.log("xxxxxx installing monitored Item",monitoredItem.itemToMonitor.nodeId.toString(),monitoredItem.itemToMonitor.attributeId);
//xx proxyObject.monitoredItem = monitoredItem;
Object.defineProperty(proxyObject, "__monitoredItem", {value: monitoredItem, enumerable: false});
proxyObject.__monitoredItem.on("changed", function (dataValue) {
proxyObject.dataValue = dataValue;
proxyObject.emit("value_changed", dataValue);
//xx console.log("xxx Value Changed ".red,proxyObject.nodeId.toString() , proxyObject.browseName,proxyObject.dataValue.toString());
});
};
if (!self.subscription) {
// some server do not provide subscription support, do not treat this as an error.
return callback(null); // new Error("No subscription"));
}
const itemToMonitor = { // ReadValueId
nodeId: proxyObject.nodeId,
attributeId: AttributeIds.Executable
};
const monitoringParameters = { // MonitoringParameters
samplingInterval: 0, /* event-based */
discardOldest: true,
queueSize: 10
};
const requestedParameters = read_service.TimestampsToReturn.None;
const monitoredItem = self.subscription.monitor(itemToMonitor, monitoringParameters, requestedParameters, callback);
Object.defineProperty(proxyObject, "__monitoredItem_execution_flag", {value: monitoredItem, enumerable: false});
proxyObject.__monitoredItem_execution_flag.on("changed", function (dataValue) {
proxyObject.executableFlag = dataValue.value.value;
//xx console.log(" execution flag = ", proxyObject.executableFlag , proxyObject.browseName , proxyObject.nodeId.toString());
//xx proxyObject.emit("execution_flag_changed",proxyObject.executableFlag);
});
};
attributeId: read_service.AttributeIds.Value,
indexRange: null,
dataEncoding: {namespaceIndex: 0, name: null}
});
} else {
assert(node instanceof Object);
return new read_service.ReadValueId(node);
}
}
const nodesToRead = nodes.map(coerceReadValueId);
const request = new read_service.ReadRequest({
nodesToRead: nodesToRead,
timestampsToReturn: read_service.TimestampsToReturn.Neither
});
assert(nodes.length === request.nodesToRead.length);
self.performMessageTransaction(request, function (err, response) {
/* istanbul ignore next */
if (err) {
return callback(err, response);
}
if (response.responseHeader.serviceResult.isNot(StatusCodes.Good)) {
return callback(new Error(response.responseHeader.serviceResult.toString()));
}
assert(response instanceof read_service.ReadResponse);
assert(nodes.length === response.results.length);
continuationPoint: null
});
}
const ReadRawModifiedDetails = new historizing_service.ReadRawModifiedDetails({
isReadModified: false,
startTime: start,
endTime: end,
numValuesPerNode: 0,
returnBounds: true
});
const request = new historizing_service.HistoryReadRequest({
nodesToRead: nodesToRead,
historyReadDetails: ReadRawModifiedDetails,
timestampsToReturn: read_service.TimestampsToReturn.Both,
releaseContinuationPoints: false
});
assert(nodes.length === request.nodesToRead.length);
self.performMessageTransaction(request, function (err, response) {
if (err) {
return callback(err, response);
}
if (response.responseHeader.serviceResult.isNot(StatusCodes.Good)) {
return callback(new Error(response.responseHeader.serviceResult.toString()));
}
assert(response instanceof historizing_service.HistoryReadResponse);
assert(nodes.length === response.results.length);
const NodeId = require("node-opcua-nodeid").NodeId;
const resolveNodeId = require("node-opcua-nodeid").resolveNodeId;
const makeNodeId = require("node-opcua-nodeid").makeNodeId;
const NodeIdType = require("node-opcua-nodeid").NodeIdType;
const NumericRange = require("node-opcua-numeric-range").NumericRange;
const BrowseDirection = require("node-opcua-data-model").BrowseDirection;
const BrowseResult = require("node-opcua-service-browse").BrowseResult;
const ReadRequest = require("node-opcua-service-read").ReadRequest;
require("node-opcua-common");
const read_service = require("node-opcua-service-read");
const AttributeIds = require("node-opcua-data-model").AttributeIds;
const TimestampsToReturn = read_service.TimestampsToReturn;
const UAVariable = require("node-opcua-address-space").UAVariable;
const ServerSidePublishEngine = require("./server_publish_engine").ServerSidePublishEngine;
const historizing_service = require("node-opcua-service-history");
const HistoryReadRequest = historizing_service.HistoryReadRequest;
const HistoryReadDetails = historizing_service.HistoryReadDetails;
const HistoryReadResult = historizing_service.HistoryReadResult;
const DataValue = require("node-opcua-data-value").DataValue;
const Variant = require("node-opcua-variant").Variant;
const DataType = require("node-opcua-variant").DataType;
const VariantArrayType = require("node-opcua-variant").VariantArrayType;
const isValidVariant = require("node-opcua-variant").isValidVariant;
"use strict";
/**
* @module opcua.client
*/
const util = require("util");
const _ = require("underscore");
const EventEmitter = require("events").EventEmitter;
const subscription_service = require("node-opcua-service-subscription");
const read_service = require("node-opcua-service-read");
const StatusCodes = require("node-opcua-status-code").StatusCodes;
const assert = require("node-opcua-assert").assert;
const TimestampsToReturn = read_service.TimestampsToReturn;
const AttributeIds = require("node-opcua-data-model").AttributeIds;
const resolveNodeId = require("node-opcua-nodeid").resolveNodeId;
const ObjectTypeIds = require("node-opcua-constants").ObjectTypeIds;
const ModifyMonitoredItemsRequest = subscription_service.ModifyMonitoredItemsRequest;
const MonitoredItemModifyRequest = subscription_service.MonitoredItemModifyRequest;
function ClientMonitoredItemBase(subscription, itemToMonitor, monitoringParameters) {
assert(subscription.constructor.name === "ClientSubscription");
const self = this;
self.itemToMonitor = new read_service.ReadValueId(itemToMonitor);
self.monitoringParameters = new subscription_service.MonitoringParameters(monitoringParameters);
self.subscription = subscription;
self.monitoringMode = subscription_service.MonitoringMode.Reporting;
const EventEmitter = require("events").EventEmitter;
const utils = require("node-opcua-utils");
const subscription_service = require("node-opcua-service-subscription");
const ClientSession = require("../src/client_session").ClientSession;
const ClientMonitoredItem = require("../src/client_monitored_item").ClientMonitoredItem;
const StatusCodes = require("node-opcua-status-code").StatusCodes;
const resolveNodeId = require("node-opcua-nodeid").resolveNodeId;
const AttributeIds = require("node-opcua-data-model").AttributeIds;
const TimestampsToReturn = require("node-opcua-service-read").TimestampsToReturn;
const debugLog = require("node-opcua-debug").make_debugLog(__filename);
const doDebug = require("node-opcua-debug").checkDebugFlag(__filename);
/**
* a object to manage a subscription on the client side.
*
* @class ClientSubscription
* @extends EventEmitter
* events:
* "started", callback(subscriptionId) : the subscription has been initiated
* "terminated" : the subscription has been deleted
* "error", : the subscription has received an error
* "keepalive", : the subscription has received a keep alive message from the server
* "received_notifications", : the subscription has received one or more notification
const browse_service = require("node-opcua-service-browse");
const read_service = require("node-opcua-service-read");
const write_service = require("node-opcua-service-write");
const historizing_service = require("node-opcua-service-history");
const subscription_service = require("node-opcua-service-subscription");
const translate_service = require("node-opcua-service-translate-browse-path");
const session_service = require("node-opcua-service-session");
const register_node_service = require("node-opcua-service-register-node");
const call_service = require("node-opcua-service-call");
const endpoints_service = require("node-opcua-service-endpoints");
const query_service = require("node-opcua-service-query");
const ServerState = require("node-opcua-common").ServerState;
const EndpointDescription = endpoints_service.EndpointDescription;
const TimestampsToReturn = read_service.TimestampsToReturn;
const ActivateSessionRequest = session_service.ActivateSessionRequest;
const ActivateSessionResponse = session_service.ActivateSessionResponse;
const CreateSessionRequest = session_service.CreateSessionRequest;
const CreateSessionResponse = session_service.CreateSessionResponse;
const CloseSessionRequest = session_service.CloseSessionRequest;
const CloseSessionResponse = session_service.CloseSessionResponse;
const DeleteMonitoredItemsRequest = subscription_service.DeleteMonitoredItemsRequest;
const DeleteMonitoredItemsResponse = subscription_service.DeleteMonitoredItemsResponse;
const RepublishRequest = subscription_service.RepublishRequest;
const RepublishResponse = subscription_service.RepublishResponse;
"use strict";
const util = require("util");
const _ = require("underscore");
const assert = require("node-opcua-assert").assert;
const read_service = require("node-opcua-service-read");
const ClientMonitoredItemBase = require("./client_monitored_item_base").ClientMonitoredItemBase;
const TimestampsToReturn = read_service.TimestampsToReturn;
/**
* ClientMonitoredItem
* @class ClientMonitoredItem
* @extends ClientMonitoredItemBase
*
* @param subscription {ClientSubscription}
* @param itemToMonitor {ReadValueId}
* @param itemToMonitor.nodeId {NodeId}
* @param itemToMonitor.attributeId {AttributeId}
*
* @param monitoringParameters {MonitoringParameters}
* @param timestampsToReturn {TimestampsToReturn}
* @constructor
*
* event:
const DataValue = require("node-opcua-data-value").DataValue;
const Variant = require("node-opcua-variant").Variant;
const StatusCodes = require("node-opcua-status-code").StatusCodes;
const NodeClass = require("node-opcua-data-model").NodeClass;
const AttributeIds = require("node-opcua-data-model").AttributeIds;
const BaseNode = require("node-opcua-address-space").BaseNode;
const sameDataValue = require("node-opcua-data-value").sameDataValue;
const sameVariant = require("node-opcua-variant").sameVariant;
const isValidVariant = require("node-opcua-variant").isValidVariant;
const MonitoringMode = subscription_service.MonitoringMode;
const MonitoringParameters = subscription_service.MonitoringParameters;
const MonitoredItemModifyResult = subscription_service.MonitoredItemModifyResult;
const TimestampsToReturn = read_service.TimestampsToReturn;
const EventFilter = require("node-opcua-service-filter").EventFilter;
const apply_timestamps = require("node-opcua-data-value").apply_timestamps;
const UAVariable = require("node-opcua-address-space").UAVariable;
const defaultItemToMonitor = {indexRange: null, attributeId: read_service.AttributeIds.Value};
const SessionContext = require("node-opcua-address-space").SessionContext;
const NumericRange = require("node-opcua-numeric-range").NumericRange;
const debugLog = require("node-opcua-debug").make_debugLog(__filename);
const doDebug = require("node-opcua-debug").checkDebugFlag(__filename);
function _adjust_sampling_interval(samplingInterval,node_minimumSamplingInterval) {