How to automatically turn off Digital Output when entering protective stop mode?

I’m using UR10 CB3, with an external Java program to send a script and run on UR.

While running the script, Digital Output 0 will turn on, when accident happens and entered protective stop mode,
Digital Output will not be turned off automatically and causing big troubles.

I know I can set in I/O page for “High when running, Low when stopped.” But that’s not what I want.
Is there any other method for communicating through API and receiving the signal of entering protective stop mode?

Thank you for all your help!

Have you considered RTDE?

No, it’s not easy to switch to RTDE after few years of development using Java