I'm adding the ability to add pens to a popup trend ad-hoc from an overview page, but noticed that there are critical functions missing from the shared
library in order to actually do this properly.
To add a pen to a chart, you need:
- history provider
- tag provider
- tag provider gateway name
- tag path
Before you say that you can just read the tag provider from the tag and the gateway name from the [system] tags, you can't do this in a multi-gateway network. Remote tag provider names are not guaranteed to be the same as the name on the original gateway, and gateway name is just not available to retrieve at all, using off the shelf methods.
So we need methods to get the tag provider name and gateway that the tag provider exists on.
As a work around, i'm going down the rabbit hole of unsupported API methods to do this...
2 Likes
E.g. using a super dodgy query on the internal db...
tagPath = 'Tag/Path'
# get the tag provider in the local gateway from the config in case the tag provider wasn't provided in the path
tagProvider = system.tag.getConfiguration(tagPath)[0]['path'].split(']')[-1]
context = system.util.getContext()
session = context.getPersistenceInterface().getSession()
try:
query = """
SELECT
COALESCE(gtps.PROVIDERNAME, tps.NAME) as tag_provider,
gtps.HISTORYDRIVERNAME as gateway_name
FROM
TAGPROVIDERSETTINGS tps
LEFT JOIN GANTAGPROVIDERSETTINGS gtps ON gtps.PROFILEID = tps.TAGPROVIDERSETTINGS_ID
WHERE tps.name = '{}'
""".format(tagProvider)
rt = session.rawQueryMaps(query, True, []) # sql, flush, params
finally:
session.close()
rt = rt[0]
histProvider, gatewayName = [qval.value for qval in system.tag.readBlocking([
'{}.historyProvider'.format(tagPath),
'[System]Gateway/SystemName'])]
gatewayName = gatewayName or rt['gateway_name']
tagProvider = rt['tag_provider']
tagPath = tagPath.split(']')[-1]
system.perspective.print('histProvider: {}'.format(histProvider))
system.perspective.print('gatewayName: {}'.format(gatewayName))
system.perspective.print('tagProvider: {}'.format(tagProvider))
system.perspective.print('tagPath: {}'.format(tagPath))
1 Like
What display component are you using? Within Perspective, both the PowerChart and TimeSeriesChart permit passing the [full]tag/path to the view. This has been useful, because it allows Ignition's Realtime Tag Provider Settings to determine where to grab the historical data from (via a database query, or from the remote gateway). So, the same view can be used on a full Ignition gateway (querying database) as on the Edge gateway (used as a local HMI, where it queries internal SQLite).
As an aside... I agree that there should be a more straightforward way to get data from the internal db. 'Hosing' of the gateway is possible, if not likely, using the method you outlined above... but I still do it.