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.
Solved! Go to Solution.
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.
Yes we did some projects where we implemented such stuff in the PLC, as described above.
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 ?
Which method you have used ?
Where is the file located on the system / in the data layer ?
Thanks for the help 🙂
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:
PROGRAM WriteFile VAR 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; 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
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.
Moved to own topic.