File Access

This group contains function blocks for reading and writing data on the file system.

General

These function blocks work asynchronously; the time from the first execution to the desired result extends over several cycles. The actual duration of each read/write operation depends on several factors, such as the size of the image and the behavior of the operating system. The following parameters are the same for all function blocks and are therefore described here once centrally.

Parameter

File path

The file path sFilePath specifies where to save a file or which file to load. Absolute and relative paths can be used. In the case of relative paths, the default paths set in the Service Configuration are used as the basis.

File Access 1:

Path length

The type of the sFilePath is specified as STRING, but paths with a length of up to 255 characters can be passed.

The file path is stored internally on a rising edge of the write command bWrite so that changes to the path in later cycles have no effect.

Execute the function

The triggers for write and read commands are bWrite and bRead respectively. They are triggered by a rising edge (change from FALSE to TRUE). The relevant input parameters are saved internally so that a parameter change during the execution has no effect. A falling edge of the trigger likewise has no effect.

File Access 2:

Calling function blocks

Please note that the description of parameters for function blocks only has an effect if the function blocks are actually called.

Timeout

So as not to have to wait a long time for the execution of the function block in the case of an unknown error, the maximum permitted execution time can be set with nTimeout. The execution will be aborted if this time is exceeded without a successful result after triggering the command trigger. The timeout error is then recognizable by the two outputs bError and nErrorId.

Working state

The output bBusy indicates whether the function block is busy. No new command can be triggered if bBusy = TRUE.

By means of a suitable IF query it is possible to determine whether the execution of the function block is completed:

IF NOT fbReadOrWrite.bBusy THEN
    // Function block execution is complete or error occurred.
    // Next write-command can be issued.
END_IF

Error state

The error state is indicated by bError binarily indicating an error and nErrorId outputting the error code (ADS Return Code) if applicable. The error state is reset as soon as a new command is triggered. The error code is PENDING (16#71E) if the function block is busy (bBusy = TRUE).

The hexadecimal value of the error code can be extracted as follows:

IF fbReadOrWrite.bError THEN
    // Show relevant error code for debugging purposes:
    nErrorCode := fbReadOrWrite.nErrorId AND 16#FFF;
END_IF

The most frequent error codes are:

Hex

Dec

Name

Meaning

16#006

6

TARGETPORTNOTFOUND

ADS server not reachable. Essentially occurs when the TwinCAT Vision Service has not started. See Vision Service doesn't start.

16#700

1792

ERROR

General error if saving or loading fails. This usually indicates that the specified file format is not supported or that the file path is unreachable.

The error usually occurs in the TwinCAT Vision Service.

16#70B

1803

INVALIDPARM

Invalid parameter. This usually indicates that the interface pointer is invalid.

16#719

1817

TIMEOUT

Timeout. Loading or saving has exceeded the maximum execution time nTimeout. In general, this occurs mainly with a heavy load on ADS.

16#71E

1822

PENDING

Not really an error, therefore the output bError is not set here. This code signals that the function block is busy. It occurs in parallel to the output bBusy if a new rising edge is registered while the function block is busy.

Examples