Machsupport Forum

Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: jonboy_360 on March 05, 2024, 10:19:36 AM

Title: On Screen Cycle Counter
Post by: jonboy_360 on March 05, 2024, 10:19:36 AM
First Time Poster here.  I'm starting to get somewhat familiar with LUA (Mostly Programming IO's and safety checks) on a CNC Router Retrofit I just finished, but looking for a little guidance on this instead of shooting in the dark. 

I want to implement an on screen cycle/part countdown.  The operator would click on the count, and input the number of sheets he wants to run.  Then each finished cycle would reduce the count by 1.   (Through M30, or a dedicated M Code if needed).  If the count equals zero, attempting to cycle start would instead bring up a window that reads something like...   "Parts Remaining = 0.  Please Input a Value".  Also I would like this value to be saved through a restart of Mach 4.  (If the value is 26 when Mach 4 is closed, it will be 26 the next time Mach 4 Opens)

Any help on a sensible way to go about this is greatly appreciated!  Thanks
Title: Re: On Screen Cycle Counter
Post by: cncmagic on March 09, 2024, 08:58:47 PM
I'm guessing the cycle stops at the end of each part and requires another cycle start? If thats the case, create a global register called 'CycleCnt' (you can name it whatever makes sense to you).. now write a short macro that reads the value in the register and decrements it by 1 (you can clip it to zero if you want). At the end of each cycle call the macro. Now inside the Cycle Start button place some code so that if the value in the register is greater than zero it does a cycle start. You can place a wxMessage in the code if the value is zero to pop up a message that alerts the operator that the count is zero. If you want to display the value on the screen, place a number display and in the screen plc code, read the value in the global register and write it into the screen display. Sounds like a lot but it should be quick and relatively easy. I actually count cycles in a similar fashion.  ???
and not only do I give advice here I also sell plots in the Antarctic.. cheap!!!
Title: Re: On Screen Cycle Counter
Post by: cncmagic on March 09, 2024, 09:00:11 PM
forgot the last part.. make the global persistent and the value should remain after power down and then up. :o
Title: Re: On Screen Cycle Counter
Post by: cncmagic on March 09, 2024, 09:26:13 PM
actually a bit easier than my earlier post.. make the global.. now using the screen editor place a numeric on the screen.. you can set the properties for it to display the value in the global.. this will also allow you operator to set the value.. you still have to make the macro to decrement the global and you also need to write the code in the cycle button script to check the value. I've attached what I used for M168 to increment the value. You can easily modify to decrement the value.  :-[
Title: Re: On Screen Cycle Counter
Post by: cncmagic on March 09, 2024, 09:36:45 PM
and just for the heck of it attached is what the Cycle Start script should look like   :(