I have a OPC-UA driver that creates an OPC-UA tag tree, but also writes some data to a database. Now I am doing the writing through the SRConnection.runPrepQuery … I wonder if its possible to use the Ignition “Store and Forward” functionality instead. If it’s possible, a short hint would be highly appreciated.
You need to use the history manager to store information through the store and forward. First you need to create a class that implements DatasourceData:
[code]public class QuerySFData implements DatasourceData {
private static final long serialVersionUID = 1L;
String query;
String datasource;
Object[] values;
public QuerySFData(String query, String datasource) {
this(query, null, datasource);
}
public QuerySFData(String query, Object[] values, String datasource) {
this.query = query;
this.values = values;
this.datasource = datasource;
}
@Override
public int getDataCount() {
return 1;
}
@Override
public HistoryFlavor getFlavor() {
return DatasourceData.FLAVOR;
}
@Override
public String getLoggerName() {
return "Client Store & Forward";
}
@Override
public String getSignature() {
return "SFQuery: " + datasource + " - " + query;
}
@Override
public void storeToConnection(SRConnection conn) throws Exception {
if (values != null) {
conn.runPrepUpdate(query, values);
} else {
conn.runUpdateQuery(query);
}
}
}[/code]
Then you just call:
context.getHistoryManager().storeHistory("YourDataSourceName", new QuerySFData(query, values, datasource));