How do I correctly assign project tags to JS Object?

How do I correctly assign project tags to JS Object?
none 0.0 0
  • HMI Model: cMT-FHDX-820
  • EasyBuilder Pro Version: 6.10.01.422

Hi everyone,

I’m currently working on customizing a chart using JavaScript, based on one of the official Weintek templates.
Template - Tutorial: Chart.js Demo - JS Action/Object SDK

I’m trying to dynamically link Weintek variables to populate the chart, but I’m running into an issue where the values being displayed are static/fallback values — which leads me to think that the variables are not being linked correctly.

Here’s the function I’m using to get the variable data:

// Function to get data from Weintek variables
async function getWeintekData() {
    try {
        // Array of Weintek variable names for each chart bar
        const variableNames = [
            'SX_ES1', 'DX_ES1',
            'SX_ES2', 'DX_ES2',
            'SX_ES3', 'DX_ES3',
            'SX_ES4', 'DX_ES4',
            'SX_ES5', 'DX_ES5',
            'SX_ES6', 'DX_ES6',
            'SX_ES7', 'DX_ES7',
            'SX_ES8', 'DX_ES8'
        ];
        
        const values = [];
        for (const varName of variableNames) {
            const data = await driver.promises.getData(this.config[varName], 1);
            values.push(data.values[0]);
        }

        return values;
    } catch (error) {
        console.error("Error retrieving data:", error);
        // Return default values if something goes wrong
        return [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20];
    }
}

The issue is that I always see these fallback values (10, 20, ...), even though the variables exist and are correctly named.

It seems like the this.config[varName] part might not be resolving correctly. Could someone point me in the right direction on how to properly bind Weintek variables in this context? Or is there something I might be missing in the config object initialization?

Any help would be greatly appreciated!

Thanks in advance.

Hi @jackluz,

Thank you for contributing to our forum.
Could you also show us the Config tab of the JS object? The link issue may have originated here, as the function looks correct.

Here are some additional resources related to JS objects, if needed:
Use JS objects to transfer data to USB
Transfer data using JS object

Hi,
I’m connected to an S7-300 PLC, and I linked them as you can see in the image.
As a type, I tried both “subscription” and “Tags”

I also tried linking the minutes system variable, but that didn’t work either.
I also inserted numeric fields with the variables into the page to see if they were imported correctly, and from there I can see the PLC numbers.

Thanks for the guides, I’ll try reviewing the code.

Hi @jackluz ,

I have a couple of solutions for you to try.

First, within the config tab, change all the values from “subscriptions” to “address”. This is because the getData function you have set up is primarily for addresses.

image

Another possible solution I want you to try is saving const addr = this.config[varName]; to a variable outside the getData function instead of declaring it inside. This sometimes solves the issue.

Lastly, here is a working demo project I created using your code. I did add a setInterval function to grab the data every second for testing. You can view the results in the EB Pro Diagnoser, under the JS tab during a simulation: Demo Project