Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

Parameters_ReadCSV (FUN)

Description

The function reads the given parameter CSV file to a struct array, which is defined by the application.

The pointer to the CSVData structure array is given as an input to the function. The first line describes the column headers.

 

CSV file can be generated with MultiTool Creator.

CSV read functionality is included in MultiTool Creator code template.

 

From library version 4.1.2.0, if start bit is defined to a parameter in CSV file, the Parameters_Edit FB handles the parameter as BOOL. The OD data is however, is as defined in CSV file (i.e. BYTE, WORD or DWORD).

 

 

Inputs

Input variable name

Data type

Description

i_Enable

BOOL

CSV file is read when input is TRUE

i_File

STRING

Absolute file path and name

i_ParameterMaxCount

INT

Maximum number of parameters

i_pCSV

POINTER TO CSVData

Pointer to struct array

i_itfExtraData

IExtraColumnsData

Interface of application specific column handler function block. If not in use set input value to 0.

Return value

Return value

Data type

Description

Parameters_ReadCSV

INT

Amount of parameters read from file. Negative value indicates error:

-1 = File open failed

-2 = Null pointer i_pCSV = 0

Outputs

Output variable name

Data type

Description

o_CSVErrorCode

CSVError

CSV error code

o_CSVErrorLine

INT

Number of CSV line containing error.

 

Example code of Parameters_ReadCSV

This example is for 6000 series units.

 

CSV file can be generated with MultiTool Creator.

CSV read functionality is included in MultiTool Creator code template.

 

The file location in the unit for 6505 and 6510 is /opt/Project/PlcLogic.

In the units 6107, 6200, 6807 and 6112 the location is /opt/user/userapp.

 

Constant Definitions:

 

///Number of parameters in network

G_NUMBER_OF_PARAMETERS_NETWORK1: INT := 100;

 

Definitions:

 

///Parameter CSV configuration parameters

csvData: ARRAY[1..G_NUMBER_OF_PARAMETERS_NETWORK1] OF EPEC_PAR.CSVData;

///CSV file path and name

csvFile: STRING(79) := '/opt/user/userapp/Parameters_NETWORK1.csv';

///CSV error code

errorCode: EPEC_PAR.CSVError;

///Number of CSV line containing error

errorInLine: INT;

// Parameter count read from csv

parCount: INT;

 

Init:

 

parCount := EPEC_PAR.Parameters_ReadCSV(

i_Enable := TRUE,

i_File := csvFile,

i_ParameterMaxCount := G_NUMBER_OF_PARAMETERS_NETWORK1,

i_pCSV := ADR(csvData),

i_itfExtraData := 0,

o_CSVErrorCode => errorCode,

o_CSVErrorLine => errorInLine

);

 

Example code of using application specific column handler function

Constant Definitions:

 

///Number of parameters in network

G_NUMBER_OF_PARAMETERS_NETWORK1: INT := 100;

 

Definitions:

 

///Parameter CSV configuration parameters

csvData: ARRAY[1..G_NUMBER_OF_PARAMETERS_NETWORK1] OF EPEC_PAR.CSVData;

///CSV file path and name

csvFile: STRING(79) := '/opt/user/userapp/Parameters_NETWORK1.csv';

///CSV error code

errorCode: EPEC_PAR.CSVError;

///Number of CSV line containing error

errorInLine: INT;

// Parameter count read from csv

parCount: INT;

 

Extras:ARRAY [1..G_NUMBER_OF_PARAMETERS_NETWORK1] OF Parameters_Extras;  (* Application specific data *)

ExtraColumns: ExtraColumnsData; (*Instance to extra data handler*)

 

Data types:

 

TYPE Parameters_Extras :

STRUCT

    column1 : BYTE; (* Application specific extra data*)

    column2 : INT; (* Application specific extra data*)

END_STRUCT

END_TYPE

 

Function block for interface IExtraColumnsData

Definitions:

 

FUNCTION_BLOCK ExtraColumnsData IMPLEMENTS IExtraColumnsData

VAR_INPUT

END_VAR

VAR_OUTPUT

END_VAR

VAR

END_VAR

 

Code:

 

 

 

Implementing CurrentColumnData method of function block

Definitions:

 

 

METHOD CurrentColumnData : STRING

VAR_INPUT

    i_HeaderData:STRING;

    i_ParameterData:STRING;

    i_CSVRow:INT;

END_VAR

 

Code:

 

IF i_HeaderData = '[Column1Name]' THEN          

Extras[i_CSVRow].column1:= STRING_TO_BYTE(i_ParameterData);

ELSIF i_HeaderData = '[Column2Name]' THEN        

Extras[i_CSVRow].column2:= STRING_TO_INT(i_ParameterData);                                    

END_IF

 

 

Using Parameters_ReadCSV with extra data

Init:

 

parCount := EPEC_PAR.Parameters_ReadCSV(

i_Enable := TRUE,

i_File := csvFile,

i_ParameterMaxCount := G_NUMBER_OF_PARAMETERS_NETWORK1,

i_pCSV := ADR(csvData),

i_itfExtraData := ExtraColumns,

o_CSVErrorCode => errorCode,

o_CSVErrorLine => errorInLine

);

 

 

See also

 

 

Source file topic100518.htm

Last updated 13-Jun-2024