0

I am using an automation device (equipped with CODESYS) to calculate the output value of a function block. In order to make sure the function work as it should do we would like to compare this output value with the output result of another function block, that we didn't write.

In order to report the result of this comparison, we would like to have the two values mentioned above drawn in the form of graph. Therefore, we need to have a time-string of these two data (in csv or any other format). I did some google research and also take a look at this question. There seems to be not large amount of information on how to do file I/O using CODESYS.

I am wondering if anybody has had similar experience (performing a synchronous file I/O to generate CSV data).

Any idea is highly appreciated. Thanks.

aghd
  • 685
  • 2
  • 9
  • 20

2 Answers2

2

See the FILE library: https://help.codesys.com/webapp/Examples;product=CAA_FILE;version=3.5.11.0

Basically what you have to do is:

  1. Create a data buffer for you CSV lines, for example
    LineArray : ARRAY[1..100] OF STRING[255].
  2. Save the measured values to the string buffer with some interval. Use CONCAT and REAL_TO_STRING to create a valid CSV line.

  3. At the same time, open the file with FILE.Open function block

  4. Use the opened file handle to write data to the file (FILE.Write) from the buffer. Remember to shift the buffer after writing with for example MemCpy.

  5. After all the lines are written, use FILE.Close.

Quirzo
  • 1,183
  • 8
  • 10
  • Thanks Quirzo. Wondering if you have any similar example. – aghd Aug 21 '17 at 20:38
  • I have only coded something similar with TwinCAT blocks. There is some examples for TwinCAT file blocks, but they work quite similar (open, write, close etc.). [Link to Beckhoff's page](https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclibsystem/html/tcplclibsys_fileio_example.htm&id=) – Quirzo Aug 23 '17 at 05:19
0

The question is asked recently in Dr. Alizadeh tutorial series on Codesys. Here is a link to it. It basically narrows than to using Codesys trace functionality.

aghd
  • 685
  • 2
  • 9
  • 20