FB_AsciiReader

 

FB_AsciiReader - General Information

Overview

Type:

Function block

Available as of:

V1.7.0.0

Inherits from:

-

Implements:

-

Versions:

Current version

Task

Reading a variables table from a file

Description

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

The function reads the number of variables of the type specified in i_pbyStructInfo which is indicated in i_iCount from a text file into the memory at the address specified in i_dwBufferAdr.

Reading is started with a positive edge at i_xExecute and stopped after an error is detected or after all data has been read successfully. During reading, 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 first has to be created with FB_AsciiWriter or any other editor and has to have the following format:

oOptional header with maximum 10 lines with, for example, comments, variable names, column headers, and so on. See also inputs i_xStructNames and i_uiLinesOfHeader.

oEach further line must contain a value for all variables of the structure in the respective format.

oThe individual values should be separated by tabs and each end of line marked by CRLF.

Interface

Input

Data type

Description

i_xExecute

BOOL

FALSE -> TRUE: POU is activated. The reading process begins.

i_sFileName

STRING

Name of the text file where the variable should be read from.

i_iCount

INT

Maximum number of records that should be read.

i_dwBufferAdr

DWORD

Address of the array where the data should be stored. 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_xStructNames

BOOL

TRUE: The number of lines defined by i_uiLinesOfHeader in the file will be disregarded. This is required if the file was created with HYPERLINK "54043196593213067.html"FB_AsciiWriter and, in addition to the data, variable names were saved or if the file was created with Excel and the column headers were also saved.

i_uiLinesOfHeader

BOOL

Number of lines at the beginning of the file which will be disregarded if i_xStructNames = TRUE.

Default value = 1

Range = 1...10

Output

Data type

Description

q_xBusy

BOOL

TRUE: Reading is in progress.

q_xDone

BOOL

Reading 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 written bytes in the memory.

q_udiUsedDiskSpace

UDINT

Number of bytes read out of the file.

Example

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

VAR
fbAsciiReader : FB_AsciiReader;
aMyType : ARRAY[0..99] OF ST_MyType;
END_VAR

fbAsciiReader(i_xExecute := TRUE,
i_sFileName := 'Data',
i_iCount := 100,
i_dwBufferAdr := ADR(aMyType),
i_pbyStructInfo := 'STRING[30], STRING[20], LREAL',
i_xStructNames := TRUE),
i_uiLinesOfHeader := 1);

Diagnostic Messages

q_etDiag

q_etDiagExt

Enumeration value

Description

OK

Executing

128

Version

OK

WaitForExecute

180

Wait for execution.

FileHandlingInvalid

FileNotExisting

104

The file does not exist.

FileHandlingInvalid

FileReadingInvalid

106

Error detected when reading from file.

FileHandlingInvalid

TooManyFilesOpen

105

Too many files are opened.

InputParameterInvalid

StructInfoInvalid

40

The StructInfo is invalid.

InputParameterInvalid

InvalidInputValue

324

The input value is outside the valid range.

UnexpectedProgramBehavior

UnexpectedFeedback

1

An unintended detected error occurred during execution.

Executing

Enumeration name:

Executing

Enumeration value:

128

Description:

Version

The data is being read.

FileNotExisting

Enumeration name:

FileNotExisting

Enumeration value:

104

Description:

The file does not exist.

Issue

Cause

Solution

-

The file does not exist.

Copy the file to the flash disk of the controller.

-

At the input i_sFilename, a file name has been applied that does not exist.

Verify the file name at i_sFilename.

FileReadingInvalid

Enumeration name:

FileReadingInvalid

Enumeration value:

106

Description:

Error detected when reading from file.

Issue

Cause

Solution

-

The file is damaged.

Create the file again.

InvalidInputValue

Enumeration name:

InvalidInputValue

Enumeration value:

324

Description:

The input value is outside the valid range.

Issue

Cause

Solution

-

The value of i_uiLinesOfHeader is invalid.

Verify that the value for i_uiLinesOfHeader is in a range of 1…10.

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.

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 are read out.