<< Click to Display Table of Contents >> Manual > Monitoring system construction guide > Establishing major functions > Logging/trend graph > Using logger actions > Collection of logger action samples > Dynamically change the file name of the CSV log |
overview
When logging to a CSV file, you may want to rename the log file during runtime as needed.
For example, consider the following case:
•I want to change the log file name for each work and setup number.
•I want to specify the file name according to instructions from an external application.
•I want to specify the file name using PLC logic
Therefore, assuming the above scenario, this article explains how to dynamically change the log file name during runtime. In this example, data from SD0000 to SD009 is saved with a different file name for each work number. Specifically, U02.F01.T01 is defined as a string tag, and the contents of this tag are used as the file name. For example, if the tag contents are obtained from a PLC via communication, the file name can be controlled by the PLC ladder in a similar processing method. The file name can also be controlled by rewriting the tag contents from an external application such as VisualBasic or SCADA via IPLink or OPC/DDE.
In this sample example, U02.F01.T02 (bit tag) is defined as the timing for data logging, and data from SD0000 to SD0009 will be logged when it changes to TRUE.
Download the sample
The creation examples shown on this page are provided with samples.
The sample can be downloaded from below.
Setup Procedure
Tag settings
1.Add a virtual device "U01" and set tags "U01.F01.SD0000" to "U01.F01.SD0009" for data collection.
2.Add a virtual device "U02" and set the tag "U02.F01.T01" for the file name and the tag "U02.F01.T02" for the data acquisition trigger.
Here, "T01" is set as the string tag, as 20-word ASCII type.
Action Settings
1.Add a logger action "A01" and add a time field "F01" and tag fields "SD0000 to SD0009".
2.From the Text Settings tab of A01, set the file name and destination for the log file.
Here, select "Add tag value to file name" from "Extension" of the file name, and specify "U02.F01.T01" as "Tag name".
Event Settings
1.Add "U02.F01.T01" as Tag event.
This event is not for logging, but to notify the action that the log file name has changed. When "U02.F01.T01" changes (i.e., when the file name string changes), the action name "A01" and the parameter "SETFILENAME" are executed. By specifying the parameter "SETFILENAME", the logger action recognizes the file name change (note that logging is not performed when the call with this parameter is given).
2.Add Tag event "U02.F01.T02" and specify "A01" as the execution action.
With this setting, "A01" will be executed when "U02.F01.T02" turns ON.
Commentary
If you specify the "SETFILENAME" parameter in the definition of the execution action of the event, you can change the file name of the log file at that timing. In this sample, the file name of the log file is changed when the string "U02.F01.T01" changes, i.e., when the file name changes. To check how it works, set some characters to "U02.F01.T01" and then set "U02.F01.T02" to TRUE.
If you want to change the file name, reset "U02.F01.T01" to a different file name, then change "U02.F01.T02" from FALSE to TRUE again, and logging will be performed using the new file name.
If the file name is not set, the log file will not be saved. In the above example, even if "U02.F01.T01" is left blank and "A01" and "SETFILENAME" are executed, the file name will not be set. |