CSV Reader Library for the PAC

The library posted here contains a function block called CSV_READER that parses a CSV file into a two-dimensional array of strings.

pastedimage1623427320207v1_4766-20240521-000917.png

 

The inputs and outputs are described below.

Direction

Data Type

Default Value

Description

In/Outs

 

 

 

astrCSVData

ARRAY [*,*] OF STRING(255)

 

Each CSV cell will be loaded into its own element in this array.  The array can be any size.  If it is too small to hold the entire CSV file, no error will be thrown.  The addresses are in column, row format.

abyIgnoreList

ARRAY [*] OF BYTE

 

Array of characters to ignore.  Not mandatory.

Inputs

 

 

 

bExecute

BOOL

 

Begin reading CSV file on a rising edge.

strFileName

STRING(255)

 

Full file path and file name with extension, using "/" to separate directories.  Example: "/Hard Disk2/Job Lists/list_12.csv".  The files do not need to have a CSV extension and can use any extension desired.

byColSep

BYTE

44 (Comma)

Character used to separate columns.  Uses ASCII character specification.  Default is 44 (comma).  For tab, use 9.  For semicolon, use 59.  Can use any ASCII character as long as it is not the one used for byRowSep.

byRowSep

BYTE

13 (Carriage Return)

Character used to separate rows.  Uses ASCII character specification.  Default is 13 (carriage return).  For line feed, use 10.  For semicolon, use 59.  Can use any ASCII character as long as it is not the one used for byColSep.

Outputs

 

 

 

bDone

BOOL

 

Entire CSV file has been read into the array or entire array has been filled.

bError

BOOL

 

Error occurred.

eError

CSV_ERRORS

 

Error code.

This function block must not be used in the EtherCAT_Master task as it performs file access and is therefore non-deterministic.

Link to CSV Reader Library

11JUN2021 DCLIFFE