Device disable/delete - set all Tags to Bad Quality

I have a module thats based on the opc ua device example. My module creates tags and changes the quality of each tag while the device is running. When i disable or delete the device i want that all tags change Quality to Bad. I tried to set the Quality in the onShutdown method but it doesn't work. Any tips?

Can you share some code? What did you try in onShutdown?

I use this method while the device is running to set all my tags to bad Quality:

public  void setAllTagsBadQuality() {//setting all the tags to bad quality
        for (String tagName : monitoredVariableNames) {
            UaVariableNode existingNode = findTagByName(tagName);
            updateTagValue(existingNode, new StatusCode(StatusCodes.Bad_NotConnected));
        }
    }

This method sets the quality of all tags as it should, monitoredVariableNames just contains every tagName that got created during the execution. But when i call it in the onShutdown it doesn't set the tags in the designer:

  private void onShutdown() {
        euromapDataMonitor.setAllTagsBadQuality();
        subscriptionModel.shutdown();
        deviceContext.getGatewayContext()
            .getExecutionManager()
            .unRegister(EuromapDeviceType.TYPE_ID, deviceContext.getName());
    }

The euromapDataMonitor object gets initialized in the onStartup and ShutdownTask is set.

Try something like this:

context.getSubscriptionModel()
    .getDataItems(context.getName())
    .forEach(item -> item.setQuality(new StatusCode(StatusCodes.Uncertain_LastUsableValue)));

During shutdown you shut down the SubscriptionModel (necessarily), which is the thing that's actually reading values from your Nodes and setting values on the subscription items. So instead, you need to set the value/quality directly.

edit: just sneakily updated the code, it was copied from an old driver at first; wrong API.

1 Like

Big thanks! it worked.
Kind regards Sebastian