CODESYS - the IEC 61131-3 automation software

How to save sensor values ​​to a file
Page 1 of 1

Author: [ Sun Aug 25, 2019 10:21 am ]
Post subject:  How to save sensor values ​​to a file

Using Raspberry Pi, I can receive sensor values ​​using SPI and Ethernet communication.

But I want to save the received value as a file that can be opened in window instead of being stored in codesys (just like '.txt' or .excel').

Is there a way to do it?

Best regards

Author:  dFx [ Mon Aug 26, 2019 9:15 am ]
Post subject:  Re: How to save sensor values ​​to a file

for built in function see ... n=
or for managing the file format by yourself see ... =

Author:  omeo [ Sat Aug 31, 2019 6:21 am ]
Post subject:  Re: How to save sensor values ​​to a file

I have a simple csv log program use caa.file and systime library.No additional license required.
   sTemplateFileName:FILE.CAA.FILENAME:='C:/Log/template.csv';//template csv head
   xEnable: BOOL;
   arData:ARRAY[1..10] OF REAL;


CASE iState OF
   0://get act date
      IF xStartRecord THEN
         udiResult := SysTimeRtcConvertUtcToLocal(udiUtcTime, udiUtcTimeLocal);
         sFileWriteName:=CONCAT('C:/Log/',RIGHT(DATE_TO_STRING(dtDate),10));//<- need change
         IF udiUtcTimeLocal <> 0 THEN
   10://open act file or create file
      fileOpen(xExecute:=TRUE,sFileName:=sFileWriteName,xExclusive:=FALSE,eFileMode:= File.MODE.MAPPD);
      IF fileOpen.xDone THEN
         iState:=50;//have file
      ELSIF fileOpen.xError THEN
         iState:=20;//no file,create it
   20://create file
      fileCopy(xExecute:=TRUE,sFileNameDest:=sFileWriteName,sFileNameSource:=sTemplateFileName,xOverWrite:= TRUE);
      IF FileCopy.xDone OR FileCopy.xError THEN
   50://generate string
      //write data
      //act local time
      udiResult := SysTimeRtcConvertUtcToLocal(udiUtcTime, udiUtcTimeLocal);
      //add string
      FOR i := 1 TO iDataSize DO
         IF i <> iDataSize THEN
         ELSIF i = iDataSize THEN
   60://write to file
      IF fileWrite.xDone THEN
      ELSIF fileWrite.xError THEN
         iState:= 32767;
         FileWrite(xExecute:= FALSE);
   70://write delay
      IF ton_Delay.Q THEN
      ELSIF xStopRecord THEN
      IF FileClose.xDone OR FileClose.xError THEN

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited