Mapp View eventscript opcua(...).valueChanged not firing if started in typed async class

Hi Community

I’ve written typed classes for OPC variables because I want to be able to spot errors at compile time.
To do this, I’ve written a factory to handle the different variants (OPC-Bool/-Int/etc. & Session-Bool/-Real/etc.).
The class must be async because a data type match is checked at startup (runtime).

If ((typeof await myObject.getValue()) !== usedType) → Exception

Now, a very strange behavior:

  • The ValueChanged event integrated into the classes for the factory fires when I add an additional “opcua(myOpcPath).valueChanged(e => { DoStuff })”
  • If I comment out the additional “<opcUa_EventAction>”, no event fires anymore.

Interpretation:
The B&R JavaScript logic doesn’t recognize when an OPC variable needs to be “activated” at a (relatively low?) nesting depth. The OPC subscriptions are deactivated similarly to when leaving a page.

Example code:

(async () => {
    const opcPath = "::LineCtrl:stGui.BirdViewTransfStr";
    const logger = new Logger('debug');

    opcua(opcPath).valueChanged(e => { console.log('Something happens: ' + e.detail.newValue) } );

    const birdviewTransform = await ValueSourceFactory.fromOpcString(opcPath, logger);

    if (birdviewTransform) {
        logger.info('birdviewTransform was created and will be started.');
        birdviewTransform
            .subscribe(e => console.log('New value:', e))
            .start();
    } else {
        logger.error('ValueSource could not be created (type fault or no OPC variable)');
    }
})();

If the line

opcua(opcPath).valueChanged(e => { console.log('Shit happens: ' + e.detail.newValue) } );

is commented out, then

.subscribe(e => console.log('New value:', e))

will no longer work.

Message in console of browser

Error when trying to read the value of node “::LineCtrl:stGui.stConfig.Dummy”: server status: undefined
Subsequent actions are not executed!

This message appears when I test different architectural approaches. The call now looks like this: var birdviewTransform = ValueSourceFactory.fromOpcInt(opcua(opcPath), logger, opcPath);

It is no “async/await” but it looks like using “opcua(..)” in classes (“subsequent actions”) is not allowed by B&R, right? As I understand this message.

This is no typical OPC behavior. Could you offer further options for OPC (e.g. no “automatic closing subscriptions” functionalities which cannot be handled)?

If you do not need the WYSIWYG editor of mapp View and want to create your HMI with advanced web technologies, maybe mapp Connect would be a better solution for you.

Innovation 2025 : Mapp Connect, new mapp Premuim package for mapp View

1 Like