Ok it wouldn't let me post, weird. SO here's what I wrote before.
Ok this was as they said, pretty easy. You just have to understand what's going on. I don't understand everything, but I got it to work.
A BIG thanks to Chad!!
So I'll try to explain what Chad said so other can figure it out.
First thing: Get your tool changer working with a PLC. I think the click does everything you need, is inexpensive, easy to use and figure out and come with Tech Support from Automation Direct. I used an 8 Position Rotary switch with a regular momentary button to make my tool changer go manually.
After you get your PLC to change tools perfectly you can add to the same line as your manual switch the following code:
X001---------------------C1
|
|
DS1 = 1-----Y001
what's going on here is my manual switch triggers an internal bit in the click "C1" that runs my program for tool changes. So I added a DS1 which is a data set, when Mach sends a tool change, Tool 1 for instance, it will send a 1 to the DS1. That's how the Click will know what tool to change to. DS1 just holds a number that's it, the Y001 is the actual signal to make the tool changer move. So in the M6 Macro, the one Chad Posted is perfect other than having to change the variables for how you program your PLC, Mach sends a number for the tool change it's going to make then send an output command, Y001, and that makes the tool change. Then at the end of the tool change in the plc I have it set an output of Y005 to verify the tool change was completed successfully. This output in the PLC also is read by Mach to continue with the rest of macro and thereby continue your GCode.
Now you've got a tool change program working in the PLC and it can take an input to make the tool change to the correct one and an output to verify the tool was changed.
In mach it's really easy to setup Modbus. I used an Ethernet PLC. When I start my Click PLC software a screen pops up to connect to the PLC or open a project. If you connect it will show you all the information you need for the PLC's address, I'm assuming it will have the same info for a PLC that is connected via serial cable. Write that down.
Open Mach 4. Goto Configure > Plugins > Modbus. In mine there were some test modbus' I deleted them. After taking a picture of each in case.
Click the Add a new modbus connection > I named Mine something simple, you should too as it matters later on. I called mine Click PLC, set the connection type to what you're using, for ethernet you'll just put in the IP addy. Leave the other settings the same unless they pertain to your PLC.
Then click on the yellow add modbus function > Read coil > name the function Y005 (or whatever your verification signal is in your click, it has to be an output or input that has a modbus address, you can find if it is in the PLC software) > the address of your input or output you put that in the modbus register (or a Y output use the full address for an X input use just the last 2 numbers, mind you this is for a click PLC) > Register Prefix I put the same Y005. Click next. Then click on the name fields and change them to Y005, Mach adds a 0 for some reason.
Next add a write single register 16 > function name DS1 > modbus register 1 (in a Click PLC a DS1 is a 1 automatically in Mach) > click next and change the names in the fields to DS1 again as Mach adds a 0.
Then add a write coil for Y001 and fill out as with the Y005. Close out of Modbus.
Then open up your PLC software and get it to a state where you can see the functions working in real time. In a click plc software you have to upload the project to a PLC then it will show you in real time the functions.
Then in Mach open up Diagnostic >Click PLC > click on the + sign and go down to DS1 > double click on it and change the value from 0 to 1 > in your PLC software the DS1 value should now show a 1. You can try this with any number and it should change in the PLC software. This is really helpful because it bypasses lots of stuff and shows that mach is correctly communicating with your PLC.
Next go to Mach > config > inputs > use one of the inputs to click and the Y005. Then goto Outputs and use one for Y001. DS1 is a register and will automatically work.
Then just copy Chad's macro and change the values to suit you. Such as:
--Your Tool Changer
function m6()
local inst = mc.mcGetInstance()
local Requested = mc.mcToolGetSelected(inst)
local Current = mc.mcToolGetCurrent(inst)
local ToolChange = mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT01) --Change the output number to the one you used above.
if Requested == Current then
mc.mcCntlSetLastError(inst, "Current tool == Requested tool so there is nothing to do")
else
--Tell the Click to change to requested tool.
local DS1 = mc.mcRegGetHandle(inst,"Click PLC/DS1 ") --Type in here the actual address of the PLC - what that means is when you setup Modbus you call it something. I called mine Click PLC, so the address of the DS1 is and what you type here is "Click PLC/DS1"
mc.mcRegSetValue(DS1,Requested)
--Send signal to the Click to start the tool change.
mc.mcSignalSetState(ToolChange,1) --Y001, this spot is using the words "toolchange" to trigger outpout 01 above. Basically it's shorthand. You set output 01 above to be called out as toolchange. So you don't really need to change this, but I thought I'd explain.
wx.wxMilliSleep(1000)
mc.mcSignalSetState(ToolChange,0) --Y001
--Wait for the signal from the CLick.
mc.mcCntlSetLastError(inst, "Wait for Click to complete tool change.")
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT0, mc.WAIT_MODE_HIGH, 20)--Time in seconds the Click has to complete the tool change. You also have to change the input to the input you setup in Mach Config.
--Error check. If the Click took too long. Alarm out Mach4.
if (rc~= 0) then
wx.wxMessageBox("The Click did not complete the tool change in time. Check for malfunction.")
local Alarm = mc.mcSignalGetHandle(inst,mc.OSIG_ALARM)
mc.mcSignalSetState(Alarm,1)
CycleStop()
else
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(Requested))
mc.mcToolSetCurrent(inst, Requested)
mc.mcCntlSetLastError(inst, "Tool Change Complete.")
end
end--Request == Current
end --m6
if (mc.mcInEditor() == 1) then
m6()
end'
Couple of notes Mach can read an output from the click as an input.
Hope that helps someone.