Read binary data from SD card
This FP instruction reads the number of words specified by n_Words from the binary format file specified by the file number s_FileNumber on the SD card. The directory name is \data and the file name is dtxxx.bin where "xxx" is the file number. 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 number (0–999)
Number of words (0–65535)
Output
Starting address
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.
If there is no directory \data or if there is no file with the specified file number in the directory, an error occurs.
If the number of data in the file is less than the number of data to be read, data is read up to the number of data in the file.
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.
With a Data Unit Type (DUT) you can define a data unit type that is composed of other data types. A DUT is first defined in the DUT pool and then processed like the standard data types (BOOL, INT, etc.) in the list of global variables or the POU header.
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*)
dutValuesRead: DUT_VALUES;
iFileNumberDut: INT:=2;
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.
eneral">BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 9 ;
NETWORK_BODY
B(B_CONTACT,,sys_bIsSDMemoryAccessActive,10,2,12,4,N);
B(B_CONTACT,,bStart,2,2,4,4,R);
B(B_VARIN,,iFileNumberDut,14,5,16,7,);
B(B_F,FP_SD_READ_BIN!,,16,3,27,8,,?DEN?Ds_FileNumber?Dn_Words?AENO?Cd_Start);
B(B_F,Size_Of_Var!,,9,6,16,8,,?D?C);
B(B_VARIN,,dutValuesRead,7,6,9,8,);
B(B_F,Adr_Of_Var_O!,,27,5,35,7,,?D?C);
B(B_VAROUT,,dutValuesRead,35,5,37,7,);
L(1,3,2,3);
L(4,3,10,3);
L(12,3,12,5);
L(12,5,16,5);
L(1,0,1,9);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF DF(bStart)AND not sys_bIsSDMemoryAccessActive then
FP_SD_READ_BIN(s_FileNumber := iFileNumberDut,
n_Words := Size_Of_Var(dutValuesRead),
d_Start => Adr_Of_Var(dutValuesRead));
END_IF;