We have a machine that runs in a production environment, and we have sorted bespoke screens which are working well in the main. One problem is the button code to interrupt the process sometimes doesn't stop the spindle on the first press. Pressing it again will stop it though !
Code is as follows, and I've tried M5 or DoSpinStop() directly -

DoOEMButton(1004) 'toggle single step
While Ismoving()
Sleep 50
Wend
DoOEMButton(1004) 'back to normal operation
DoOEMButton(233) ' lock doors
Code "G0 G53 Z0" 'z axis up to safe height
Code "G0 G53 X0 Y0" 'retun to machine zero
While Ismoving()
Sleep 50

Wend

DoSpinStop() 'stop spindle
Code "M421" 'unblock wp selection buttons

While Ismoving()
Sleep 50

Wend
Code "M30" 'end script and return to start

DoOEMButton(234) 'open doors
IF GetOEMLED(82) =1 Then 'if single step active
DoOEMButton(1004) 'toggle single step

End If

Any ideas ? Tim