You have the bitmask values backwards–the correct bitmask values are:
bit flag set to 0 = de-energize
bit flag set to 1 = energize
I created 2 macros using this that work perfectly:
Lock Motors. Energizes and locks x(1), y(2), and z(4) axis motors when not being driven by g-code.
$37=7
Unlock Motors. DE-energizes and UN-locks ALL motors when not being driven by g-code.
$37=0
I used my Lock Motors macro yesterday to successfully change the tool bit without losing position, and the Unlock macro lets me move the head around when the machine is on but not running a job.
That being said…
I left the lock macro on while running a job that I have run many times, and it went astray near the end of the job. The only things I had changed from previous runs of this exact same g-code was this $37=7 value and I was cutting OSB instead of pine or oak.
Total guess: Either the $37=7 made the motors get hot and lose steps, or some part of the OSB acted like a tough wood knot that gave too much resistance. Or maybe a little of both. I’m going to try again sometime today to see if unlocking the motors before running the job makes a difference (and I’m going to babysit it this time and touch the motors to see if they are warm–they were not warm when I looked for this early on).
Total guess #2: Just realized while typing this that $37=7 may be insufficient because my 4th-axis (A-axis) stepper driver is used to drive the 2nd Y-axis motor! So I probably need to use $37=15 to lock all 4 motors.
EDIT: Nope. $37=15 throws an error when I try to set it:
error: 52 - Setting value is out of range. [ $37 = 15 ]
I may tweak the current on the motors a bit too, as I originally set them somewhat arbitrarily when I was figuring out that my old power supply had been the cause of previous nightmare quasi-inevitable intermittent job failures, so they might be running a bit weakly on insufficient current. (I may try just cranking them to max and then checking for warmth to see if they run hot.)
(Unrelated aside: I had been complaining in other posts recently about needing to run my Ox too slowly to get things done, but I found the bottom wheel on my z-axis was turning freely and there was obvious play/slop. I adjusted the eccentric and it has been running noticeably better, which only makes this more confusing. Aside2: I had a loose limit switch too, which caused some weird repeatability problems after homing but is also fixed now.)