152
« on: February 27, 2016, 08:29:59 AM »
OK - so you need to understand something about macros.
They run in a totally separate thread from Mach proper. i.e. they run CONCURRENTLY.
So when you issue (say)
Code "G53 G0 X40" 'Move to clear the tool holders
The macro is saying to Mach - please insert this into your execution queue.
Mach will do as it's asked but here's the thing. Mach will EXECUTE that line of code in it's own good time.
Meanwhile, the macro will move onto the next line and say to Mach - please insert this into your execution queue.
Again, Mach will do this BUT it's probably (most likely) still actually executing the first line.
What you're doing is asking Mach to queue all four lines and then immediately activating output 4.
HOWEVER, Mach is probaby STILL just actually executing the first gcode line.
So you end up activating your draw bar WELL before you should.
So when you ask Mach to queue requests (in this case for movement), you MUST then WAIT until Mach has finished before you carry on. This is called thread synchronisation. The method Mach provides us to do this is the isMoving() function.
So what you need is:
Code "G53 G0 X40" 'Move to clear the tool holders
Code "G53 G0 Y61.61"
Code "G53 G0 X6.83" 'Move to directly above the tool position
Code "G53 G1 Z-30 F500" 'Move to a safe height just above the tool
while isMoving() 'wait for Mach to do everything in the queue
wend
ActivateSignal(OutPut4) 'THEN - Open the drawbar