Configuration
FileType objects are created in a separate namespace called "FileTransfer". An XML file (files.xml) is used to configure this namespace and to select the files and folders available via OPC UA. The file must be located in the same directory as the executable file of the OPC UA server. The system must be restarted in order to activate the configuration. The XML file contains information about the folder path and a search mask that defines which files are published in the OPC UA namespace:
<Files>
<FolderObject DisplayName="TwinCAT">
<FolderObject DisplayName="3.1">
<FolderObject DisplayName="Boot" Path="c:/TwinCAT/3.1/Boot" Search="*.*" >
<FolderObject DisplayName="Plc" Path="c:/TwinCAT/3.1/Boot/Plc" Search="*.*" ></FolderObject>
<FolderObject DisplayName="Tmi" Path="c:/TwinCAT/3.1/Boot/Tmi" Search="*.*" ></FolderObject>
</FolderObject>
</FolderObject>
</FolderObject>
</Files>
Reading a file with an OPC UA client
General file handling is described in Appendix C of the OPC UA specification.
Reading a file via OPC UA can therefore be divided into the following steps:
- Calling the Open method of a file. This method returns a file handle that must be saved for later access. The mode defines whether the file is read or written to (see File modes).
- Determining the file size with the property "Size". In this way, the entire file can be read when the Read method is called.
- Calling the Read method. Inserting the file handle and file size as inputs. Selecting the destination folder in which the file contents are to be saved AFTER the method call.
- Calling the Close method to enable the file handle.
File modes
The following table shows all available file modes:
Field | Bit | Description |
---|---|---|
Read | 1 | The file is opened for reading. If this bit is not set, Read cannot be executed. |
Write | 4 | The file is opened for writing. If this bit is not set, Write cannot be executed. |
EraseExisting | 6 | The existing file contents are deleted, and an empty file is made available. |
Append | 10 | The file is opened and positioned at the end, otherwise it is moved to the beginning. This position can be changed with SetPosition. |
General behavior
The number of files opened in parallel is in principle unlimited and is subject only to any restrictions of the underlying operating system. However, files are subject to a 60 seconds timeout. After this timeout, open files are not automatically closed immediately. Instead, they are marked as "to close". If the corresponding FileHandle is used for a read/write operation during this time, the timeout is reset and the FileHandle remains valid. If an Open operation is performed on the same file during this time, the old FileHandle is enabled. If an OPC UA Client disconnects from the server and still has files open, all FileHandles belonging to this session will be closed automatically.