Hello, we use the Gateway for reading, writing and acknowledging some tags. This was working in Ignition 7.9.9. flawlessly. After installing 8.0.0 the module did not work anymore.
After installing JDK 11, Eclipse was upgraded so it can run with JDK 11. After downloading the 8.0 java samples the project poms were modified accordingly. Next an update of Maven in Eclipse was done and the repositories updated nicely to version 8.0. After setting the target java version to 11 the project rebuilt with less than 10 errors.
These 10 errors all have to do with the new Ignition 8.0 api functions that uses the Futures threading mechanism.
Searching for an example in the 8.0 samples did not give any results.
Can somebody supply an example in java for Ignition 8 for reading, writing and acknowledging tags in the Gateway.
Thanx.
I thought we had some 8.0 tag API examples in the SDK docs, but I can’t find anything. I will see if we can get some examples into the documentation. In the meantime, which methods won’t compile? We should be able to answer those pretty quickly.
Edit: the published javadocs might be able to help also. Maybe start here: http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.1/com/inductiveautomation/ignition/gateway/tags/model/GatewayTagManager.html
Thanks for your reply.
Previously the “scripting-rpc-example” from 7.9.9 was used as a base.
With usage of the JavaDocs the following solution for the tag read function was created:
protected Object readTag(GatewayContext gatewayContext, TagPath tagPath) throws FaultException{
GatewayTagManager tagManager = gatewayContext.getTagManager();
java.util.List<TagPath> tagPaths = Arrays.asList(tagPath);
CompletableFuture<List<QualifiedValue>> future = tagManager.readAsync(tagPaths);
Object tagValue;
try
{
List<QualifiedValue> results = future.get();
QualifiedValue qualifiedValue = results.get(0);
if (qualifiedValue.getQuality()!=QualityCode.Good) {
throw new FaultException("Tag value can not be read:\n'" + tagPath,
FaultCode.FaultCode_ReadTagException);
// logger.warn(result);
}
tagValue = qualifiedValue.getValue();
}
catch(ExecutionException ee)
{
throw new FaultException("Tag value can not be read(ExecutionException):\n'" + tagPath,
FaultCode.FaultCode_ReadTagException);
}
catch( InterruptedException ie)
{
throw new FaultException("Tag value can not be read (InterruptedException):\n'" + tagPath,
FaultCode.FaultCode_ReadTagException);
}
return tagValue;
}
The version of Ignition that is specified in the pom.xml is “8.0.1”
The problem for the write tag function is that following code will compile and the module can be installed:
protected String writeTagValue(GatewayContext gatewayContext, TagPath tagPath, String tagValue) throws FaultException {
java.util.List<TagPath> tagPathsList = Arrays.asList(tagPath);
java.util.List<QualifiedValue> qualifiedValuesList = Arrays.asList(new BasicQualifiedValue(tagWaarde));
com.inductiveautomation.ignition.gateway.sqltags.model.BasicWriteRequest.BasicWriteRequest<TagPath>(TagPath
GatewayTagManager tagManager = gatewayContext.getTagManager();
TagProvider defaultTagProvider = tagManager.getTagProvider("default");
SecurityContext securityContext = SecurityContext.gatewayContext();
CompletableFuture<List<QualityCode>> future = defaultTagProvider.writeAsync(tagPathsList, qualifiedValuesList, securityContext);
Object result;
try
{
List<QualityCode> results = future.get();
QualityCode qualityCode = results.get(0);
if (QualityCode.getQualityFor(qualityCode.getCode())!=QualityCode.Good) {
throw new FaultException("Tag can not be written to:\n'" + tagPath, FaultCode.FaultCode_WriteTagException);
}
}
catch(ExecutionException ee)
{
throw new FaultException("Tag can not be written(ExecutionException):\n'" + tagPath,
FaultCode.FaultCode_WriteTagException);
}
catch( InterruptedException ie)
{
throw new FaultException("Tag value can not be written(InterruptedException):\n'" + tagPath,FaultCode.FaultCode_WriteTagException);
}
return "Succes";
}
There seems to be not any problem with this code but a peculiarity is the SecurityContext!
In Ignition 8.0.0 one would use SecurityContext.gatewayContext()
In 8.0.1 one would use SecurityContext.emptyContext()
The first, codecompletion suggests SecurityContext.gatewayContext(), compiles correctly with 8.0.1 in the pom.xml, however it is an 8.0.0 method, but gives the following error on execution: java.lang.NoSuchMethodError: com.inductiveautomation.ignition.common.tags.model.SecurityContext.gatewayContext()Lcom/inductiveautomation/ignition/common/tags/model/SecurityContext;
Now when “open declaration” is choosen from the context menu on the “import com.inductiveautomation.ignition.common.tags.model.SecurityContext;” this turns out to be the version with gatewayContext() what is a 8.0.0 functions but it lays in C:\Users\theUserName.m2\repository\com\inductiveautomation\ignition\common\8.0.1-SNAPSHOT\common-8.0.1-SNAPSHOT.jar.
There appears to be a difference between JavaDoc 8.0.1. and common-8.0.1-SNAPSHOT.jar.
In the install log of Ignition the following lines were found:
Unpacking C:\Program Files\Inductive Automation\Ignition\lib\core\gateway\simple-orm-8.0.2-SNAPSHOT.jar
Unpacking C:\Program Files\Inductive Automation\Ignition\lib\core\designer\designer-8.0.2-SNAPSHOT.jar
Unpacking C:\Program Files\Inductive Automation\Ignition\lib\core\client\client-api-8.0.2-SNAPSHOT.jar
Unpacking C:\Program Files\Inductive Automation\Ignition\lib\core\client\active-query-builder-8.0.2-SNAPSHOT.jar
Unpacking C:\Program Files\Inductive Automation\Ignition\lib\core\gateway\gateway-api-8.0.2-SNAPSHOT.jar
Unpacking C:\Program Files\Inductive Automation\Ignition\lib\core\gateway\gateway-8.0.2-SNAPSHOT.jar
Unpacking C:\Program Files\Inductive Automation\Ignition\lib\core\gateway\metro-8.0.2-SNAPSHOT.jar
However when in the pom.xml the 8.0.2 is placed the above mentioned SNAPSHOT generate the following errors: Missing artifact com.inductiveautomation.ignitionsdk:client-api:pom:8.0.2-SNAPSHOT
Can someone explain this, fix this or have a workaround ?
Thanks.
It looks like you already figured out the javadocs, but we just published some tag API examples for anyone who stumbles across this thread later. They are here
The SecurityContext did change for 8.0.1, and SecurityContext.emptyContext() should be the correct method to use in your case. Also, we generally don’t publish SNAPSHOT SDK jars before release. You should be able to use the 8.0.1 jar references in the pom.xml, correct? I would also recommend using a 8.0.1 Ignition installation, just to ensure that the SDK jars are completely in sync with the Ignition installation.
Dear mgross,
Thanks for the example code. The example code for reading and writing looks very similar to ours and as such will not work.
This is also done on a freshly installed windows 10 machine with Ignition 8.0.1, Java 11 and Eclipse 4.11.0 as adviced in your post.
The problem is still that in the provided common-8.0.1-SNAPSHOT.jar not the needed SecurityContext.emptyContext() can be found but SecurityContext.gatewayContext(). You can see in the picture what Eclipse found:
In the other picture you can see the properties of this file on disk with a timestamp of today:
So there must be something wrong with common-8.0.1-SNAPSHOT.jar. For good measures the pom and other config files from maven are added as well:_remote.zip (2.7 KB)
Hopefully you can resolve this issue with the supplied information.
Regards,
Iwan.
The problem is solved!
Quite simply really by changing the line <ignition-sdk-version>${ignition-platform-version}-SNAPSHOT</ignition-sdk-version>
into <ignition-sdk-version>${ignition-platform-version}</ignition-sdk-version>
in the main project pom.xml.
Next, after starting “clean” in Eclipse, maven started downloading the 8.0.1 version of the jars.
Now the compiler gave an error at SecurityContext.gatewayContext() and codecompletion suggested SecurityContext.emptyContext(). Next the project was build, signed, sealed and delivered to the server and both reading and writing tags now works. Next “acknowledging” is on the agenda.
Thanks for the responses.