### C.2 FileType

This ObjectType defines a type for files. It is formally defined in Table C.1.

Table C.1 – FileType

Attribute Value
BrowseName FileType
IsAbstract False

Subtype of the BaseObjectType defined in 6.2

References NodeClass BrowseName DataType TypeDefinition Modelling Rule
HasProperty Variable Size UInt64 PropertyType Mandatory
HasProperty Variable Writable Boolean PropertyType Mandatory
HasProperty Variable UserWritable Boolean PropertyType Mandatory
HasProperty Variable OpenCount UInt16 PropertyType Mandatory
HasProperty Variable MimeType String PropertyType Optional
HasComponent Method Open Defined in C.2.1 Mandatory
HasComponent Method Close Defined in C.2.2 Mandatory
HasComponent Method Read Defined in C.2.3 Mandatory
HasComponent Method Write Defined in C.2.4 Mandatory
HasComponent Method GetPosition Defined in C.2.5 Mandatory
HasComponent Method SetPosition Defined in C.2.6 Mandatory

Size defines the size of the file in Bytes. When a file is opened for write the size might not be accurate.

Writable indicates whether the file is writable. It does not take any user access rights into account, i.e. although the file is writable this may be restricted to a certain user / user group. The Property does not take into account whether the file is currently opened for writing by another client and thus currently locked and not writable by others.

UserWritable indicates whether the file is writable taking user access rights into account. The Property does not take into account whether the file is currently opened for writing by another client and thus currently locked and not writable by others.

OpenCount indicates the number of currently valid file handles on the file.

The optional Property MimeType contains the media type of the file based on RFC 2046.

Note that all Methods on a file require a fileHandle, which is returned in the Open Method.

## C.2.1 Open

Open is used to open a file represented by an Object of FileType. When a client opens a file it gets a file handle that is valid while the session is open. Clients shall use the Close Method to release the handle when they do not need access to the file anymore. Clients can open the same file several times for read. A request to open for writing shall return Bad_NotWritable when the file is already opened. A request to open for reading shall return Bad_NotReadable when the file is already opened for writing.

Signature

Open(
[in] Byte mode
[out] UInt32 fileHandle
);

Argument Description
mode Indicates whether the file should be opened only for read operations or for read and write operations and where the initial position is set.
The mode is an 8-bit unsigned integer used as bit mask with the structure defined in the following table:

Field   Bit   Description
Read   0   The file is opened for reading. If this bit is not set the Read Method cannot be executed.
Write   1   The file is opened for writing. If this bit is not set the Write Method cannot be executed.
EraseExisting   2   This bit can only be set if the file is opened for writing (Write bit is set). The existing content of the file is erased and an empty file is provided.
Append   3   When the Append bit is set the file is opened at end of the file, otherwise at begin of the file. The SetPosition Method can be used to change the position.
Reserved   4:7   Reserved for future use. Shall always be zero.

fileHandle A handle for the file used in other method calls indicating not the file (this is done by the Object of the Method call) but the access request and thus the position in the file. The fileHandle is generated by the server and is unique for the Session. Clients cannot transfer the fileHandle to another Session but need to get a new fileHandle by calling the Open Method.

Method Result Codes (defined in Call Service)

Result Code Description
Bad_NotReadable See OPC 10000-4 for a general description. File might be locked and thus not readable.
Bad_NotWritable See OPC 10000-4 for a general description.
Bad_InvalidState See OPC 10000-4 for a general description. The file is locked and thus not writable.
Bad_InvalidArgument See OPC 10000-4 for a general description. Mode setting is invalid.
Bad_NotFound See OPC 10000-4 for a general description.
Bad_UnexpectedError See OPC 10000-4 for a general description.

Table C.2 specifies the AddressSpace representation for the Open Method.

Table C.2 – Open Method AddressSpace Definition

Attribute Value
BrowseName Open
References NodeClass BrowseName DataType TypeDefinition ModellingRule
HasProperty Variable InputArguments Argument[] PropertyType Mandatory
HasProperty Variable OutputArguments Argument[] PropertyType Mandatory