Showing results for 
Search instead for 
Did you mean: 

Data Logging with CtrlX

Data Logging with CtrlX



for a Test Project i need to log some Data from a Sensor. 

The data come from a IO-Link device in cycle time of 5ms . So i guess every 3 PLC cycle i want to record 16 Bytes (1 measurement)

I need around 10000 measurements . 

I thought over the IDE App in Python or directly in Codesys.

I am little bit concerned about the storage and the record speed/ rate. 

How is the most efficent way to do this ? Is there anyone who already have done this. 

Any approach or example is helpful

Thanks in advanced. 

Best regards

Christoph Hund



Community Moderator
Community Moderator

As python cannot really be connected to a bus cycle in your case I would suggest to use the PLC. Create a task with the cycle time needed by you (e.g. 5ms). Setup an array with 10k variables space and go.

Of course you could also use python or data bases / cloud connector apps for this e.g. via the Bosch - DeviceBridge, Cedalo - Eclipse Mosquitto MQTT Broker or ctrlX CORE - Node-RED App.

Yes we did some projects where we implemented such stuff in the PLC, as described above.

  • Data size is 16Bytes * 100 000 Measures = 160 kByte no problem for the PLC.
  • When your measurement is finished you can store it to a disc. e.g. A csv file for analysing it e.g. in Excel.

Cool , Thanks for the Feedback. 
Works pretty good so far. 
I have now made an Array for test purpose with a size of 10000. 

Which way approach is the best from here ?

  • Write the array in a file i guess.

Which method you have used ?
Where is the file located on the system / in the data layer ?

Thanks for the help 🙂 

Community Moderator
Community Moderator

Use library CXA_FileAsync with FB IL_FileWriteAsync. Have a look into the libaries FB, where you find an example, how to use it.


The plc app only has access to the active configuration folder of the plc app. So just provide a relative name (without a "/" at start) like "myFile.cvs" or "data/myFile.csv"

Use PLC Engineering to browse this folder.

Double click on (1) Select tab "Files" (2) Click on "Refresh" (3)



You can additionally access the app data (activeConfiguration). See the modified example from the CXA_FileAsyn library:


  fbFile: CXA_FileAsync.IL_FileAsync;
  fbFileWrite: CXA_FileAsync.IL_FileWriteAsync;
  filename: STRING := '/var/snap/rexroth-solutions/common/solutions/activeConfiguration/testfile.txt';
  itestcase: UINT := 0;
  writebuf: STRING(500);
  writebuflen: UDINT := 500;
  writelen: UDINT := 0;


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;

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
    itestcase := itestcase + 1;

3: // close file
  If NOT fbFile.Shutdown AND NOT fbFile.InOperation THEN
    itestcase := 0;

IF fbFileWrite.Error OR fbFile.Error THEN
  ; // post some error


Thanks for your help works everthing like expected with the file writeing. 

But it is strange that i only get each 200ms new Data from the BUS even the Cycle Time is 5ms and i have set the Buscycle Option to the Main Task. 


Is there anything which i do not cover at the moment ? 

Thanks for all your help. 


Occasional Contributor

Hi, please check cycle time of the Main Task or your PLC Task, by Default it's set to 200ms