I understand what you mean and can program my PLC for the most part
Good, get that done first like I said. Once you have the tool changer working right and it can change tools when you tell it 2 things....
1) What tool to get through a register
2) Change to that tool (start tool change) through a register
you're virtually finished and you can do all of this before you ever even install Mach4.
Then you will need the PLC to tell you that the tool change is complete (by changing that register that told it to change tools).
Once you have that done getting the m6 to do 3 things......
1) Tell the PLC those 2 things (what tool to get and start tool change).
2) Then wait for conformation that the PLC has finished changing tools.
3) Then update your tool offsets or error out depending on what the confirmation check comes back with.
will be super easy with Mach4. I have given you most of it (though not completely accurate) already. But you get the PLC changing tools as I described using only the PLC and Qmodbus (or similar) someone here will help you get the scripting in your m6 (if I have to do it myself). And do note I said help. Help means you will learn too. But if someone else does it all for you it will take all the fun out of it. Don't want that. Hobbies are supposed to be fun.
How does Mach know what signal to send to my PLC with the identity of the tool that needs changing?
local current, rc = mc.mcToolGetCurret(inst)
local selected, rc = mc.mcToolGetSelected(inst)
But, like I said, you need not even worry about that yet. Use Qmodbus to write to a register in the PLC telling the PLC what tool to change to.
but I'm not understanding the code.
You can fix that. Look up those 2 api calls in the Mach4 core API doc. It's in your C:\Mach4 Hobby\Docs directory.
Trust me, doing this in Mach4 will be much easier than you think if you can get the PLC doing its thing. But I wont be helping much with that. Others here probably will but if not I'm sure you can work through it between Click's docs and AutomationDirects forum, support and other resources.