Persist variables as defined in the Codesys environment are not implemented on the uControl platform however variables can be stored in a file which will survive application installs and firmware updates.
The example is broken into the thee work tasks needed to implement file creation, file writing, and file reading using the Codesys SysFile library functions.
File Storage
Files are stored in the Runtime Location "/" found in the Device files tab. Subfolders can be added to this drive location. In the image below we see a file labeled persistent in the root directory and a new folder created labeled PlcLogic.
Files can be created using a text editor or Excel as a csv file or text file then transferred from your computers hard drive to the uControl persistent memory from this window using the << or >> buttons.
Expanding the folders even further we see /PlcLogic/Application and the file included in this example varlist.csv. The path is defined as follows: strFileName : STRING := '//$$PlcLogic$$/Application/varlist.csv';
Running the Example
Open the PLC_PRG code window and set the individual function you wish to test by setting its Boolean to True. Run only one function at a time. Each one performs its function on a different file.
Create a New File
To create a new file use the use the .AM_WRITE sysfile function. This will overwrite any existing file with the same name.
Running this code will create a new file called writefile.txt and writes the text "Hello World".
Write to a File (Append)
To append data to an existing file use the .AM_WRITE_PLUS sysfile function.
This code creates a new file if it does not already exist named append.txt then adds two columns of data consisting of strings and integers.
Read from a File
The file varlist.csv is included in this project so will be installed in the //PlcLogic/Application folder on the uControl.
To read data from a file use the .AM_READ_PLUS sys file function
The code will read and parse out two columns of strings and integers which can be viewed in the debug window. A csv file can be created using Excel or a text editor then imported into the project.
Comments
0 comments
Please sign in to leave a comment.