Read data from SD card
This FP instruction reads the number of data specified by n_NumberOfDataToRead from a file specified by s1_FullFileName on the SD card. The DUT FP_SD_READ_DUT at s2_dutRead specifies the reading parameters. The result is stored in the area specified by d_Start. ASCII code requires 8 bits (1 byte) to express 1 BCD character. Upon conversion to ASCII, the data length will thus be twice the length of the source data.
Input
File name
Number of data to be read
Values:
0–65535 (16-bit data)
0–32767 (32-bit data)
0–1999 (character string)
Input/output
Reading format, reading mode, pointer position, etc.
Output
Starting address
If a pointer mode has been selected in FP_SD_READ_DUT at s2_dutRead (wMode=2 or wMode=3), reading is started at the position of the pointer. After reading, the pointer moves to the position where reading has been completed. The next reading operation will start from this point.The position of the pointer can also be specified by udiBytePosition in the DUT. In the examples below, the arrows indicate valid pointer positions:
16-bit INT data (BIN format file): |
ASCII data (CSV format file): |
---|---|
In CSV files, the pointer always moves to the position next to a space, comma or line break. Spaces, commas and line breaks at the end of data are skipped.
Please also refer to precautions for SD card access.
The SD memory access active flag (sys_bIsSDMemoryAccessActive) turns to TRUE after the trigger EN of the SD card instruction has turned to TRUE and remains TRUE until execution has completed. During this time, other SD card instructions cannot be executed.
The SD memory access done flag (sys_blsSDMemoryAccessDone) is FALSE when the instruction is executed and turns to TRUE and remains TRUE when the instruction is completed.
Do not read the data from the output area until execution of the instruction is completed.
Two successive double quotation marks ("") in character strings are read as one character ("). One double quotation mark by itself is ignored.
In CSV files, null fields (e.g. parts with successive commas) are counted as part of the number of data to read, but the data is not stored.
FALSE: when the instruction has completed without error
TRUE: when the instruction has completed with an error
Use sys_iSDMemoryAccessErrorCode to evaluate the error code.
if the area specified using the index modifier exceeds the limit.
if the area specified using the index modifier exceeds the limit.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
bStart: BOOL:=FALSE;
(*activates the instruction*)
sFile_Test_Csv: STRING[32]:='\Test.csv';
dutFpReadTest_csv: FP_SD_READ_DUT;
sStringRead: STRING[32]:='';
iStringLengthRead: INT:=0;
END_VAR
When the variable bStart changes from FALSE to TRUE and the system variable sys_bIsSDMemoryAccessActive is not TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_COMMENT,,ø^Read string ASCII data from SD card memory - ASCII value,3,0,58,3,);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 4 ;
NETWORK_BODY
B(B_CONTACT,,bStart,2,1,4,3,R);
B(B_CONTACT,,sys_bIsSDMemoryAccessActive,10,1,12,3,N);
B(B_F,E_MOVE!,,17,0,23,4,,?DEN?D?AENO?C);
B(B_VARIN,,10,15,2,17,4,);
B(B_VAROUT,,dutFpReadTest_csv.wFormat,23,2,25,4,);
L(1,2,2,2);
L(4,2,10,2);
L(12,2,17,2);
L(1,0,1,4);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 7 ;
NETWORK_BODY
B(B_VARIN,,sFile_Test_Csv,15,3,17,5,);
B(B_VAROUT,,sStringRead,30,3,32,5,);
B(B_VARIN,,dutFpReadTest_csv,15,5,17,7,);
B(B_CONTACT,,bStart,2,1,4,3,R);
B(B_CONTACT,,sys_bIsSDMemoryAccessActive,10,1,12,3,N);
B(B_F,FP_SD_READ!,,17,1,30,7,,?DEN?Ds1_FullFileName?Dn_NumberOfDataToRead?Ds2_dutRead?As2_dutRead?AENO?Cd_Start);
B(B_VARIN,,iStringLengthRead,15,4,17,6,);
L(1,2,2,2);
L(4,2,10,2);
L(12,2,12,3);
L(12,3,17,3);
L(1,0,1,7);
END_NETWORK_BODY
END_NET_WORK
END_BODY
eneral">(* Read string ASCII data from SD card memory - ASCII value *)
IF DF(bStart)And not sys_bIsSDMemoryAccessActive then
dutFpReadTest_csv.wFormat:=10;
FP_SD_READ(s1_FullFileName := sFile_Test_Csv,
n_NumberOfDataToRead := iStringLengthRead,
s2_dutRead := dutFpReadTest_csv,
d_Start => sStringRead);
END_IF;