Hi guys,
I’m trying to read values from some DB tags from my GatewayHook.
Here’s the code:
[code] // Test the SQLTag read
try {
List pathList = new ArrayList();
pathList.add(TagPathParser.parse("[default]Mode"));
List<TagReadResult> resultList;
resultList = context.getTagManager().read(pathList, context.getAuthenticationManager().getProfile("default").authenticate("admin", "password"), true);
System.out.println("tag value for [default]Mode: "+resultList.get(0).getValue().getValue());
}
catch (Exception e) {
System.out.println("Could not get tag value for [default]Mode:");
e.printStackTrace();
}[/code]
It’s giving me an error. The relevant part of the stacktrace below:
Could not get tag value for [default]Mode:
java.lang.NullPointerException
at com.inductiveautomation.ignition.gateway.sqltags.execution.AbstractTagDriver.read(AbstractTagDriver.java:445)
at com.inductiveautomation.ignition.gateway.sqltags.SQLTagsManagerImpl.read(SQLTagsManagerImpl.java:332)
at com.inductiveautomation.webservices.gateway.WebServicesGatewayHook.startup
Any ideas on why this might be happening? The “[default]Mode” tag does exist. Thanks!
It would appear here that the problem is more with your authentication procedure.
That NPE is coming from trying to check the authenticated user. Bad form on our part, shouldn’t error out. But, it appears that AuthenticationProfile.authenticate() will return null if the authentication fails.
Your parsing of “[default]Mode” is correct - in the gateway, you’re not under a project, so you won’t have a “default provider”, so leaving it off will only return an Config Error quality. Note, for others reading this, if it’s not immediately clear: the default provider that is created by the system is actually called “default”, so that’s what he’s referring to here.
Actually, there’s another problem, if the tag’s permission set happens to be null… which unfortunately can happen fairly easily. This has been fixed for 7.2.9.