4.2 FileType

4.2.1 General

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

Table 1 – FileType
Attribute Value
BrowseNameFileType
IsAbstractFalse
References NodeClass BrowseName DataType TypeDefinition Modelling
Rule
Subtype of the BaseObjectType defined in OPC 10000-5
HasPropertyVariableSizeUInt64PropertyTypeMandatory
HasPropertyVariableWritableBooleanPropertyTypeMandatory
HasPropertyVariableUserWritableBooleanPropertyTypeMandatory
HasPropertyVariableOpenCountUInt16PropertyTypeMandatory
HasPropertyVariableMimeTypeStringPropertyTypeOptional
HasComponentMethodOpenDefined in 4.2.2Mandatory
HasComponentMethodCloseDefined in 4.2.3Mandatory
HasComponentMethodReadDefined in 4.2.4Mandatory
HasComponentMethodWriteDefined in 4.2.5Mandatory
HasComponentMethodGetPositionDefined in 4.2.6Mandatory
HasComponentMethodSetPositionDefined in 4.2.7Mandatory
HasPropertyVariableMaxByteStringLengthUInt32PropertyTypeOptional
HasPropertyVariableLastModifiedTimeDateTimePropertyTypeOptional
Conformance Units
Base Info FileType Base

Size defines the size of the file in Bytes. When a file is opened for write, the size might not be accurate. If the Server can not accurately determine the size of the file, the Size Property shall be returned to a Client with a StatusCode of Bad_NotSupported.

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 consider 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 consider 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.

The optional MaxByteStringLength Property indicates the maximum number of bytes of the read and write buffers. If this Property is not present then the maximum size is defined by the MaxByteStringLength Property of the ServerCapabilitiesType defined in OPC 10000-5.

The optional LastModifiedTime Property indicates the time the file was last modified. The Property shall be updated whenever the Server detects that the file has changed.

4.2.2 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:

fileHandleA 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_NotReadableSee OPC 10000-4 for a general description. File might be locked and thus not readable.
Bad_NotWritableSee OPC 10000-4 for a general description.
Bad_InvalidStateSee OPC 10000-4 for a general description. The file is locked and thus not writable.
Bad_InvalidArgumentSee OPC 10000-4 for a general description. Mode setting is invalid.
Bad_NotFoundSee OPC 10000-4 for a general description.
Bad_UnexpectedErrorSee OPC 10000-4 for a general description.

Table 2 specifies the AddressSpace representation for the Open Method.

Table 2 – Open Method AddressSpace definition
Attribute Value
BrowseNameOpen
References NodeClass BrowseName DataType TypeDefinition ModellingRule
HasPropertyVariableInputArgumentsArgument[] PropertyTypeMandatory
HasPropertyVariableOutputArgumentsArgument[] PropertyTypeMandatory
Conformance Units
Base Info FileType Base

4.2.3 Close

Close is used to close a file represented by a FileType. When a client closes a file, the handle becomes invalid.

Signature

	Close(
		 [in] UInt32 fileHandle
		);
Argument Description
fileHandleA handle indicating the access request and thus indirectly the position inside the file.

Method Result Codes (defined in Call Service)

Result Code Description
Bad_InvalidArgumentSee OPC 10000-4 for a general description. Invalid file handle in call.

Table 3 specifies the AddressSpace representation for the Close Method.

Table 3 – Close Method AddressSpace definition
Attribute Value
BrowseNameClose
References NodeClass BrowseName DataType TypeDefinition ModellingRule
HasPropertyVariableInputArgumentsArgument[] PropertyTypeMandatory
Conformance Units
Base Info FileType Base

4.2.4 Read

Read is used to read a part of the file starting from the current file position. The file position is advanced by the number of bytes read.

Signature

	Read(
		 [in] UInt32 fileHandle
		 [in] Int32 length
		 [out] ByteString data
		);
Argument Description
fileHandleA handle indicating the access request and thus indirectly the position inside the file.
Length

Defines the length in bytes that should be returned in data, starting from the current position of the file handle. If the end of file is reached all data until the end of the file is returned. The Server is allowed to return less data than specified length.

Only positive values are allowed.

DataContains the returned data of the file. If the ByteString is empty it indicates that the end of the file is reached.

Method Result Codes (defined in Call Service)

Result Code Description
Bad_InvalidArgumentSee OPC 10000-4 Invalid file handle in call or non-positive length.
Bad_UnexpectedErrorSee OPC 10000-4 for a general description.
Bad_InvalidStateSee OPC 10000-4 for a general description. File was not opened for read access.

Table 4 specifies the AddressSpace representation for the Read Method.

Table 4 – Read Method AddressSpace definition
Attribute Value
BrowseNameRead
References NodeClass BrowseName DataType TypeDefinition ModellingRule
HasPropertyVariableInputArgumentsArgument[] PropertyTypeMandatory
HasPropertyVariableOutputArgumentsArgument[] PropertyTypeMandatory
Conformance Units
Base Info FileType Base

4.2.5 Write

Write is used to write a part of the file starting from the current file position. The file position is advanced by the number of bytes written.

Signature

	Write(
		 [in] UInt32 fileHandle
		 [in] ByteString data
		);
Argument Description
fileHandleA handle indicating the access request and thus indirectly the position inside the file.
data

Contains the data to be written at the position of the file. It is server-dependent whether the written data are persistently stored if the session is ended without calling the Close Method with the fileHandle.

Writing an empty or null ByteString returns a Good result code without any affect on the file.

Method Result Codes (defined in Call Service)

Result Code Description
Bad_InvalidArgumentSee OPC 10000-4 for a general description. Invalid file handle in call.
Bad_NotWritableSee OPC 10000-4 for a general description. File might be locked and thus not writable.
Bad_InvalidStateSee OPC 10000-4 for a general description. File was not opened for write access.

Table 5 specifies the AddressSpace representation for the Write Method.

Table 5 – Write Method AddressSpace definition
Attribute Value
BrowseNameWrite
References NodeClass BrowseName DataType TypeDefinition ModellingRule
HasPropertyVariableInputArgumentsArgument[] PropertyTypeMandatory
Conformance Units
Base Info FileType Base

4.2.6 GetPosition

GetPosition is used to provide the current position of the file handle.

Signature

	GetPosition(
		 [in] UInt32 fileHandle
		 [out] UInt64 position
		);
Argument Description
fileHandleA handle indicating the access request and thus indirectly the position inside the file.
PositionThe position of the fileHandle in the file. If a Read or Write is called it starts at that position.

Method Result Codes (defined in Call Service)

Result Code Description
Bad_InvalidArgumentSee OPC 10000-4 for a general description. Invalid file handle in call.

Table 6 specifies the AddressSpace representation for the GetPosition Method.

Table 6 – GetPosition Method AddressSpace definition
Attribute Value
BrowseNameGetPosition
References NodeClass BrowseName DataType TypeDefinition ModellingRule
HasPropertyVariableInputArgumentsArgument[] PropertyTypeMandatory
HasPropertyVariableOutputArgumentsArgument[] PropertyTypeMandatory
Conformance Units
Base Info FileType Base

4.2.7 SetPosition

SetPosition is used to set the current position of the file handle.

Signature

	SetPosition(
		 [in] UInt32 fileHandle
		 [in] UInt64 position
		);
Argument Description
fileHandleA handle indicating the access request and thus indirectly the position inside the file.
PositionThe position to be set for the fileHandle in the file. If a Read or Write is called it starts at that position. If the position is higher than the file size the position is set to the end of the file.

Method Result Codes (defined in Call Service)

Result Code Description
Bad_InvalidArgumentSee OPC 10000-4 for a general description. Invalid file handle in call.

Table 7 specifies the AddressSpace representation for the SetPosition Method.

Table 7 – SetPosition Method AddressSpace definition
Attribute Value
BrowseNameSetPosition
References NodeClass BrowseName DataType TypeDefinition ModellingRule
HasPropertyVariableInputArgumentsArgument[] PropertyTypeMandatory
Conformance Units
Base Info FileType Base