FB_VN_WriteImage
This FB writes an image to the hard drive.
Syntax
Definition:
FUNCTION_BLOCK FB_VN_WriteImage
VAR_INPUT
ipImage : Reference To ITcVnImage;
sFilePath : STRING;
bWrite : BOOL;
nTimeout : TIME;
END_VAR
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrorId : UDINT;
END_VAR
Inputs
Name |
Type |
Default |
Description |
---|---|---|---|
ipImage |
Reference To ITcVnImage |
|
The image to write |
sFilePath |
STRING |
|
Full path of the file or relative path to the default directory on the target pc (e.g. only a file name). If the string is empty, a file name will be generated (containing the current time). |
bWrite |
BOOL |
|
Writing the image is triggered by a rising edge at this input. |
nTimeout |
TIME |
VISION_ADS_TIMEOUT |
Indicates the time before the function is cancelled. |
Outputs
Name |
Type |
Description |
---|---|---|
bBusy |
BOOL |
This output remains TRUE until the function block has executed a command, but at the longest for the duration supplied to the 'nTimeout' input. While bBusy = TRUE, no new command will be accepted at the inputs. |
bError |
BOOL |
This output is switched to TRUE as soon as an error occurs during the execution of a command. The command-specific error code is contained in ‘nErrorId’. If the function block has a timeout error, 'bError' is TRUE and 'nErrorId' is 1861 (hexadecimal 0x745). Is reset to FALSE by the execution of a command at the inputs. |
nErrorId |
UDINT |
Contains the ADS error code or the command-specific error code of the last executed command. Is reset to 0 by the execution of a command at the inputs. |
Further information
The function block FB_VN_WriteImage
saves an image from a file asynchronously into the PLC.
Parameter
Some parameters are described centrally in the section File Access Parameters.
Input image
The format of the input image ipImage
must match the file format defined in the file path sFilePath
.
Saving on a rising edge of bWrite The image is copied internally on a rising edge of the write command. Changes to the image in the following cycle thus have no effects. The image transferred at the time of the rising edge of bWrite is always the one that is saved. |
File path and format
The file path sFilePath
specifies where the input image ipImage
is saved and which image format should be used for saving. The image format is automatically recognized on the basis of the file extension. If no file name is specified it is automatically generated and contains the current time. If no file extension (e.g. .jpg
) is specified, the extension .bmp
and thus the BMP format are automatically used.
The following image formats are supported for saving.
- BMP (
.bmp
) - PNG (
.png
) - JPEG (
.jpeg
or.jpg
) - TIF (
.tif
) - TwinCAT serialization (
.tcimg
)
Notice | |
Possibility of errors Make sure that the selected image format corresponds to the format of the actual input image. Otherwise, errors may occur or the saved images may be faulty. |
Notice | |
16-bit images Only the TIF format and the TwinCAT serialization may be used if 16-bit images are to be saved without losses. |
Application
Saving an image to the file C:\TcVision\Image.bmp
looks like this, for example:
fbWriteImage(
ipImage := ipImageRes,
sFilePath := 'C:\TcVision\Image.bmp',
bWrite := TRUE,
nTimeout := T#500MS);
IF NOT fbWriteImage.bBusy AND NOT fbWriteImage.bError THEN
// ipImageRes was successfully written to given file path.
END_IF
Related function block: FB_VN_ReadImage for loading images.
Samples
Required License
TC3 Vision Base
System Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT V3.1.4024.54 or later | PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU | Tc3_Vision |