# AbstractTagDriver writevalue initilization behavior?

**URL:** <https://forum.inductiveautomation.com/t/abstracttagdriver-writevalue-initilization-behavior/6179>\
**Category:** Module Development\
**Created:** [April 9, 2013, 9:05am UTC](https://forum.inductiveautomation.com/t/abstracttagdriver-writevalue-initilization-behavior/6179 "2013-04-09T09:05:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [April 9, 2013, 9:05am UTC](https://forum.inductiveautomation.com/t/abstracttagdriver-writevalue-initilization-behavior/6179/1 "2013-04-09T09:05:46Z")

</div>

Hi,

I’m trying to implement a driver based on the AbstractTagDriver example.  
All is fine, except one point.

When I reload my driver, I would like that the value of a WritableDriverTag to be initialized with the last writed value of the ignition tag connected to my WritableDriverTag.

What is the initial status to set for a WritableDriverTag ?

```auto
package com.eco2charge.drivercan.gateway.tag;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.eco2charge.drivercan.gateway.ITrameSend;
import com.inductiveautomation.opcua.types.DataType;
import com.inductiveautomation.opcua.types.DataValue;
import com.inductiveautomation.opcua.types.StatusCode;
import com.inductiveautomation.opcua.types.UtcTime;
import com.inductiveautomation.opcua.types.Variant;
import com.inductiveautomation.xopc.driver.api.tags.WritableDriverTag;

public class IntegerWritableDriverTag implements WritableDriverTag {
	
	private Integer localValue = null;
	private String localAddress = "";	
	private StatusCode statusCode = StatusCode.BAD_UNKNOWN;
	private Logger logger = LogManager.getLogger(IntegerWritableDriverTag.class);
	private ITrameSend trameSend = null;
	
	public IntegerWritableDriverTag(String address, ITrameSend _trameSend) {
		this.localAddress = address;
		this.trameSend = _trameSend;
	}

	// Acces OPC-UA	
	@Override
	public DataValue getValue() {
		if (localValue == null){
			return new DataValue(statusCode);
		} else {
			return new DataValue(new Variant((Integer)localValue),statusCode);
		}
	}

	@Override
	public DataType getDataType() {
		return DataType.Int32;
	}

	@Override
	public String getAddress() {
		return localAddress;
	}

	@Override
	public StatusCode setValue(DataValue arg0) {
		try {
			localValue = (Integer) arg0.getValue().getValue();	
		} catch (Exception e) {
			logger.error("error dans setValue() : " + e.getMessage());
			statusCode = StatusCode.BAD_INTERNAL_ERROR;
			return statusCode;
		}
		if (trameSend != null){
			// maj de la trame complete
			try {
				trameSend.updateSendTrame();				
			} catch (Exception e) {
				logger.error("error dans setValue() : " + e.getMessage());	
			}
		}
		statusCode = StatusCode.GOOD;
		return statusCode;
	}
	
	// acces depuis le driver 
	public Integer getLocalValue() {
		return(localValue);
	}
	
	public void setLocalValue(Integer _localValue) {
		localValue = _localValue;
	}
}
```

---

<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:** [April 9, 2013, 1:43pm UTC](https://forum.inductiveautomation.com/t/abstracttagdriver-writevalue-initilization-behavior/6179/2 "2013-04-09T13:43:35Z")

</div>

A Node that has just been added to the address space gets a null value with a StatusCode of Uncertain\_InitialValue, which is what happens behind the scenes when you add a DriverTag to the AbstractTagDriver.

This value will quickly be replaced the first time it is read or subscribed to by whatever value your driver provides. You’ll probably have to save the last value to disk on shutdown or something if you really need to provide that value the first time getValue() gets called on your tag after the driver starts again.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [April 9, 2013, 2:57pm UTC](https://forum.inductiveautomation.com/t/abstracttagdriver-writevalue-initilization-behavior/6179/3 "2013-04-09T14:57:04Z")

</div>

Yes, read value is OK.  
But for the Ignition write, is there a way to initailize the WritableDriverTag value with the last writed value from the ignition’s tag connected to the WritableDriverTag provider ?

As for me, the abstractTagDriver is resposible for the initialization of tag readed values, but the ignition tag database is responsible for the initialization of tag writed values ?  
 ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

---

<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:** [April 9, 2013, 2:59pm UTC](https://forum.inductiveautomation.com/t/abstracttagdriver-writevalue-initilization-behavior/6179/4 "2013-04-09T14:59:17Z")

</div>

[quote=“mazeyrat”]Yes, read value is OK.  
But for the Ignition write, is there a way to initailize the WritableDriverTag value with the last writed value from the ignition’s tag connected to the WritableDriverTag provider ?

As for me, the abstractTagDriver is resposible for the initialization of tag readed values, but the ignition tag database is responsible for the initialization of tag writed values ?  
 ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")[/quote]

What do you mean by the WritableDriverTag provider? I’m not quite sure what you’re trying to do achieve here.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [April 9, 2013, 3:15pm UTC](https://forum.inductiveautomation.com/t/abstracttagdriver-writevalue-initilization-behavior/6179/5 "2013-04-09T15:15:57Z")

</div>

My class ATDDriver extends AbstractTagDriver

I add some WritableDriverTag, (com.inductiveautomation.xopc.driver.api.tags.WritableDriverTag)  
with .addDriverTag(WritableDriverTag);

```auto
public class BooleanWritableDriverTag implements {
private Boolean localValue = null;

@Override
	public String getAddress() {
		return localAddress;
	}

	@Override
	public DataType getDataType() {
		return DataType.Boolean;
	}

	@Override
	public DataValue getValue() {
		if (localValue == null){
			return new DataValue(statusCode);
		} else {
			return new DataValue(new Variant((Boolean)localValue),
								statusCode,
								horodate,
								horodate);
		}
	}
}
```

I would like ignition initailize the DataValue of this WritableDriverTag with the last writed value in Ignition Tags

Example : when restarting Ignition ou reloading my driver  
ETS\_SleepMode is null, and the last writed value is lost.

![]()

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/5b9e4cd90f22ce7270d87a5981eec6fb54148dbf.png)  
  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6215e2617a779a588ae121b036b3dd072e95e293.png)

---

<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:** [April 9, 2013, 3:23pm UTC](https://forum.inductiveautomation.com/t/abstracttagdriver-writevalue-initilization-behavior/6179/6 "2013-04-09T15:23:36Z")

</div>

Ignition won’t do that for you. There’s a pile of completely different sub-systems between your driver and what you read/write/interact with in the designer.

Drivers are built on the assumption that the tag data comes from some underlying system/device (a PLC usually), and that you can read that data again when the driver starts.

If you want hang onto the last value written to your driver across driver restarts, and you don’t have any source to read it back from, you’ll have to do that yourself somehow. Maybe by persisting it to disk on driver shutdown and reading it again on driver startup. It sounds like what you’ve got right now is a driver whose values exist only in memory.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [April 10, 2013, 9:54am UTC](https://forum.inductiveautomation.com/t/abstracttagdriver-writevalue-initilization-behavior/6179/7 "2013-04-10T09:54:54Z")

</div>

Ok I understand the writted value must be persisted to be restored in my case.  
Is there an ignition integrated mecanis to store and restore persisted value directly into my module ?
