AbstractTagDriver writevalue initilization behavior?

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 ?

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;
	}
}

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.

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:

[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:[/quote]

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

My class ATDDriver extends AbstractTagDriver

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

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.





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.

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 ?