From OpenSCADAWiki
Jump to: navigation, search

Q: How can I save-restore the modified data at the logical level?
Re: Indeed, it may sometimes be necessary to save and then recover, preferably at restart, some of the modified dynamic data, such as equipment mileage meters. In general, the processing of this type of data and equipment needs to be done on the logical level of the subsystem "Data acquisition", but it can be implemented in many ways, which involves storing data in a certain repository and further restoration of them, however, the more well-known methods are:

  • Periodic, or when stop, to save the context of the template parameters by requesting the OpenSCADA user API via cntrReq(), where "force" for force saving not modified parameters:
SYS.cntrReq(SYS.XMLNode("save").setAttr("path",this.nodePath()+"/%2fobj").setAttr("force","1"));
  • If the attribute of the template with the counter is archived then at the start of the parameter you can get the last value from this archive, for example, as follows:
if(f_start)    prevArchRestore = false;
if(!prevArchRestore && (archEnd=this.cntr.arch().end("FSArch.1s"))) {
    SYS.messInfo("testArch", "val="+this.cntr.arch().getVal(archEnd)+"; "
               "val1="+this.cntr.arch().getVal(archEnd,false,"FSArch.1s")+"; "
               "val2="+this.cntr.get(archEnd/1000000,archEnd%1000000));
    cntr = this.cntr.arch().getVal(archEnd);
    prevArchRestore = true;
}
  • Create a custom database table and write/read this data directly into this table through SQL-queries by SQLReq().