FB_AsciiWriter

 

FB_AsciiWriter - General Information

Overview

Type:

Function block

Available as of:

V1.0.3.0

Inherits from:

-

Implements:

-

Versions:

Current version

Task

Writing of any data structures in a text file.

Description

NOTE: The function block FB_AsciiWriter only works correctly if the used data structures are saved with Pack_Mode = 1.

The function block writes the number of variables of the type specified in i_pbyStructInfo which are entered in i_iCount from memory at the address i_dwBufferAdr to a file.

Writing is started with a positive edge at i_xExecute and stopped after an error is detected or after all data has been written successfully. During writing, no parameter (other than i_xExecute) may be changed. Also, that memory area which i_dwBufferAdr points to may not be written to.

The file that is created can be read with any editor.

Interface

Input

Data type

Description

i_xExecute

BOOL

FALSE -> TRUE: POU is activated. The writing procedure begins.

i_sFileName

STRING[80]

Name of the text file where the variable should be written to.

i_iCount

INT

Maximum number of records that should be written.

i_dwBufferAdr

DWORD

Address of the array where the data is read. The respective amount of memory must be reserved.

a: ARRAY [0..i_iCount-1] OF Struct

BufferAdr:=adr(a);

i_pbyStructInfo

POINTER TO BYTE

Start address of the string with the description of a record in the structure. The standard type of the individual variables are separated by a comma.

e.g. 'BOOL,DWORD,USINT'

i_pbyStructNames

POINTER TO BYTE

Description of the individual elements of the ARRAY. The variable names of the individual variables are separated by commas. The names of the individual StructVariables will be written in the first line, separated by tabs.

The variable must be empty when the first line should not be written with the variable name.

Each of the remaining lines represents one Struct whose variable values are displayed in the appropriate format and are separated by tabs. The ends of lines are each indicated by CRLF.

i_etMode

ET_WriteMode

If ET_WriteMode.Create mode is chosen, the file will be created anew. If a file with the same name already exists, it will be overwritten.

If ET_WriteMode.Append mode is chosen, the new data will be appended to the existing file.

Output

Data type

Description

q_xBusy

BOOL

TRUE: Writing is in progress.

q_xDone

BOOL

TRUE: Writing is completed.

q_etDiag

GD.ET_Diag

General library-independent statement on the diagnostic.

A value not equal to ET_Diag.Ok corresponds to an diagnostic message.

q_etDiagExt

ET_DiagExt

POU-specific output on the diagnostic.

q_etDiag = ET_Diag.Ok -> Status message

q_etDiag <> ET_Diag.Ok -> Diagnostic message

q_sMsg

STRING[80]

Event-triggered message which gives more detailed information on the diagnostic state.

q_udiUsedMemory

UDINT

Number of bytes read from the memory.

q_udiUsedDiskSpace

UDINT

Number of bytes written into the memory.

Example

{attribute 'pack_mode' := '1'}
TYPE ST_MyType :
STRUCT
sName : STRING[30];
sStreet : STRING[20];
lrValue : LREAL;
END_STRUCT
END_TYPE

VAR
fbAsciiWriter : FB_AsciiWriter;
aMyType : ARRAY[0..99] OF ST_MyType;
sStructTypes : STRING := 'STRING[30], STRING[20], LREAL';
sStructNames : STRING := 'Name, Street, Value';
END_VAR

fbAsciiWriter(i_xExecute := TRUE,
i_sFileName := 'Data',
i_iCount := 100,
i_dwBufferAdr := ADR(aMyType),
i_pbyStructInfo := ADR(sStructTypes),
i_pbyStructNames := ADR(sStructNames),
i_etMode := ET_WriteMode.Create);

Diagnostic Messages

q_etDiag

q_etDiagExt

Enumeration value

Description

OK

Executing

128

Version

OK

WaitForExecute

180

Wait for execution.

FileHandlingInvalid

CanNotOpenFile

112

The file cannot be opened.

FileHandlingInvalid

TooManyFilesOpen

105

Too many files are opened.

InputParameterInvalid

StructInfoInvalid

40

The StructInfo is invalid.

InputParameterInvalid

UnknownMode

111

The Mode is indeterminable.

UnexpectedProgramBehavior

UnexpectedFeedback

1

An unintended detected error occurred during execution.

CanNotOpenFile

Enumeration name:

CanNotOpenFile

Enumeration value:

112

Description:

The file cannot be opened.

Issue

Cause

Solution

-

The file i_sFileName could not be opened.

Verify whether the file called i_sFileName is stored on the data carrier.

Verify data carrier for defects.

Executing

Enumeration name:

Executing

Enumeration value:

128

Description:

Version

Data are being written.

StructInfoInvalid

Enumeration name:

StructInfoInvalid

Enumeration value:

40

Description:

The StructInfo is invalid.

Issue

Cause

Solution

-

At the memory address which the input i_pbyStructInfo points to, no valid structure data are applied.

Verify the data of the string that is transferred via the pointer.

Verify the address that is transferred at the input i_pbyStructInfo.

TooManyFilesOpen

Enumeration name:

TooManyFilesOpen

Enumeration value:

105

Description:

Too many files are opened.

Issue

Cause

Solution

-

Too many files are opened.

Close files that are no longer needed using SystemInterface.FC_CloseFile.

UnexpectedFeedback

Enumeration name:

UnexpectedFeedback

Enumeration value:

1

Description:

An unintended detected error occurred during execution.

Issue

Cause

Solution

-

An error occurred in the internal execution.

An error occurred in the internal execution.

UnknownMode

Enumeration name:

UnknownMode

Enumeration value:

111

Description:

The Mode is indeterminable.

Issue

Cause

Solution

-

At the input i_etMode, an invalid value has been applied.

At the input i_etMode, an element of the enumeration ET_WriteMode must be applied.

WaitForExecute

Enumeration name:

WaitForExecute

Enumeration value:

180

Description:

Wait for execution.

The function block is ready. As reaction to a positive edge from i_xExecute, the data is written.