I am part of tractor pulling team and we have Bechoff CX8190 based PLC for data logging. System works most of the time but every now and then saving sensor values (every 10ms is collected) to CSV fails (mostly in middle of csv row). Guy who build the code is new with the TwinCAT and does not know how to find what causes that. Any Ideas where to look reason for this.
-
Not much to work on here. Could you extract the code where the CSV-logging is done and upload it either here or on a GitHub repository? – Jakob Aug 31 '21 at 05:30
-
Does the function block you use to write the csv files output any error code? – Roald Aug 31 '21 at 12:31
-
No, and what is easiest way to add some error code logging to code. system works so that we have a switch that is used to active current to one pin. If there is current in that pin then function block writes to CSV. No we added some delay to that logic so even if there is small cut in current code does not stop. – arip Sep 01 '21 at 07:51
-
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Sep 02 '21 at 20:43
1 Answers
Writing to a file is always a asynchron action in TwinCAT. That is to say this is no realtime action and it is not safe that the writing process is done within the task cycletime of 10ms. Therefore these functionblocks always have a BUSY-output which has to be evaluated and the functionblock has to be called successivly until the BUSY-output returns to FALSE. Only then a new write command can be executed.
I normally tackle this task with a two-side-buffer algorithm. Lets say the buffer-array has 2x100 entries. So fill up the first 100 entries with sample values. Then write them all together with one command to the file. When its done, clean the buffer. In the meanwhile the other half of the buffer can be filled with sample values. If second side is full, write them all together to the file ... and so on. So you have more time for the filesystem access (in the example above 100x10ms=1s) as the 10ms task cycletime.
But this is just a suggestion out of my experience. I agree with the others, some code could really help.