save & write the log data and PLC project on the µSD

Customer is asking if they can save & write the log data and PLC project into the inserted micro sd card during operation. Is there any example or how-to ?

Best reply by TheCodeCaptain

Hi Sophie,

you can read/write from the PLC or other apps like NodeRED to the memory card or usb-stick by using this path:

/media/mmcblk1p1/testfile.txt

The name of your device could be different and can be found in the ui under Settings-->Storage.

The PLC boot project is saved in the active configuration which is not on the memory card.

Find attached a plc example.

ROGRAM FileWriteAsync_PRG
VAR
  fbFile: CXA_FileAsync.IL_FileAsync;
  fbFileWrite: CXA_FileAsync.IL_FileWriteAsync;
  filename: STRING := '/media/mmcblk1p1/testfile.txt'; // /var/snap/ctrlx-node-red/current/solutions/activeConfiguration/plc/run/linux-gcc-aarch64/data/myfilename.txt
  itestcase: UINT := 0;
  writebuf: STRING(500);
  writebuflen: UDINT := 500;
  writelen: UDINT := 0;
END_VAR


CASE itestcase OF
1: // open the file
  fbFile(Enable:=TRUE, FileName:=ADR(filename), Mode:=IL_FILE_ACCESS_MODE.AM_WRITE);
  IF fbFile.InOperation THEN
    itestcase := itestcase + 1;
  END_IF

2: // write the file
  writebuf := 'BoschRexroth$R$NCtrlX Automation$R$NCXA_FileAsync$R$N';
  writebuflen := IL_LEN(ADR(writebuf));

  fbFileWrite(Execute:=TRUE, FileHandle:=fbFile.FileHandle, BufferAddr:=ADR(writebuf), BufferSize:=writebuflen, BytesWritten=>writelen);
  IF fbFileWrite.Done THEN
    fbFileWrite(Execute:=FALSE);
    itestcase := itestcase + 1;
  END_IF

3: // close file
  fbFile(Enable:=FALSE);
  If NOT fbFile.Shutdown AND NOT fbFile.InOperation THEN
    itestcase := 0;
  END_IF
END_CASE

IF fbFileWrite.Error OR fbFile.Error THEN
  ; // post some error
END_IF
WriteToStorage.txt
1.18KB
View original
4 replies