File Access
This group contains function blocks for reading and writing data on the file system.
Function blocks
Images
Container
Machine learning models
Calibration pattern
Function initialization
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.
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.
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 (!fbReadOrWrite.bBusy)
{
// Function block execution is complete or error occurred.
// Next write-command can be issued.
}
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 (0x71E)
if the function block is busy (bBusy == true
).
The hexadecimal value of the error code can be extracted as follows:
if (fbReadOrWrite.bError)
{
// Show relevant error code for debugging purposes:
nErrorCode = fbReadOrWrite.nErrorId & 0xFFF;
}
The most frequent error codes are:
Hex | Dec | Name | Meaning |
---|---|---|---|
|
|
| ADS server not reachable. Essentially occurs when the TwinCAT Vision Service has not started. See Vision Service doesn't start. |
|
|
| 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. |
|
|
| Invalid parameter. This usually indicates that the interface pointer is invalid. |
|
|
| Timeout. Loading or saving has exceeded the maximum execution time |
|
|
| Not really an error, therefore the output |