Is there any Windows native command line able to immediately flush persistent data from Codesys to Disk ?
I just came accross the following code, intended to save(/retrieve) data from Code(/File), but at some point it instantiate the Linux command sync which at first sight seems like there is no similar native option under CMD prompt command.
I found this link, which gives the solution by installing an executable, which I wanted to avoid:
Thanks in advance,
Andre.
PROGRAMPLC_PRGVAR
  first: BOOL:=TRUE; Â
  application: POINTERTOAPPLICATION;
  result: POINTERTORTS_IEC_RESULT;
  storeRetains: BOOL :=FALSE;END_VAR//NOTE: Flashmemoryhasahighbutlimitedamountofwritecyclesbeforeitwillbegintowearout. Thismeansthattheusershouldbecarefulnottowritetoflash//toooftentoavoidwear. Itisrecommenededtoonlywritepersistentvariableswhenchangesaremadetothepersistentvariableandnotinacyclicmanner.
//Thisfunctionisexecutedatstartuponlyoncetoloadwhatisinthefunction.
IF(first)THEN
  //Getthecurrentapplicationforusebytherestoreretainsfunctionbelow
  application:=AppGetCurrent(pResult:=result);
 Â
  //Thisfunctionrestorestheretainedvariablesfromthefile'Application.ret'intothecurrentapplication.Â
  //Ifyoukeepthefilenameofyourpersistantvariablefile'Application.ret'thisfunctionshouldnotbeneededasCODESYSshouldautomaticallyretore
  //theretainfileatstartup. Thisisjustshownasanexampleincasetheuserwouldliketomaintaindifferentretainfiles
  AppRestoreRetainsFromFile(pApp:=application, pszFilname:='Application.ret');
  first:=FALSE;END_IF//thisfunctionwillexecuteonetimewhenthe'storeRetains'booleanvariableisturnedtotrue;IF(storeRetains)THEN
  //thisisatestretainvariable. Itwillstartat0sinceitisinitializedthatwayinthePersistentVarsobject.
  //Everytimethisfunctionisexecutedthepersistentvariablewillincreaseby1andstoreitsnewvalue
  test_persist_var:=test_persist_var+1;
  //Getthecurrentapplicationforusebytherestoreretainsfunctionbelow
  application:=AppGetCurrent(pResult:=result);
  //Storethevariableslistedinthe'PersistentVars'objectintothefile'Application.ret'.
  //Youmaychangethefilenametoanythingyoupreferbutthe'Application.ret'shouldbeloadedautomaticallybyCODESYSsoifthefilenameischangedyou
  //mayneedtoloadthefileyourselfasshownabove
  AppStoreRetainsInFile(pApp:=application, pszFilname:='Application.ret');
 Â
  //CODESYSandtheLinuxfilesystemkeepfilesopenforapproximately40secondsafterthewritetoreducewearontheflashmemory. Ifpowerisabruptlylost
  //duringthatperiodoftimetheretainsfilecanbecorruptedandalluserdatacanbelost. Issuingthe'sync'commandbelowtotheLinuxfilesystem
  //willforcethefiletowriteandsyncwiththefilesystemmakingitverydifficultforthefiletobecorrupted.
  ShellCommand_System(command:='sync');
 Â
  //turnthe'storeRetains'variablebacktofalsesothisfuctionwon't execute until it is turned back to true
  storeRetains:=FALSE;END_IF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I-Campbell hat geschrieben:
Does CAA File.Flush() do what you want?
Hi,
Perhaps, but the above code already uses the library to handle files, and to be honest I`m unaware if there is replacement option for all functions used there. Is there any advantage that you know on using the CAA instead of the CmpApp?
BTW:
In the meantime, I tryied to add this library on the project, but seems as not available anywhere.
Do you know any link from where I could download it?
Thanks,
Andre
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Umm... So you're using the same version I am, CODESYS 3.5.15.30 so...
Library Manager > Add Library
Make sure the buttons are as shown
insert the File Access, which gives you CAA File
(alternatively, depress the "Show Advanced Libraries" button and search for CAA File)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Worked like a charm ! (at least now it is able to compile )
Since I'm out of office I cannot test on target device, but I'll update this thread with results along this week.
BTW: I'm not sure whether I did not exactly as you meant by "CAA File.Flush()" stated above:
Instead, the only option was for declaring as that:
  sFileName    :  File.CAA.FILENAME  :=  'Application.ret';  hFileHandle  :  File.CAA.HANDLE;  FileFlush    :  File.Flush();
And instantiating this way:
  FileFlush(xExecute:=storeRetains);
Seems it correct?
Thank you,
Andre.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I believe "ShellCommand_System()" is in a library provided by a hardware vendor (Cross Control). If file.flush doesn't work for you, you might see if your hardware vendor provides a way to execute shell commands.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi there,
Is there any Windows native command line able to immediately flush persistent data from Codesys to Disk ?
I just came accross the following code, intended to save(/retrieve) data from Code(/File), but at some point it instantiate the Linux command sync which at first sight seems like there is no similar native option under CMD prompt command.
I found this link, which gives the solution by installing an executable, which I wanted to avoid:
Thanks in advance,
Andre.
Does CAA File.Flush() do what you want?
Hi,
Perhaps, but the above code already uses the library to handle files, and to be honest I`m unaware if there is replacement option for all functions used there. Is there any advantage that you know on using the CAA instead of the CmpApp?
BTW:
In the meantime, I tryied to add this library on the project, but seems as not available anywhere.
Do you know any link from where I could download it?
Thanks,
Andre
Umm... So you're using the same version I am, CODESYS 3.5.15.30 so...
Library Manager > Add Library
Make sure the buttons are as shown
insert the File Access, which gives you CAA File
(alternatively, depress the "Show Advanced Libraries" button and search for CAA File)
Worked like a charm ! (at least now it is able to compile )
Since I'm out of office I cannot test on target device, but I'll update this thread with results along this week.
BTW: I'm not sure whether I did not exactly as you meant by "CAA File.Flush()" stated above:
Instead, the only option was for declaring as that:
And instantiating this way:
Seems it correct?
Thank you,
Andre.
You would need to do this flush in addition to your CmpApp code.
Open the file, flush the file, close the file.
Look forward to your results.
I believe "ShellCommand_System()" is in a library provided by a hardware vendor (Cross Control). If file.flush doesn't work for you, you might see if your hardware vendor provides a way to execute shell commands.