I've built a machine that mills two parts behind an enclosure (running mach3 with ajax hardware). The operator loads the parts through the enclosure. As the machine is milling on the first part the operator is putting in the second part. When the machine is finished with the first part it automatically unclamps and moves on to the second part while the operator removes the first part and puts in a new one. The clamping/unclamping is performed by a plc that sends a "clamped" signal to tell the cnc that the part is clamped, and when the part is done the cnc sends a signal to the plc to unclamp that part. To do this I've made 4 macro's M300,M301,M302, and M303. M300 is placed about 4th line in G-code. It makes sure the first part is clamped before moving on. This is the macro M300
RightClampDone= not GetOEMLED(1000)
While(RightClampDone)
sleep100
Wend
Then at the end of the first part program I have macro M301 which unclamps the first part.
SetUserLED(1002,1)
code "G4 P1"
While Ismoving
Wend
SetUserLED(1002,0)
OK here's the problems. If I load a part without hitting cycle start the plc clamps the part and sends the "clamped" signal to the cnc. The cnc starts up automatically and begins milling without me hitting cycle start. When is finishes the part it automatically unclamps like it's supposed to and moves on to the second part. I'm not sure why the machine starts up automatically....makes it dangerous!!
If I hit cycle start first the machine moves into position and waits until receiving the signal from plc to begin, but now when it gets to the end it does not unclamp the part.
I'm confused. It seems like sometimes it skips right over the unclamp macro. Also if the second part is not present the machine will wait until it's present before beginning to run the part, but now you have to hit the cycle start for it to proceed with the G-Code. Am I going about this all wrong? Help!