in my program some files are opened at the beginning and data is continually written to and read from these files. The files are closed before ENDPROC.
How can these files be closed when the user stops execution of the program? UNDO doesn’t work in this case.
You need to have a background task (which runs continuously while the controller is powered) to manage communication with the files.
Your foreground task would pass data to the background task for writing.
The background task would monitor execution of the foreground task and close the files when execution stops.
You will need the ‘Multitasking’ RobotWare option in your controller in order to do this.
…if you don’t have Multitasking, take a look at Event Routines for the “STOP” event. This is a way to trig a Rapid routine when a specific event occur. Event routines are set up in the Controller section of the System parameters. It might be a good idea to declare the routine in a system module.