FB_VN_WriteImage

FB_VN_WriteImage 1:

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

FB_VN_WriteImage 2: 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.

FB_VN_WriteImage 3: 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.

Weiterführende Informationen

Der Funktionsblock FB_VN_WriteImage speichert ein Bild aus der SPS asynchron in einer Datei.

Parameter

Einige Parameter sind zentral in der Sektion File Access Parameter beschrieben.

Eingangsbild

Das Format des Eingangsbilds ipImage muss mit dem im Dateipfad sFilePath festgelegten Dateiformat zusammenpassen.

FB_VN_WriteImage 4:

Speichern bei steigender Flanke von bWrite

Das Bild wird bei einer steigenden Flanke des Schreib-Befehls intern kopiert. Somit haben Änderungen an dem Bild im folgenden Zyklus keine Auswirkungen. Es wird immer das Bild gespeichert, welches zum Zeitpunkt der steigenden Flanke von bWrite übergeben ist.

Dateipfad und Format

Der Dateipfad sFilePath legt fest, wo das Eingangsbild ipImage gespeichert wird und welches Bildformat dazu verwendet werden soll. Das Bildformat wird automatisch anhand der Dateiendung erkannt. Wenn kein Dateiname angegeben wird, wird dieser automatisch generiert und enthält die aktuelle Zeit. Wenn keine Dateiendung (z. B. .jpg) angegeben wird, wird automatisch die Endung .bmp und damit das BMP-Format verwendet.

Zum Speichern werden folgende Bildformate unterstützt.

Hinweis

Fehlermöglichkeit

Achten Sie darauf, dass das gewählte Bildformat mit dem Format des tatsächlichen Eingangsbildes übereinstimmt. Anderenfalls können Fehler auftreten oder die gespeicherten Bilder fehlerhaft sein.

Hinweis

16 Bit Bilder

Um 16-Bit-Bilder verlustfrei zu speichern, kommen nur das TIF-Format und die TwinCAT Serialisierung in Frage.

Anwendung

Das Speichern eines Bildes in die Datei C:\TcVision\Image.bmp sieht z. B. so aus:

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

Verwandter Funktionsblock: FB_VN_ReadImage zum Laden von Bildern.

Beispiele

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