L'exemple suivant illustre la manière dont les valeurs lues dans un fichier CSV sont stockées dans la mémoire tampon fournie par l'application en vue de leur traitement.
Contenu du fichier example.csv avec le point-virgule (;
) comme séparateur :
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=> );
La mémoire tampon fournie par l'application contient les éléments lus dans le fichier CSV :
Index de tableau |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
---|---|---|---|---|---|---|---|
0 |
PNo |
PName |
PValue |
PUnit |
Description |
– |
– |
1 |
1 |
Velo_Max |
1500 |
1/min |
maximum velocity of |
– |
– |
2 |
2 |
Velo_Min |
100 |
1/min |
minimum velocity of |
– |
– |
3 |
3 |
Velo_ManMode_Slow |
150 |
1/min |
velocity manual mode |
– |
– |
4 |
4 |
Velo_ManMode_Fast |
600 |
1/min |
velocity manual mode |
– |
– |
5 |
– |
– |
– |
– |
– |
– |
– |
6 |
– |
– |
– |
– |
– |
– |
– |
7 |
– |
– |
– |
– |
– |
– |
– |