Hello Guest it is April 19, 2024, 04:11:42 PM

Author Topic: Help me troubleshoot the Cycle Timer  (Read 1459 times)

0 Members and 1 Guest are viewing this topic.

Help me troubleshoot the Cycle Timer
« on: November 05, 2019, 09:18:57 AM »
Hi All,

I have posted here before that my cycle timer is not working, but unfortunately I have not been able to fix it.

It persistently shows 0:00:22 and does not increment or reset. It is certainly possible that I broke the LUA code as I have made massive modifications to the LUA code to customize the capabilities of Mach 4 to my machine (mostly behind the scenes stuff, very little changes to the GUI).

My hangup is that I cannot find where in the LUA code the cycle timer is incremented? It is possible I accidentally deleted it, but I don't think I did. I also don't understand where in the screen element you actually pull the data into it? It just looks like a plain old string display with no linked registers or DROs.

Any information on how this screen element works behind the scenes or tips on how to troubleshoot its (non)functionality would be greatly appreciated.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Help me troubleshoot the Cycle Timer
« Reply #1 on: November 05, 2019, 09:49:57 AM »
This is a perfect example of why you need to always keep the default screen. Also, I would highly recommend when you start with Mach4 copy the profile and screen you plan to start your actual profile with and save each of them as something custom, screen and profile. I usually make the names match for both screen and profile. This way later on you have a exact copy of what you began with if you need to undo something, use for reference, start over, etc.

The cycle timer uses 2 bits of script. One in the screens PLC script and the other is in the screens screen load script.

PLC
Code: [Select]
-------------------------------------------------------
--  Cycle time label update
-------------------------------------------------------
--Requires a static text box named "CycleTime" on the screen
if (machEnabled == 1) then
local cycletime = mc.mcCntlGetRunTime(inst, time)
scr.SetProperty("CycleTime", "Label", SecondsToTime(cycletime))
end


Screen load
Code: [Select]
-------------------------------------------------------
--  Seconds to time Added 5-9-16
-------------------------------------------------------
--Converts decimal seconds to an HH:MM:SS.xx format
function SecondsToTime(seconds)
if seconds == 0 then
return "00:00:00.00"
else
local hours = string.format("%02.f", math.floor(seconds/3600))
local mins = string.format("%02.f", math.floor((seconds/60) - (hours*60)))
local secs = string.format("%04.2f",(seconds - (hours*3600) - (mins*60)))
return hours .. ":" .. mins .. ":" .. secs
end
end
;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: Help me troubleshoot the Cycle Timer
« Reply #2 on: November 05, 2019, 09:55:21 AM »
Duly noted. I have the original screensets saved but must've missed this. I do work with custom screens and profiles which has definitely saved me in the past when I broke something badly.

I appreciate you taking the time to respond with this information. I will go in an make sure I have everything where it needs to be.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Help me troubleshoot the Cycle Timer
« Reply #3 on: November 05, 2019, 10:06:18 AM »
No problem,

Also, make sure any variables (like machEnabled) in the scripts are defined and set somewhere (like the default screens do) or create your own suitable replacements.
;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: Help me troubleshoot the Cycle Timer
« Reply #4 on: November 06, 2019, 11:31:23 AM »
Was able to get the CycleTimer working! Turns out I didn't delete any code, however the value of "machEnabled" is stuck at zero for some reason.

I ended up removing the condition on machEnabled == 1 for the cycle timer to display since I'm not sure why is was ever required.

I need to troubleshoot getting the machEnabled state working correctly again before I put the condition back in. Thanks for all the help and understanding on how this works!

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Help me troubleshoot the Cycle Timer
« Reply #5 on: November 08, 2019, 11:43:26 AM »
Good deal, glad you got it working.

;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!