Most likely a wiring, earth, limit switch sense problem.
Opto isolated? Probably not.
A desktop PC? OK.
A laptop? No way, unless it is very old.
You must fix the ES problem.
Do you have watchdogs enabled, to or from the machine?
Disable ES from watchdogs, while trying to solve the problem.
PC and machine on same power circuit? I hope so.
If not opto isolated:
Isolate the PC earth, and earth directly to the machine earth, so currents can't flow through the PC cable ground.
Find the cause Fixit it!. Foremost, it is safety issue.
Super X3. 3600rpm. Sheridan 6"x24" Lathe + more. Three ways to fix things: The right way, the other way, and maybe your way, which is possibly a faster wrong way.