The following example shows how the values read from a CSV file are stored in the buffer provided by the application for further processing.
Content of the file example.csv with delimiter specified as semicolon(;
):
PNo;PName;PValue;PUnit;Description
1;Velo_Max;1500;rpm;maximum velocity of the motor
2;Velo_Min;100;rpm;minimum velocity of the motor
3;Velo_ManMode_Slow;150;rpm;velocity manual mode slow move
4;Velo_ManMode_Fast;600;rpm;velocity manual mode fast move
PROGRAM SR_Example
VAR
fbRead :FFU.FB_CsvRead;
xCmdRead :BOOL;
asCsvTable:ARRAY[0..c_uiNumOfRows-1,0..c_uiNumOfColumns-1] OF STRING(c_uiLengthOfValue);
stCsvTable: FFU.ST_CsvTable;
END_VAR
VAR CONSTANT
c_uiNumOfRows :UINT:= 8;
c_uiNumOfColumns :UINT:= 7;
c_uiLengthOfValue :UINT:= 20;
END_VAR
fbRead.i_stTableReadValues.pbyTable := ADR(asCsvTable);
fbRead.i_stTableReadValues.uiNumOfRows := c_uiNumOfRows;
fbRead.i_stTableReadValues.uiNumOfColumns := c_uiNumOfColumns;
fbRead.i_stTableReadValues.udiSizeOfTable := SIZEOF(asCsvTable);
fbRead.i_stReadParameter.sDelimiter := ';';
fbRead.i_stReadParameter.etReadMode := FFU.ET_CsvReadMode.AllValues;
fbRead.i_stReadParameter.udiNumOfRow := 0;
fbRead.i_stReadParameter.udiNumOfColumn := 0;
fbRead(
i_xExecute:= xCmdRead,
i_sFilePath:= './myfiles/Example.csv',
i_stTableReadValues:= ,
i_stReadParameter:= ,
i_timTimeout:= ,
q_xDone=> ,
q_xBusy=> ,
q_xError=> ,
q_etResult=> ,
q_sResultMsg=> ,
q_stFileInformation=> ,
q_stCsvWarnValueTruncated=> ,
xValueTruncated=> );
The buffer provided by the application contains the elements read from the CSV file:
Array Index |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
---|---|---|---|---|---|---|---|
0 |
PNo |
PName |
PValue |
PUnit |
Description |
– |
– |
1 |
1 |
Velo_Max |
1500 |
rpm |
maximum velocity of |
– |
– |
2 |
2 |
Velo_Min |
100 |
rpm |
minimum velocity of |
– |
– |
3 |
3 |
Velo_ManMode_Slow |
150 |
rpm |
velocity manual mode |
– |
– |
4 |
4 |
Velo_ManMode_Fast |
600 |
rpm |
velocity manual mode |
– |
– |
5 |
– |
– |
– |
– |
– |
– |
– |
6 |
– |
– |
– |
– |
– |
– |
– |
7 |
– |
– |
– |
– |
– |
– |
– |