FB_VN_WriteContainer

FB_VN_WriteContainer 1:

This FB writes a container as an xml file to the hard drive.

Syntax

Definition:

FUNCTION_BLOCK FB_VN_WriteContainer
VAR_INPUT
    ipContainer   : Reference To ITcVnContainer;
    sFilePath     : STRING;
    eExportFormat : ETcVnContainerExportFormat;
    bWrite        : BOOL;
    nTimeout      : TIME;
END_VAR
VAR_OUTPUT
    bBusy         : BOOL;
    bError        : BOOL;
    nErrorId      : UDINT;
END_VAR

FB_VN_WriteContainer 2: Inputs

Name

Type

Default

Description

ipContainer

Reference To ITcVnContainer

 

The container 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).

eExportFormat

ETcVnContainerExportFormat

TCVN_CEF_XML

Container export format (default is human readable xml)

bWrite

BOOL

 

Writing the container is triggered by a rising edge at this input.

nTimeout

TIME

VISION_ADS_TIMEOUT

Indicates the time before the function is cancelled.

FB_VN_WriteContainer 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_WriteContainer speichert einen Container aus der SPS asynchron in einer Datei.

Parameter

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

Container

Der Container ipContainer wird unter dem angegebenen Dateipfad als XML-Datei gespeichert.

Export-Format

Das Export-Format eExportFormat legt über das Enum ETcVnContainerExportFormat fest, ob der Container in menschenlesbarer Form oder serialisiert gespeichert werden soll:

Die menschenlesbare Form (XML, CSV) hat den Vorteil, dass Einträge des Containers einfach per Hand überprüft und editiert werden können. Allerdings kann es zu Rundungsungenauigkeiten kommen. Das serialisierte Format hat den Vorteil, dass keine Rundungsungenauigkeiten auftreten. Jedoch ist das Format nicht gut lesbar oder editierbar. Das CSV-Format hat den Vorteil, dass die Daten extern in anderen Programmen einfach weiterverarbeitet werden können. Das Binärformat empfiehlt sich bei großen Datenmengen.

Anwendung

Das Speichern eines Containers im serialisierten XML-Format in die Datei C:\TcVision\Container.xml sieht z. B. so aus:

fbWriteContainer(
    ipContainer     := ipContainer,
    sFilePath       := 'C:\TcVision\Container.xml',
    eExportFormat   := TCVN_CEF_XML_SERIALIZED,
    bWrite          := TRUE,
    nTimeout        := T#500MS);

IF NOT fbWriteContainer.bBusy AND NOT fbWriteContainer.bError THEN
    // container was written successfully to file
END_IF

Verwandter Funktionsblock: FB_VN_ReadContainer.

Required License

TC3 Vision Base

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1. 4024.44 or later

PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU

Tc3_Vision