FP_SD_WRITE

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.

Parameters

Input

s_Start (ANY)

Starting address

n_NumberOfDataToWrite (WORD, INT, UINT)

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

d1_FullFileName (STRING)

File name with extension, e.g. '\Test.csv'

Input/output

d2_dutWrite (FP_SD_WRITE_DUT)

Writing format, writing mode, pointer position, etc.

Pointer mode

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.

  1.  (1) 16-bit INT data (BIN format file)
  2.  (2) 16-bit INT data (CSV format file)
  3.  (3) ASCII data (CSV format file)
  4.  (4) File pointer

Remarks

  • 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 ("").

Error flags

sys_bIsSDMemoryAccessError
  • 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.

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.

Example

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*)
		sStringWrite1: STRING[32]:='Test String1';
	END_VAR

POU body

When the variable bStart changes from FALSE to TRUE and the system variable sys_bIsSDMemoryAccessActive is not TRUE, the function is carried out.

LD body

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

ST 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;

Modified on: 2024-03-06Feedback on this pagePanasonic hotline