Hello Guest it is May 14, 2021, 02:54:46 AM

Author Topic: Mach4 screen not updating while running Macro  (Read 1862 times)

0 Members and 1 Guest are viewing this topic.

Mach4 screen not updating while running Macro
« on: September 25, 2017, 10:55:54 AM »
mcCntlGcodeExecuteWait() seems to work fine, but the screen doesn't update while the code is running.  It updates after the button script is done. I can compile and step through the lua code and it works fine in debug mode. When I try to run my M file from MDI or in a gcode line it ignores it. If I copy and paste the code to a button, without the function title and debug snip at the end, it operates correctly but does not update the screen till it is finished. I really need the screen dro's updated while it is running. Is there a function I can drop in my lua code that will update the screen while it is running?
Re: Mach4 screen not updating while running Macro
« Reply #1 on: September 26, 2017, 02:42:27 PM »
Can't help you with an answer but I've the same problem.

I believe I recall reading in the documentation somewhere that this was expected behaviour but it was some time ago and I could be wrong.

I'd also like to know if there was a command to update the screen while executing a script.

I did get a workaround by assigning my LUA script as a Mxx code and then running that from a button rather than running the code directly from the button and the screen updates but I've no idea if that's the way it should be done, a dirty hack or an absolute no-no.

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Mach4 screen not updating while running Macro
« Reply #2 on: September 26, 2017, 03:36:19 PM »
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Mach4 screen not updating while running Macro
« Reply #3 on: September 26, 2017, 05:05:39 PM »
Chaoticone,
I forgot about that, I remember hearing Scott tell us that like 3 years ago.  We're going to rewrite the script with the correct syntax and give that a shot.
Thanks.
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Mach4 screen not updating while running Macro
« Reply #4 on: September 26, 2017, 05:17:00 PM »
No problem.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Mach4 screen not updating while running Macro
« Reply #5 on: September 27, 2017, 02:49:18 PM »
I've tried both "Execute" and "Mdi" and am still not getting a result.  I'm also getting a message when I open my code file.
      "Invalid value 2 for a boolean key "WholeWord" in config file"
Here is the code, if that helps:

--Grind to this dimension
function M200()

-----
--Variables
-----
local inst = mc.mcGetInstance()
local FinishDiameterText = scr.GetProperty ("GrindDimensionText", "Value")
local PlungeFeedText = scr.GetProperty("PlungeFeedText", "Value")
local RoughIncText = scr.GetProperty("RoughIncText", "Value")
local FinishIncText = scr.GetProperty("FinishIncText", "Value")
local SparkOutsText = scr.GetProperty("SparkOutsOnlyText", "Value")
local LeftXText = scr.GetProperty("EndLeftText", "Value")
local RightXText = scr.GetProperty("EndRightText", "Value")
local LeftFeedText = scr.GetProperty("FRLeftText", "Value")
local RightFeedText = scr.GetProperty("FRRightText", "Value")
local LeftDwellText = scr.GetProperty("DwellLeftText", "Value")
local RightDwellText = scr.GetProperty("DwellRightText", "Value")
local FeedRightLED = scr.GetProperty("FeedOnRightLED", "Value")
local FeedLeftLED = scr.GetProperty("FeedOnLeftLED", "Value")
local EndLeftLED = scr.GetProperty("EndOnLeftLED", "Value")
local EndRightLED = scr.GetProperty("EndOnRightLED", "Value")

local FinishDiameter = tonumber(FinishDiameterText)
local PlungeFeed = tonumber(PlungeFeedText)
local RoughInc = tonumber(RoughIncText)
local FinishInc = tonumber(FinishIncText)
local SparkOuts = tonumber(SparkOutsText)
local LeftX = tonumber(LeftXText)
local RightX = tonumber(RightXText)
local LeftFeed = tonumber(LeftFeedText)
local RightFeed = tonumber(RightFeedText)
local LeftDwell = tonumber(LeftDwellText)
local RightDwell = tonumber(RightDwellText)
local FeedRightLED = scr.GetProperty("FeedOnRightLED", "Value")
local FeedLeftLED = scr.GetProperty("FeedOnLeftLED", "Value")
local EndLeftLED = scr.GetProperty("EndOnLeftLED", "Value")
local EndRightLED = scr.GetProperty("EndOnRightLED", "Value")
local CurrentY = scr.GetProperty ("droCurrentY", "Value")
local ToGrindNum = (CurrentY - FinishDiameter)
local ToGrind = ToGrindNum
local ToGrindVar = 0
local SparkOutCtr = 0
local SparkOutCounter = 0


-----
--Rough Grind
-----
mc.mcCntlSetLastError(inst,"Start Rough Grind.")
mc.mcCntlGcodeExecute(inst,"M3M8")

while (ToGrind > (RoughInc + FinishInc)) do
    FeedLeftLED = scr.GetProperty("FeedOnLeftLED", "Value")
    if (FeedLeftLED == "1") then
        mc.mcCntlGcodeExecute(inst, "F" .. RightFeed) --FR from the right.
        mc.mcCntlGcodeExecute(inst, "G90G01X" .. LeftX)
        mc.mcCntlGcodeExecute(inst, "G04" .. LeftDwell)
        mc.mcCntlGcodeExecute(inst, "G91G00Y-" .. RoughInc)
        mc.mcCntlGcodeExecute(inst, "F" .. LeftFeed) --FR from the left.
        mc.mcCntlGcodeExecute(inst, "G90G01X" .. RightX)
        mc.mcCntlGcodeExecute(inst, "G04" .. RightDwell)
           
        ToGrindVar = (ToGrind - RoughInc) -- How much is actually left grind.
        ToGrind = ToGrindVar
           
    end --If
           
    FeedRightLED = scr.GetProperty("FeedOnRightLED", "Value")
    if (FeedRightLED == "1") then
        if (ToGrind > (RoughInc + FinishInc)) then
            mc.mcCntlGcodeExecute(inst, "F" .. LeftFeed) --FR from the left.
            mc.mcCntlGcodeExecute(inst, "G90G01X" .. RightX)
            mc.mcCntlGcodeExecute(inst, "G04" .. RightDwell)
            mc.mcCntlGcodeExecute(inst, "G91G00Y-" .. RoughInc)
            mc.mcCntlGcodeExecute(inst, "F" .. RightFeed) --FR from the right.
            mc.mcCntlGcodeExecute(inst, "G90G01X" .. LeftX)
            mc.mcCntlGcodeExecute(inst, "G04" .. LeftDwell)
           
            ToGrindVar = (ToGrind - RoughInc) -- How much is actually left grind.
            ToGrind = ToGrindVar
           
        end --If
           
    end --If
end --While


-----
--Finish Rough Grind
-----
mc.mcCntlSetLastError(inst,"Start Finish Grind.")
mc.mcCntlGcodeExecute(inst,"M3M8")

while (ToGrind > FinishInc) do
    FeedLeftLED = scr.GetProperty("FeedOnLeftLED", "Value")
    if (FeedLeftLED == "1") then
        mc.mcCntlGcodeExecute(inst, "F" .. RightFeed) --FR from the right.
        mc.mcCntlGcodeExecute(inst, "G90G01X" .. LeftX)
        mc.mcCntlGcodeExecute(inst, "G04" .. LeftDwell)
        mc.mcCntlGcodeExecute(inst, "G91G00Y-" .. FinishInc)
        mc.mcCntlGcodeExecute(inst, "F" .. LeftFeed) --FR from the left.
        mc.mcCntlGcodeExecute(inst, "G90G01X" .. RightX)
        mc.mcCntlGcodeExecute(inst, "G04" .. RightDwell)
           
        ToGrindVar = (ToGrind - FinishInc) -- How much is actually left grind.
        ToGrind = ToGrindVar
    end --If
         
    FeedRightLED = scr.GetProperty("FeedOnRightLED", "Value")
    if (FeedRightLED == "1") then
        if (ToGrind > RoughInc) then
            mc.mcCntlGcodeExecute(inst, "F" .. LeftFeed) --FR from the left.
            mc.mcCntlGcodeExecute(inst, "G90G01X" .. RightX)
            mc.mcCntlGcodeExecute(inst, "G04" .. RightDwell)
            mc.mcCntlGcodeExecute(inst, "G91G00Y-" .. FinishInc)
            mc.mcCntlGcodeExecute(inst, "F" .. RightFeed) --FR from the right.
            mc.mcCntlGcodeExecute(inst, "G90G01X" .. LeftX)
            mc.mcCntlGcodeExecute(inst, "G04" .. LeftDwell)
           
            ToGrindVar = (ToGrind - FinishInc) -- How much is actually left grind.
            ToGrind = ToGrindVar
        end --If
    end --If
end --While

-----
--Finish Finish Grind
-----
mc.mcCntlSetLastError(inst,"Grinding Remainder.")
mc.mcCntlGcodeExecute(inst,"M3M8")

FeedLeftLED = scr.GetProperty("FeedOnLeftLED", "Value")
if (FeedLeftLED == "1") then
    mc.mcCntlGcodeExecute(inst, "F" .. RightFeed) --FR from the right.
    mc.mcCntlGcodeExecute(inst, "G90G01X" .. LeftX)
    mc.mcCntlGcodeExecute(inst, "G04" .. LeftDwell)
    mc.mcCntlGcodeExecute(inst, "G90G00Y" .. FinishDiameter)
    mc.mcCntlGcodeExecute(inst, "F" .. LeftFeed) --FR from the left.
    mc.mcCntlGcodeExecute(inst, "G90G01X" .. RightX)
    mc.mcCntlGcodeExecute(inst, "G04" .. RightDwell)
end   
           
FeedRightLED = scr.GetProperty("FeedOnRightLED", "Value")
if (FeedRightLED == "1") then
    mc.mcCntlGcodeExecute(inst, "F" .. LeftFeed) --FR from the left.
    mc.mcCntlGcodeExecute(inst, "G90G01X" .. RightX)
    mc.mcCntlGcodeExecute(inst, "G04" .. RightDwell)
    mc.mcCntlGcodeExecute(inst, "G90G00Y" .. FinishDiameter)
    mc.mcCntlGcodeExecute(inst, "F" .. RightFeed) --FR from the right.
    mc.mcCntlGcodeExecute(inst, "G90G01X" .. LeftX)
    mc.mcCntlGcodeExecute(inst, "G04" .. LeftDwell)
end --If
         
-----
--SparkOut
-----
mc.mcCntlSetLastError(inst,"Sparkouts.")
while (SparkOutCounter < SparkOuts) do
    mc.mcCntlGcodeExecute(inst, "F" .. RightFeed) --FR from the right.
    mc.mcCntlGcodeExecute(inst, "G90G01X" .. LeftX)
    mc.mcCntlGcodeExecute(inst, "G04" .. LeftDwell)
       
    mc.mcCntlGcodeExecute(inst, "F" .. LeftFeed) --FR from the left.
    mc.mcCntlGcodeExecute(inst, "G90G01X" .. RightX)
    mc.mcCntlGcodeExecute(inst, "G04" .. RightDwell)

    SparkOutVar = (SparkOutCounter + 1)
    SparkOutCounter = SparkOutVar
end

-----
--End on left or right?
-----
mc.mcCntlSetLastError(inst,"End on Left or Right?")
if (EndLeftLED == "1") then
    mc.mcCntlGcodeExecute(inst, "F" .. RightFeed) --FR from the right.
    mc.mcCntlGcodeExecute(inst, "G90G01X" .. LeftX)
    mc.mcCntlSetLastError(inst,"End on the left.")
end 

if (EndRightLED == "1") then
    mc.mcCntlGcodeExecute(inst, "F" .. LeftFeed) --FR from the left.
    mc.mcCntlGcodeExecute(inst, "G90G01X" .. RightX)
    mc.mcCntlSetLastError(inst,"End on the right.")
end 

mc.mcCntlGcodeExecute(inst, "M5M9")
mc.mcCntlSetLastError(inst,"Finished Grinding!!")

end --Macro End

if (mc.mcInEditor() == 1) then
 M200()
end

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Mach4 screen not updating while running Macro
« Reply #6 on: September 27, 2017, 04:16:20 PM »
Errrrr, might want to read the API doc.

mc.mcCntlGcodeExecute

Notes:


If the control is in the idle state, this function will execute the G code in MDI mode.

It is important to note that this function does not wait for the G code to complete. It is an error to execute G code with this function one line after another. Instead, the lines should be combined into one string separeated with newline characters (\n).

mc.mcCntlMdiExecute

Notes:
Used to run commands like MDI or script commands. The function returns immediately without waiting on the G code to proocess. It is an error to call this function multiple times for each block of G code. Multiple blocks should be concatenated and separated with new line characters to form a "unit of work".
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Mach4 screen not updating while running Macro
« Reply #7 on: September 28, 2017, 02:57:24 PM »
OK,
  I've read the current API docs, looked and tried examples. Can I just get a sample code of a button script that has more than one gcode line that echoes to the screen realtime?

Offline Chaoticone

*
  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Re: Mach4 screen not updating while running Macro
« Reply #8 on: September 28, 2017, 11:57:37 PM »
This should work.....

Code: [Select]
local inst = mc.mcGetInstance()
local Var1 = 100
local Var2 = 1
local Var3 = 1
local Var4 = 1

local MyGcode = string.format("G17 G90 G91.1 G94 G20 G40 G49 G80 G98 G50 G67 G54 G61 G69 G15\n") --Just setting some things to a known state
MyGcode = MyGcode .. string.format("G91 G54 G01 F%.4f X%.4f Y-%.4f Z%.4f\n", Var1, Var2, Var3, Var4)
MyGcode = MyGcode .. string.format("G91 G54 G01 F100 X0.0000 Y-0.0000 Z0.0000\n")
mc.mcCntlGcodeExecute(inst, MyGcode)
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!