Write data to SD card
This FP instruction reads the number of data specified by n_NumberOfDataToWrite stored at the address starting with s_Start, and writes the data to the file specified by d1_FullFileName on the SD card. The DUT FP_SD_WRITE_DUT at d2_dutWrite specifies the writing parameters.
Input
Starting address
Number of of data to write, specified by DUT member udiNumberOfDataWritten
For wFormat=1–8: Number of 16-bit/32-bit comma-separated data
For wFormat=10: Number of 8-bit characters
For wFormat=11: Number of 16-bit data
File name with extension, e.g. '\Test.csv'
Input/output
Writing format, writing mode, pointer position, etc.
If a pointer mode has been selected in FP_SD_WRITE_DUT at s2_dutWrite (wMode=2 or wMode=3), writing is started at the position of the pointer. After writing, the pointer moves to the position where writing has been completed. The next writing operation will start from this point.The position of the pointer can also be specified by udiBytePosition in the DUT. In the example below, file pointer positions are indicated for different data formats.
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.
When the file attribute is read-only, no data can be written.
When saving ASCII data, written character strings are enclosed in double quotation marks.
A double quotation mark (") in character strings is converted to two double quotation marks ("").
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*)
sStringWrite1: STRING[32]:='Test String1';
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,,ø^Write string ASCII data into 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!,,18,0,24,4,,?DEN?D?AENO?C);
B(B_VARIN,,10,16,2,18,4,);
B(B_VAROUT,,dutFpWriteTest_csv.wFormat,24,2,26,4,);
L(1,2,2,2);
L(4,2,10,2);
L(12,2,18,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,,sStringWrite,16,2,18,4,);
B(B_CONTACT,,bStart,2,1,4,3,R);
B(B_VARIN,,sFile_Test_Csv,16,4,18,6,);
B(B_VARIN,,dutFpWriteTest_csv,16,5,18,7,);
B(B_CONTACT,,sys_bIsSDMemoryAccessActive,10,1,12,3,N);
B(B_F,FP_SD_WRITE!,,18,0,31,7,,?DEN?Ds_Start?Dn_NumberOfDataToWrite?Dd1_FullFileName?Dd2_dutWrite?Ad2_dutWrite?AENO);
B(B_VARIN,,iStringLength,16,3,18,5,);
L(1,2,2,2);
L(4,2,10,2);
L(12,2,18,2);
L(1,0,1,7);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF DF(bStart)AND not sys_bIsSDMemoryAccessActive then
dutFpWriteTest_csv.wFormat:=10;
FP_SD_WRITE(s_Start := sStringWrite,
n_NumberOfDataToWrite := iStringLength,
d1_FullFileName := sFile_Test_Csv,
d2_dutWrite := dutFpWriteTest_csv);
END_IF;