Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "node-opcua in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'node-opcua' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

// Add a mechanism to dismiss session early
    const obj = namespace.addObject({ 
        nodeId: "ns=1;s=MyObject",
        browseName: "MyObject" ,
        organizedBy: myDevices,
    });

    const simulateNetworkOutage = namespace.addMethod(obj, {
        browseName: "SimulateNetworkOutage",
        executable: true,
        inputArguments: [
            {
                name: "outageDuration",
                description: {text: "specifies the number of miliseconds the Outage should be"},
                dataType: opcua.DataType.UInt32
            }
        ],
        nodeId: "ns=1;s=SimulateNetworkOutage",
        outputArguments: [],
        userExecutable: true,
    });

    async function simulateNetworkOutageFunc(
        /*this: UAMethod,*/ inputArguments/*: Variant[]*/, context/*: SessionContext*/, callback/*: MethodFunctorCallback*/
    ){
        const outageDuration = inputArguments[0].value;
        console.log("Simulating Server Outage for ", outageDuration, "ms");
        await server.suspendEndPoints();
        setTimeout(async () => {
            await server.resumeEndPoints();
            console.log("Server Outage is now resolved ");
async function main() {
    try {

        const server = new OPCUAServer({
            registerServerMethod: RegisterServerMethod.LDS
        });

        await server.initialize();

        server.on("request", (request: Request) => {

            console.log(request.constructor.name, request.requestHeader.requestHandle);

            // you can either check the instance of the request object directl
            if (request instanceof BrowseRequest) {
                console.log("BrowseRequest.requestedMaxReferencesPerNode=", request.requestedMaxReferencesPerNode);
            } else if (request instanceof ActivateSessionRequest) {
                console.log(request.toString());
            }
async function main() {

    try {

        const server = new OPCUAServer({
            nodeset_filename: [
                nodesets.standard_nodeset_file
            ]
        });

        await server.initialize();

        // post-initialize
        const addressSpace = server.engine.addressSpace!;

        const object = installObjectWithMethod(addressSpace);

        console.log("object = ", object.toString());
        await callMethodFromServer(addressSpace, object.nodeId);

        await server.start();
function build_server_with_temperature_device(options, done) {

    assert(_.isFunction(done, "expecting a callback function"));
    assert(typeof opcua.nodesets.standard_nodeset_file === "string");

    //xx console.log("xxx building server with temperature device");

    // use mini_nodeset_filename for speed up if not otherwise specified
    options.nodeset_filename = options.nodeset_filename ||
        [
            opcua.nodesets.standard_nodeset_file
        ];

    options.userManager = userManager;

    const server = new OPCUAServer(options);
    // we will connect to first server end point

    server.on("session_closed", function (session, reason) {
        //xx console.log(" server_with_temperature_device has closed a session :",reason);
        //xx console.log(chalk.cyan("              session name: "),session.sessionName.toString());
    });

    server.on("post_initialize", function () {

        const addressSpace = server.engine.addressSpace;
function build_server_with_temperature_device(options, done) {

    assert(_.isFunction(done, "expecting a callback function"));
    assert(typeof opcua.nodesets.standard_nodeset_file === "string");

    //xx console.log("xxx building server with temperature device");

    // use mini_nodeset_filename for speed up if not otherwise specified
    options.nodeset_filename = options.nodeset_filename ||
        [
            opcua.nodesets.standard_nodeset_file
        ];

    options.userManager = userManager;

    const server = new OPCUAServer(options);
    // we will connect to first server end point

    server.on("session_closed", function (session, reason) {
        //xx console.log(" server_with_temperature_device has closed a session :",reason);
server._on_TransferSubscriptionsRequest =(message /* :Message*/, channel/*: ServerSecureChannelLayer*/) => {
        const response = new opcua.TransferSubscriptionsResponse({
            responseHeader: { serviceResult: opcua.StatusCodes.BadNotImplemented }
        });
        return channel.send_response("MSG", response, message);
    }
server.on("post_initialize", function () {

    const addressSpace = server.engine.addressSpace;

    const rootFolder = addressSpace.findNode("RootFolder");

    const namespace = addressSpace.getOwnNamespace();

    const myDevices = namespace.addFolder(rootFolder.objects, {browseName: "MyDevices"});

    const variable0 = namespace.addVariable({
        organizedBy: myDevices,
        browseName: "Counter",
        nodeId: "ns=1;s=MyCounter",
        dataType: "Int32",
        value: new opcua.Variant({dataType: opcua.DataType.Int32, value: 1000.0})
    });

    server._on_TransferSubscriptionsRequest =(message /* :Message*/, channel/*: ServerSecureChannelLayer*/) => {
        const response = new opcua.TransferSubscriptionsResponse({
            responseHeader: { serviceResult: opcua.StatusCodes.BadNotImplemented }
        });
        return channel.send_response("MSG", response, message);
    }

});
server.on("post_initialize", function () {

    const addressSpace = server.engine.addressSpace;

    const rootFolder = addressSpace.findNode("RootFolder");

    const namespace = addressSpace.getOwnNamespace();

    const myDevices = namespace.addFolder(rootFolder.objects, {browseName: "MyDevices"});

    const variable0 = namespace.addVariable({
        organizedBy: myDevices,
        browseName: "Counter",
        nodeId: "ns=1;s=MyCounter",
        dataType: "Int32",
        value: new opcua.Variant({dataType: opcua.DataType.Int32, value: 1000.0})
    });

    // Add a mechanism to dismiss session early
    const obj = namespace.addObject({ 
        nodeId: "ns=1;s=MyObject",
        browseName: "MyObject" ,
        organizedBy: myDevices,
    });

    const simulateNetworkOutage = namespace.addMethod(obj, {
        browseName: "SimulateNetworkOutage",
        executable: true,
        inputArguments: [
            {
                name: "outageDuration",
                description: {text: "specifies the number of miliseconds the Outage should be"},
//xx    assert(parentNode instanceof opcua.BaseNode);

    const addressSpace = parentNode.addressSpace;
    const namespace = addressSpace.getOwnNamespace();

    // add a UAAnalogItem
    namespace.addAnalogDataItem({
        componentOf: parentNode,
        nodeId: "s=TemperatureAnalogItem",
        browseName: "TemperatureAnalogItem",
        definition: "(tempA -25) + tempB",
        valuePrecision: 0.5,
        engineeringUnitsRange: {low: 100, high: 200},
        instrumentRange: {low: -100, high: +200},
        engineeringUnits: opcua.standardUnits.degree_celsius,
        dataType: "Double",
        value: {
            get: function () {
                return new Variant({dataType: DataType.Double, value: Math.random() + 19.0});
            }
        }
    });

}
});
    
        app.use(express.static(__dirname + '/'));
    
        const io =socketIO.listen(app.listen(port));
    
        io.sockets.on('connection', function (socket) {
        });
    
        console.log("Listening on port " + port);
        console.log("visit http://localhost:" + port);
        // --------------------------------------------------------
    
        const itemToMonitor = {
            nodeId: nodeIdToMonitor,
            attributeId: AttributeIds.Value
        };
        const parameters = {
            samplingInterval: 100,
            discardOldest: true,
            queueSize: 100
        };
        const monitoredItem = await subscription.monitor(itemToMonitor, parameters, TimestampsToReturn.Both);

        monitoredItem.on("changed", (dataValue) => {
            console.log(dataValue.value.toString());
            io.sockets.emit('message', {
                value: dataValue.value.value,
                timestamp: dataValue.serverTimestamp,
                nodeId: nodeIdToMonitor,
                browseName: "Temperature"
            });

Is your System Free of Underlying Vulnerabilities?
Find Out Now