Reading and writing files
Using the sample programs This document contains sample applications of our products for certain areas of application. The application notes provided here are based on typical features of our products and only serve as examples. The notes contained in this document explicitly do not refer to specific applications. The customer is therefore responsible for assessing and deciding whether the product is suitable for a particular application. We accept no responsibility for the completeness and correctness of the source code contained in this document. We reserve the right to modify the content of this document at any time and accept no responsibility for errors and missing information. |
The 1 MB flash memory of the EL6070 can be used to store files.
- Up to 20 files can be stored.
- The file content is stored in binary format.
- Before a file is read, the special file system can read a directory containing names of files and their sizes and additional information. A so-called dot file “.“ have to be read out for it: if the name or the ASCII character for “.“ is passed by FoE upload (ASCII value 0x2E), a defined header of information from the memory of the terminal is returned, which contains information about all stored files in the terminal. For example, the following memory contents are present:
Detailed information to this can in principle be taken from the present example program. - When saving a file, a freely selectable 32 bit password is expected. Each file can have its own password. If none is given, PW=0 is accepted from the terminal. For reading out the file, the password is then needed again, possibly also PW=0 if none was specified.
- An existing file will be overwritten when a file is saved under the same name. A file can be deleted by a write access with the file name and a transferred file size of 0 (correspondingly without content).
The following sample program uses the TwinCAT functions of the Tc2_EtherCAT library for the FoE read and write access as well as the file access functions of the Tc2_System library with a fixed path „C:\EL6070_files\“. Hence, a drive “C:” and such folder have to be existing. The device configuration is also present within this example:
IPC + EK1100 + EL6070 + EL9011.
Explanatory notes for the sample program “EL6070_Access”
The sample program uses a TwinCAT 3 visualization. It illustrates file handling for the terminal on the left and file access to the control PC on the right. First, the data are loaded into the controller memory. Then they can either be loaded or saved on/ to the control computer as file, or they can be read to or written from the terminal:
Notes:
- The needed NetId for terminal access will be identified by the already existing link within the configuration. Therefrom the address for the PLC system will be derived.
- This example program does not use a checksum and does not support the password function.
- A duration while file access on the terminal with a transfer rate of several 1000 bytes/s have to be expected (e.g. over 3 minutes for 1 MB).
- The files that are loaded, stored and deleted on the right are located on the controller. This has to be taken into account during remote access. The path can only point to the local computer’s file system and is preset „C:\EL6070_files\“. Network paths cannot be specified here. In addition, special care is required for file access on the control computer.
Download:
Sample program “EL6070_Access”: Download
Preparations for starting the sample programs (tnzip file / TwinCAT 3)
- Click on the download button to save the Zip archive locally on your hard disk, then unzip the *.tnzip archive file in a temporary folder.
- Select the .tnzip file (sample program).
- A further selection window opens. Select the destination directory for storing the project.
- For a description of the general PLC commissioning procedure and starting the program please refer to the terminal documentation or the EtherCAT system documentation.
- The EtherCAT device of the example should usually be declared your present system. After selection of the EtherCAT device in the “Solutionexplorer” select the “Adapter” tab and click on “Search...”:
- Checking NetId: the “EtherCAT” tab of the EtherCAT device shows the configured NetId:.
The first four numbers must be identical with the project NetId of the target system. The project NetId can be viewed within the TwinCAT environment above, where a pull down menu can be opened to choose a target system (by clicking right in the text field). The number blocks are placed in brackets there next to each computer name of a target system. - Modify the NetId: By right clicking on “EtherCAT device” within the solution explorer a context menu opens where “Change NetId...” have to be selected. The first four numbers of the NetId of the target computer must be entered; both last values are 4.1 usually.
Example: - NetId of project: myComputer (123.45.67.89.1.1)
- Entry via „Change NetId...“: 123.45.67.89.4.1