How can you store data records/variables event-triggered with date and time in a CSV file?
You can store data records/variables in CSV file via a script that is executed event-triggered (e.g. by clicking a button). The functionality is explained here with a sample script that is available for downloading at the end of this entry.
Description of the sample script:
The name of the CSV file itself is Archiv_x.csv, where the x stands for the date. The date is generated via the function "DatePart" from the VBScript variable "Date". The "FName" variable consists of the file name and the file path.
The data records are written to the "DataSet" string variable. First of all the PC time (Now) is entered followed by the separate variables to be stored ("Var1", "Var2" and "Var3").
Please make sure that you convert the variables into a text using the CStr() function and separate them with commas or semicolons. You can set comma or semicolon as separator character in in MS-Excel under "Data >Text in Columns...".
The script is called for a specific trigger event (e.g. clicking a button). First a check is made whether an archive file with the same name is already located in the directory specified. If not, a new file is created.
If there is such a file already available, it is opened, the data records inserted in it and then it is closed again.
Depending on the storage path (Slot A/B), you can select the storage path you want to use via an icon list - data storage on CF card or PC card. Information on the storage path is available in the manual of the operator device concerned. You might have to change the storage path in the configuration.
You enter the relevant values in the input fields Var1, Var2 and Var3.
Click the "Storage Data" button to store the variable values in the "Archiv_x.csv" file. If an incorrect storage path has been selected or there is no storage card in the relevant slot, a system message is issued.
In the PC Runtime project the path for storing the file must already exist on the PC - in this case "C:\Data\PT_Data".
The Visual Basic commands of a script for PC applications is different to those for WinCE applications.
Please refer here to the information given in Entry ID 13408815.
Runnability and test environment:
The example can be used on all operator panels that support script functions.
The following table lists the components that have been used to create this entry and verify the functions described.
|Component||Product and version|
|PC operating system||Microsoft Windows XP SP2|
|HMI Software||ProTool/Pro V6.0 SP3|
|HMI devices||MP370 Touch 12"; PC Runtime|
The attached download contains the archived ProTool project for an MP370 Touch operator panel and a PC Runtime configuration with the functions described above.
Attachment 1: Projekt_1.zip ( 28 KB )