Writing tag values

Hi,

I am trying to write values (from my gateway module) in tags using the following write method of SQLTagsManager interface:

java.util.List write(java.util.List<WriteRequest> writes, AuthenticatedUser user, boolean isSystem)
Writes to the tags/properties defined by the tag paths.

But i am at a loss how initialize the AuthenticatedUser user implementing class? Can someone please guide me with an exapmle.

regards
PRAMANJ
:cry:

If you’re calling this from a gateway module without being invoked in a context where you might have an AuthenticatedUser object (an RPC call from the client for example) then you can use a null value for user and the isSystem flag to true.

Hi Kevin,
Thanks for your reply. I tried writing using following code

			    WriteQuality = SQLTagManagerContext.write(writepaths, new BasicAuthenticatedUser(null, null )  , true );

where writepaths is declared as a local variable as follows:

List<WriteRequest> writepaths = new ArrayList <WriteRequest> ();

and WriteQuality is declared as local variable as follows:

java.util.List WriteQuality = new ArrayList ();

I get a run time exception at the “write” method execution, whereas the compilation and goes thru and build is successful!

Would appreciate your early reply,
Best regards
PRAMANJ

Use a null value for the user:

WriteQuality = SQLTagManagerContext.write(writepaths, null, true);
1 Like

Hi Kevin,
Thanks for the reply. The execution goes through now but I don’t get the right results!
Is my initialization of writepaths correct in the following code?

List<WriteRequest> writepaths = new ArrayList <WriteRequest> ();
writepaths.add(new BasicAsyncWriteRequest(TagPathParser.parse(…the path string…),Integer.parseInt(“5”));
java.util.List WriteQuality = new ArrayList ();
WriteQuality = SQLTagManagerContext.write(writepaths, null, true);
out.println(WriteQuality.get(0).isGood());
writepaths.clear();

The isGood() returns false and value of the tag given in the tagpath string remains null!

What am i doing wrong!
regards
PRAMANJ

Try printing the name and description from the Quality you get and see if there’s any hints.

when i print the two value it gives “Access Denied ACCESS_DENIED” for name and description respectively. I am trying to write to one of the tags of the simpleTagProvider example given in your SDK extended to 20 tags from 10 tags given in the example.
PRAMANJ

sorry values “Access Denied ACCESS_DENIED” are for description and name respectively, not name and description respectively.
regards
PRAMANJ

Did you register a WriteHandler on the SimpleTagProvider?

The SimpleTagProvider example already has the following code:

ourProvider.registerWriteHandler(CONTROL_TAG, new WriteHandler() {
@Override
public Quality write(TagPath target, Object value) {
Integer intVal = TypeUtilities.toInteger(value);
//The adjustTags function will add/remove tags, AND update the current value of the control tag.
adjustTags(intVal);
return CommonQualities.GOOD;
}
});

But I am not using this write method! I am just using the following call as explained in my earlier reply.

WriteQuality = SQLTagManagerContext.write(writepaths, null, true);

If you’re writing to a TagPath that you haven’t registered a WriteHandler for in the SimpleTagProvider then you’ll get the Access Denied quality…

try writing to whatever the TagPath for that CONTROL_TAG that has a registered handler is and see if it works.

Thanks lot kevin. I will try it tomorrow as its already midnight here.
Best regards
PRAMANJ

That means only the registered tag provider can update value of any of its own tags not some someone else? What if I want to update one of the SimpleTageProvider’s tags given in the examples in SDK from my gatewayHook Module using the write method of SQLTagsManager interface. I thought the isSystem flag set to true will override access qualifier for tags for a gateway module! Is there any way I can write a value on any tag in the system from my gateway module? How does ignition client write to a PLC input tag from an input button on client, to switch ON/OFF an equipment?
regards
PRAMANJ

The TagProvider a tag belongs to is ultimately responsible for allowing the tag to be written or not.

With the SimpleTagProvider the very first thing required for allowing writes is having a WriteHandler for that tag. If you control the SimpleTagProvider AND you want to write to a tag, then you’ll need a WriteHandler.

If you’re writing to tags belonging to another tag provider you’re at the mercy of the provider to allow you to write. While the SimpleTagProvider requires WriteHandlers be registered for any tag to write, other tag providers are all free to work in their own way.

In your test code if you were writing an OPC or memory tag belonging to the internal provider instead of a SimpleTagProvider that you aren’t registering WriteHandlers on your write would likely go through, assuming you had the correct TagPath and permissions (or use system flag + null user).

Hi Kevin,
That makes sense! Bottom line is it should be tag driven by Internal tag provider and memory tag or even OPC tag. (bit surprised about OPC tag is also writable! Perhaps it may also have some access protection in the address space it belongs to).

I think reading any valid tag path doesn’t have any such restriction about internal or external tag provider or memory or database tag etc. Please correct me if I am wrong.

Best regards
PRAMANJ