FP_SD_WRITE_LINE

Write one line to a specified file on SD card

This FP instruction writes the string specified by s_In into the file specified by d_FullFileName on the SD card.

Parameters

Input

s_In (STRING)

String

d_FullFileName (STRING)

File name

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.

  • If the specified file does not exist, a new file will be created.

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 := 8 ;
        NETWORK_BODY
B(B_VARIN,,sStringWrite1,11,4,13,6,);
B(B_CONTACT,,bStart,2,1,4,3,R);
B(B_CONTACT,,sys_bIsSDMemoryAccessActive,10,1,12,3,N);
B(B_VARIN,,'\TestLine.csv',11,5,13,7,);
B(B_F,FP_SD_WRITE_LINE!,,13,2,23,7,,?DEN?Ds_In?Dd_FullFileName?AENO);
L(1,2,2,2);
L(4,2,10,2);
L(12,2,12,4);
L(12,4,13,4);
L(1,0,1,8);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF DF(bStart)AND not sys_bIsSDMemoryAccessActive then
    FP_SD_WRITE_LINE(s_In := sStringWrite1,
                     d_FullFileName := '\TestLine.csv');
END_IF;

Example writing multiple lines into an SD card

POU header

All input and output variables used for programming this function have been declared in the POU header.

	VAR
		i: INT:=0;
		asDumpString: ARRAY [0..99] OF STRING[32]:=['1','2','3','4','5','6','7','8',89(''),'z','y','z'];
		dutWriteInfo: FP_SD_WRITE_DUT(wFormat:=11,wMode:=1);
		sDumpString: STRING[3500]:='';
			(*100 * 32 character + separator*)
		bDumpStringArrayToSDCard: BOOL:=FALSE;
		bStoreStringToSDCardFile: BOOL:=FALSE;
	END_VAR

ST body

if (bDumpStringArrayToSDCard AND not(bStoreStringToSDCardFile)) then
	bDumpStringArrayToSDCard := FALSE;
	(* Convert string array to single string *)
	sDumpString := '';
	for i := 0 to Elem_OfArray1D(asDumpString) -1 do
		sDumpString := CONCAT(sDumpString, asDumpString[i], ','); (* delimiter , OR ; *)
	end_for;
	sDumpString := DELETE(IN := sDumpString, L := 1, P := LEN(sDumpString));
	bStoreStringToSDCardFile := TRUE; (* Enable store to SD card *)
end_if;

if (bStoreStringToSDCardFile AND not(sys_bIsSDMemoryAccessActive)) then
	FP_SD_WRITE_LINE(s_In := sDumpString, d_FullFileName := 'Test.csv');
	bStoreStringToSDCardFile := FALSE;
end_if;

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