Use $ACT_TOOL_C or $TOOL_C. But you have to save the value before resettig the program. You can do it with an interrupt.
Thanks! I'll try this.
It should work like it's done in the .SPS because I'm reading the current tool before the CWRITE-Instructions.