First, thanks so much for distributing the OSCAT libraries!
I want to use the function block "DLOG_STORE_FILE_CSV" to log data into one file only. Because of the restrictions of retaining variables (for BeagleBone Black the proper shutdown is needed), I want to do some workaround in that way as the data has to be append only to the file.
I know this feature already exists, but to work properly the data in the variable "save_data : DLOG_SAVE" (used as a paramter for "DLOG_STORE_FILE_CSV" instance, has to be a retained variable. Therefore it is necessary to use a UPS, to savely retain variable on my BeagleBone Black. To workaround this, I would like to use an "append" parameter, to not need the variable to be retained.
If I use the code and the demo from the library (on my BeagleBone Black without retaining the retain variables), the content of the file will be erased, due to the empty variable "save_data" of data type "DLOG_SAVE" used as parameter for instance call of "DLOG_STORE_FILE_CSV". For me the functionality of writing with append, should not depend on retaining any variables.
(Btw. I know that that hasn't already be written to file will be lost due to power lost; but this doesn't matter. Morte important is the fact that there is no unlimited storage on devices, so it would be best for me to define a maximum number of "FILE_SIZE" or "line count", to delete the latest log entry and write the new log entry, if the file hits this maximum file size. So there will be only one file with the latest log entries, depending on the defined file size.)
At least the question is how to change the behavior of writing to file (append or delete content and write data) if there is already a file with that filename?I've read a lot about this function block in this forum. Several times there is the hint to use the append mode, but don't know how to do. Can anyone please give me an advise in how to code that?
In the documentation for the function block "FILE_SERVER" there is also a hint:
An automatic append function can be realized very easy. The parameter FILE_SIZE has to be written to the OFFSET
But I don't know how to implement. When I tried to do it outside the function block instance call, an error occurs because FILE_SIZE is no input of FILE_SERVER. Here is the code I tried:
x1(X:=x); // Logger input for STRING, used for Time stamp
x2(X:=x, STR:=Glob_Var.sLogExportText2); // Logger input for STRING, used for Event type
x3(X:=x, STR:=Glob_Var.sLogExportText3); // Logger input for STRING, used for Description
DLOG_STORE_FILE_CSV(X:=x, SAVE_DATA:=save_data, ENABLE:=enable, TRIG_M:=Glob_Var.xLogExportTrig_m, FILENAME:=filename, DTI:=RTC_2.UDT, SEP:=9, AUTO_CLOSE:=TIME#10S, ERROR_C=>error_c, ERROR_T=>error_t); // File storage (csv)
RTrig(CLK:=DLOG_STORE_FILE_TSV.FSD.FILE_OPEN);
IF RTrig.Q THEN
DLOG_STORE_FILE_CSV.FSD.OFFSET := DLOG_STORE_FILE_CSV.FSD.FILE_SIZE;
END_IF
When I try to use a copy of the function block "DLOG_STORE_FILE_CSV" from the library everything is OK, but when I try to use a copy of the function block "FILE_SERVER" from the library and to the change there, it gets me several errors (32) when I want to translate the project. Here is the code I tried:
150: (* File Open *)
IF command = BYTE#0 THEN
IF error THEN
step := 30000; (* Beenden *)
ELSE
(* Filedaten eintragen *)
handle := open_handle;
used_filename := FSD.FILENAME;
file_position := UDINT#4294967295; (* maximal = unbekannt *)
FSD.FILE_OPEN := TRUE;
FSD.OFFSET := FSD.FILE_SIZE;
step := 200;
END_IF;
END_IF;
Till now my workaround was to change the code of "DLOG_STORE_FILE_CSV" like this:
10: X.UCB.D_STRING := fn_last;
// IF fn_last = SAVE_DATA.FN_REM THEN
X.UCB.D_HEAD := WORD#16#F201; (* Filemode open + write *)
X.ADD_COM := 00;
// ELSE
// X.UCB.D_HEAD := WORD#16#F301; (* Filemode create + write *)
// X.ADD_COM := 02; (* ADD HEADER *)
// END_IF;
X.UCB.D_MODE := 1; (* Dateinamen als String ablegen *)
UCB(DATA:=X.UCB); (* Daten eintragen *)
step_1 := 30;
But this results in losing the opertunity to get a new file, by changing the variable "filename", and this is no goal.
I use CODESYS 3.5.16 Patch 4 and the OSCAT NETWORK library (v1.3.5.2) from CODESYS store.
I'm over this topic for a long while now and pretty looking forward for some help to get it work.