How to use node-opcua-client - 10 common examples

To help you get started, we’ve selected a few node-opcua-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / playground / sample1.ts View on Github external
for (const reference of result.references!) {
            console.log(reference.toString());
        }
        const registeredNodes = await session.registerNodes(["ns=1;s=FanSpeed", "ns=1;s=PumpSpeed"]);

        const fanSpeedId = registeredNodes[0].toString();
        const pumpSpeedId = registeredNodes[1].toString();

        console.log("registered Node", fanSpeedId);
        console.log("registered Node", pumpSpeedId);

        const value = await session.read({ nodeId: fanSpeedId, attributeId: AttributeIds.Value });
        console.log(`FanSpeed ${value.toString()}`);

        const value2 = await session.read({ nodeId: pumpSpeedId, attributeId: AttributeIds.Value });
        console.log(`PumpSpeed ${value2.toString()}`);

        await client.disconnect();

    } catch (e) {
        // Deal with the fact the chain failed

        console.log(chalk.red("Error !"), e);
        process.exit(-1);
    }
})();
github node-opcua / node-opcua / packages / playground / sample1.ts View on Github external
const result = await session.browse({
            nodeId: "i=2558"
        });

        for (const reference of result.references!) {
            console.log(reference.toString());
        }
        const registeredNodes = await session.registerNodes(["ns=1;s=FanSpeed", "ns=1;s=PumpSpeed"]);

        const fanSpeedId = registeredNodes[0].toString();
        const pumpSpeedId = registeredNodes[1].toString();

        console.log("registered Node", fanSpeedId);
        console.log("registered Node", pumpSpeedId);

        const value = await session.read({ nodeId: fanSpeedId, attributeId: AttributeIds.Value });
        console.log(`FanSpeed ${value.toString()}`);

        const value2 = await session.read({ nodeId: pumpSpeedId, attributeId: AttributeIds.Value });
        console.log(`PumpSpeed ${value2.toString()}`);

        await client.disconnect();

    } catch (e) {
        // Deal with the fact the chain failed

        console.log(chalk.red("Error !"), e);
        process.exit(-1);
    }
})();
github node-opcua / opcua-commander / lib / model / model.ts View on Github external
public monitor_item(treeItem: any) {

        if (!this.subscription) return;
        const node = treeItem.node;

        this.subscription.monitor({
            nodeId: node.nodeId,
            attributeId: AttributeIds.Value
            //, dataEncoding: { namespaceIndex: 0, name:null }
        }, {
            samplingInterval: 1000,
            discardOldest: true,
            queueSize: 100
        },
            TimestampsToReturn.Both,
            (err: Error | null, monitoredItem: ClientMonitoredItem) => {

                if (err) {
                    console.log("cannot create monitored item", err.message);
                    return;
                }

                node.monitoredItem = monitoredItem;

                const monitoredItemData = [node.browseName, node.nodeId.toString(), "Q"];

                this.monitoredItemsListData.push(monitoredItemData);

                this.emit("monitoredItemListUpdated", this.monitoredItemsListData);
                //   xxx                monitoredItemsList.setRows(monitoredItemsListData);
github node-opcua / node-opcua / packages / playground / sample1.ts View on Github external
Variant
} from "node-opcua-client";

const connectionStrategy: ConnectionStrategyOptions = {
    initialDelay: 1000,
    maxRetry: 1
};
const options: OPCUAClientOptions = {
    applicationName: "Hello",
    connectionStrategy,
    securityMode: MessageSecurityMode.None,
    // securityPolicy: SecurityPolicy.Basic256Sha256
    securityPolicy: SecurityPolicy.None
};

const client = OPCUAClient.create(options);

(async () => {
    try {

        console.log(" about to connect");
        await client.connect("opc.tcp://opcuademo.sterfive.com:26543");
        console.log("connected");

        client.on("backoff", () => {
            console.log("Backoff");
        });

        const session = await client.createSession({
            password: "password1",
            type: UserTokenType.UserName,
            userName: "user1",
github node-opcua / node-opcua / packages / playground / polling_client.ts View on Github external
initialDelay: 1000,
        maxDelay: 20000, // retry every 20 seconds
        maxRetry: 2, // maxRetry: 0xFFFFF // we need a large number here
    };

    const options: OPCUAClientOptions = {
        applicationName: "ClientBrowseNextDemo",
        connectionStrategy,
        endpoint_must_exist: false,
        keepSessionAlive: false,
        requestedSessionTimeout: 60000, // 1 minute
        securityMode: MessageSecurityMode.None,
        securityPolicy: SecurityPolicy.None,
    };

    const client = OPCUAClient.create(options);

    client.on("backoff", (retry: number, delay: number) => {
        console.log("Backoff ", retry, " next attempt in ", delay, "ms");
    });

    client.on("connection_lost", () => {
        console.log("Connection lost");
    });

    client.on("connection_reestablished", () => {
        console.log("Connection re-established");
    });

    client.on("connection_failed", () => {
        console.log("Connection failed");
    });
github node-opcua / node-opcua / packages / playground / client_with_custom_datatype.ts View on Github external
async function main() {

    const connectionStrategy: ConnectionStrategyOptions = {
        initialDelay: 1000,
        maxRetry: 1
    };
    const options: OPCUAClientOptions = {
        applicationName: "ClientWithCustomDataTypeSupport",
        connectionStrategy,
        securityMode: MessageSecurityMode.None,
        // securityPolicy: SecurityPolicy.Basic256Sha256
        securityPolicy: SecurityPolicy.None
    };

    const client = OPCUAClient.create(options);

    console.log(" about to connect");
    await client.connect("opc.tcp://" + os.hostname() + ":48010");
    console.log("connected");

    client.on("backoff", () => {
        console.log("Backoff");
    });

    const session = await client.createSession();

    const variableNodeID = "ns=2;s=Demo.WorkOrder.WorkOrderVariable";

    const dataValueDataType = await session.read({ nodeId: variableNodeID, attributeId: AttributeIds.DataType });
    console.log(" DataType =", dataValueDataType.value.value.toString());
    const dataTypeNodeId = dataValueDataType.value.value as NodeId;
github node-opcua / node-opcua / packages / playground / client_with_monitored_item_group_ts.ts View on Github external
initialDelay: 1000,
            maxDelay: 20000, // retry every 20 seconds
            maxRetry: 2 // maxRetry: 0xFFFFF // we need a large number here
        };

        const options: OPCUAClientOptions = {
            applicationName: "ClientBrowseNextDemo",
            connectionStrategy,
            endpoint_must_exist: false,
            keepSessionAlive: false,
            requestedSessionTimeout: 60000, // 1 minute
            securityMode: MessageSecurityMode.None,
            securityPolicy: SecurityPolicy.None
        };

        const client = OPCUAClient.create(options);

        client.on("backoff", (retry: number, delay: number) => {
            console.log("Backoff ", retry, " next attempt in ", delay, "ms");
        });

        client.on("connection_lost", () => {
            console.log("Connection lost");
        });

        client.on("connection_reestablished", () => {
            console.log("Connection re-established");
        });

        client.on("connection_failed", () => {
            console.log("Connection failed");
        });
github node-opcua / node-opcua / packages / playground / sample1.ts View on Github external
MessageSecurityMode,
    OPCUAClient,
    OPCUAClientOptions,
    SecurityPolicy,
    UserTokenType,
    Variant
} from "node-opcua-client";

const connectionStrategy: ConnectionStrategyOptions = {
    initialDelay: 1000,
    maxRetry: 1
};
const options: OPCUAClientOptions = {
    applicationName: "Hello",
    connectionStrategy,
    securityMode: MessageSecurityMode.None,
    // securityPolicy: SecurityPolicy.Basic256Sha256
    securityPolicy: SecurityPolicy.None
};

const client = OPCUAClient.create(options);

(async () => {
    try {

        console.log(" about to connect");
        await client.connect("opc.tcp://opcuademo.sterfive.com:26543");
        console.log("connected");

        client.on("backoff", () => {
            console.log("Backoff");
        });
github node-opcua / node-opcua / packages / playground / client_with_monitored_item_group_ts.ts View on Github external
try {

        const connectionStrategy: ConnectionStrategyOptions = {
            initialDelay: 1000,
            maxDelay: 20000, // retry every 20 seconds
            maxRetry: 2 // maxRetry: 0xFFFFF // we need a large number here
        };

        const options: OPCUAClientOptions = {
            applicationName: "ClientBrowseNextDemo",
            connectionStrategy,
            endpoint_must_exist: false,
            keepSessionAlive: false,
            requestedSessionTimeout: 60000, // 1 minute
            securityMode: MessageSecurityMode.None,
            securityPolicy: SecurityPolicy.None
        };

        const client = OPCUAClient.create(options);

        client.on("backoff", (retry: number, delay: number) => {
            console.log("Backoff ", retry, " next attempt in ", delay, "ms");
        });

        client.on("connection_lost", () => {
            console.log("Connection lost");
        });

        client.on("connection_reestablished", () => {
            console.log("Connection re-established");
        });
github node-opcua / node-opcua / packages / playground / polling_client.ts View on Github external
async function main() {

    const connectionStrategy: ConnectionStrategyOptions = {
        initialDelay: 1000,
        maxDelay: 20000, // retry every 20 seconds
        maxRetry: 2, // maxRetry: 0xFFFFF // we need a large number here
    };

    const options: OPCUAClientOptions = {
        applicationName: "ClientBrowseNextDemo",
        connectionStrategy,
        endpoint_must_exist: false,
        keepSessionAlive: false,
        requestedSessionTimeout: 60000, // 1 minute
        securityMode: MessageSecurityMode.None,
        securityPolicy: SecurityPolicy.None,
    };

    const client = OPCUAClient.create(options);

    client.on("backoff", (retry: number, delay: number) => {
        console.log("Backoff ", retry, " next attempt in ", delay, "ms");
    });

    client.on("connection_lost", () => {
        console.log("Connection lost");
    });

    client.on("connection_reestablished", () => {
        console.log("Connection re-established");
    });