261
Mach4 General Discussion / Re: Modbus Programming guidance needed
« on: January 02, 2021, 04:59:52 PM »
Some of the modbus devices need to see communication . So read a status of something and it should be good.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
--PRIVATE this is it runs as it's own chunk outside of the screen
local inst = mc.mcGetInstance()
local ProbeDownDist = -15--distance to look down to find the part
local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) --get the current mode so we can return to it when macro ends
local currenttool = mc.mcToolGetCurrent(inst)
local curpos = mc.mcCntlGetValue(inst,mc.VAL_AXIS_MACHINE_POS,mc.Z_AXIS)
local rc = 0
local MyChoice = wx.wxMessageBox("Click Ok to Begin Probing the New Tool","Click OK to continue" , 16)
if(MyChoice == 4)then
mc.mcCntlSetLastError(inst, "Probing in Progress!")
rc = mc.mcCntlGcodeExecuteWait(inst, string.format("G91 G31 Z%.3f F100.", ProbeDownDist))--probe the new tool Change F to set the Feed
if(rc ~= mc.MERROR_NOERROR)then
return;
end
local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_MACH_POS_Z) -- Z Probe position in Machine coords
local Retract = string.format("G00 G90 G53 Z%.3f\nG%.0f", curpos, posmode)
rc = mc.mcCntlGcodeExecuteWait(inst, Retract)--Retract
if(rc ~= mc.MERROR_NOERROR)then
return;
end
if(math.abs(curpos + ProbeDownDist - probedz) <.01)then
wx.wxMessageBox("Probe did not contact Probe","ERROR" );
else
local OffsetToMasterTool = 100.406;
local NewOffset = probedz - OffsetToMasterTool
mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, currenttool, NewOffset)
end
end