# Driver Read Method

**URL:** <https://forum.inductiveautomation.com/t/driver-read-method/5842>\
**Category:** Module Development\
**Created:** [February 11, 2013, 4:42pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842 "2013-02-11T16:42:43Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![lisawas](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lisawas](https://forum.inductiveautomation.com/u/lisawas)\
**Post date:** [February 11, 2013, 4:42pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/1 "2013-02-11T16:42:43Z")

</div>

In the Driver Interface, there is a Read stub that must be overridden, but this appears to be a general, asynchronous read. Is there a method I can override to deal with polling for tags with a subscription?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 11, 2013, 4:51pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/2 "2013-02-11T16:51:30Z")

</div>

Driver#alterSubscriptions() is called any time a monitored item for a node is added or deleted to let you know what you should be subscribed to and at what rate.

---

<div class="post-metadata">

**Author:** ![lisawas](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lisawas](https://forum.inductiveautomation.com/u/lisawas)\
**Post date:** [February 11, 2013, 5:00pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/3 "2013-02-11T17:00:28Z")

</div>

I’m trying to talk to a device that speaks OPCXML. The method that it uses to just read a tag, versus reading a tag that is part of a subscription, is different. Does Driver just use Read to get the tag values of subscribed tags?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 11, 2013, 5:41pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/4 "2013-02-11T17:41:28Z")

</div>

No, reads aren’t necessarily related to subscribed items.

You can, if you choose to implement it this way, detect if items you’re getting a read call for are already part of a subscription and just return the latest value you have on hand for that item though.

But there’s no requirement that an item you get a read request for is part of a subscription.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 11, 2013, 5:46pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/5 "2013-02-11T17:46:56Z")

</div>

Also, unless you REALLY need the data from the device exposed through the UA server for some reason, consider implementing and adding an SROPCServer to the platform instead of adding a Driver to the UA module.

If you went that route, you’d end up with the ability to add a 3rd type of OPC connection (XML, in addition to DCOM and UA).

---

<div class="post-metadata">

**Author:** ![lisawas](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lisawas](https://forum.inductiveautomation.com/u/lisawas)\
**Post date:** [February 11, 2013, 5:55pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/6 "2013-02-11T17:55:26Z")

</div>

I’m already a fair chunk of the way through the driver…as long as subscribed items use the read method to get their values, I’m alright, even if other tags also use the read method. That was my big concern.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 11, 2013, 6:25pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/7 "2013-02-11T18:25:44Z")

</div>

I’m not sure what you mean when you say “as long as subscribed items use the read method to get their values”.

Don’t expect Driver#readItems() to be called repeatedly, or at all, for items you receive in Driver#alterSubscriptions().

Calls to Driver#readItems() are initiated when the OPC-UA server receives a read service call for an item belonging to your driver, that’s all.

---

<div class="post-metadata">

**Author:** ![lisawas](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lisawas](https://forum.inductiveautomation.com/u/lisawas)\
**Post date:** [February 11, 2013, 8:30pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/8 "2013-02-11T20:30:49Z")

</div>

I’m trying to relate the Driver methods to OPCXML calls. In OPCXML, you can do an asynchronous read of a list of tags, which returns their values. Alternatively, you can make a PolledRefresh call where you pass the pertinent subscription, and the tag values are returned.

I was assuming that SQLTags and transaction groups would call Read according to their scan rates, in which case I would use PolledRefresh…but I’m not sure one way or the other. OPCXML requires you to poll for tags, even when they have subscriptions.

Perhaps the pertinent question is, under what circumstances does Ignition use the Read() method in Driver?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 11, 2013, 8:42pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/9 "2013-02-11T20:42:47Z")

</div>

[quote=“lisawas”]  
Perhaps the pertinent question is, under what circumstances does Ignition use the Read() method in Driver?[/quote]

When a scan class is in “Read Mode” instead of “Subscribe Mode”, ditto for groups, or when a user calls system.opc.readValues() from scripting.

Or when any other OPC-UA client (which is what Ignition is as well) calls the OPC-UA read service on the server.

By default, scan classes and groups use subscribe mode.

---

<div class="post-metadata">

**Author:** ![lisawas](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lisawas](https://forum.inductiveautomation.com/u/lisawas)\
**Post date:** [February 11, 2013, 8:47pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/10 "2013-02-11T20:47:26Z")

</div>

I see…is there a method that I can override that Ignition calls when it wants to get tag values in Subscribe mode?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 11, 2013, 8:48pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/11 "2013-02-11T20:48:54Z")

</div>

No, these are totally separate systems we’re talking about here. The drivers, OPC-UA server, and even OPC-UA client code don’t know anything about scan classes or their modes.

They all know how to read things they’re asked to read, and how to subscribe to things they’re asked to subscribe to.

---

<div class="post-metadata">

**Author:** ![lisawas](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lisawas](https://forum.inductiveautomation.com/u/lisawas)\
**Post date:** [February 11, 2013, 9:59pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/12 "2013-02-11T21:59:00Z")

</div>

Does Ignition operate under the idea that items with subscriptions will push changes to Ignition?  
At this point, I’m tempted to register a task to poll my device and update the tags whose values have changed.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 11, 2013, 10:05pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/13 "2013-02-11T22:05:41Z")

</div>

[quote=“lisawas”]Does Ignition operate under the idea that items with subscriptions will push changes to Ignition?  
At this point, I’m tempted to register a task to poll my device and update the tags whose values have changed.[/quote]

It’ll help if you stop referring to the system as a whole (Ignition) and start referring to the specific subsystem(s) we’re dealing with - in this case drivers and the OPC-UA server.

The OPC-UA server expects that all SubscriptionItems it passes to a Driver in Driver#alterSubscriptions() will have setValue() called on that item, repeatedly, at the rate specified in the item. You must make this setValue() call at the specified rate, or as close as possible, whether or not the value has actually changed. How ever you manage to do this is up to your implementation.

---

<div class="post-metadata">

**Author:** ![lisawas](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lisawas](https://forum.inductiveautomation.com/u/lisawas)\
**Post date:** [February 11, 2013, 10:39pm UTC](https://forum.inductiveautomation.com/t/driver-read-method/5842/14 "2013-02-11T22:39:43Z")

</div>

Okay. I think I know how I want to do that, then. Thank you.
