Hello Guest it is April 19, 2024, 07:03:47 PM

Author Topic: Mach closing randomly 4162  (Read 1465 times)

0 Members and 1 Guest are viewing this topic.

Mach closing randomly 4162
« on: July 08, 2019, 02:26:00 PM »
Mach4 is closing randomly whenever I run scripts. 
I originally thought the issue was with my m6 macro, but I was testing the position of my tool carousel and kept cycling the POT up and down with trouble shooting buttons on the screen that will run a small chunk of code to turn on an output and check for an input and Mach4 closed on me when I was pushing these buttons.

It was suggested that I make sure the code is still compatible with the new version of LUA, I looked through the code and found no errors and it worked several times before Mach4 just closes; same with the m6 macro, I ran a couple of tool changes with no issues, then randomly it will close.
Chad Byrd
Re: Mach closing randomly 4162
« Reply #1 on: July 08, 2019, 03:07:35 PM »
Here is the m6 and a button script
Chad Byrd
Re: Mach closing randomly 4162
« Reply #2 on: July 09, 2019, 01:59:05 PM »
I downloaded 4162 on my work computer and adjusted my m6 macro to not have the error check in it.  I am able to run through the macro several times and I've had no issues.
I added buttons on the screen that do the same thing as my trouble shooting buttons, excluding the Error check as well.

Does the new LUA version do something different with the error checking?  So far that has been the only difference in this test vs the machine.
Chad Byrd

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Mach closing randomly 4162
« Reply #3 on: July 10, 2019, 02:15:32 AM »
Chad,

What error checking are you reffering to?  Give me a line number for an example in one of the files you posted.

What IS different between 5.2 and 5.3 is that 5.3 has a new integer type.  This mainly affects formating a string with "%d" or "%i" formats.  You can't format a LUA number (real number) with those anymore.  It will fail.  You have to use "%f" with old school LUA numbers.  To print only the integer portion of a real number, use "%.0f" instead of "%d".  So look for code that has printf statements with "%d" and check that. 

Steve

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Mach closing randomly 4162
« Reply #4 on: July 10, 2019, 02:26:00 AM »
Oh, one more thing.  In your tool change mcs file, there are a lot of locals declared and initialized.  There is a finite limit to the amount of local variables you can have in any one chunk.  The default limit is 200 and we don't change it.  Since all of the macro scripts are compiled into one chunk, you have to be careful with locals.  It would be better to declare one local table in the m6 function.
Code: [Select]
function m6()
local inst = mc.mcGetInstance()
local rc

local vars = {
    Alarm = mc.mcSignalGetHandle(inst, mc.OSIG_ALARM)
    AlarmState = 0
    RequestedTool = mc.mcToolGetSelected(inst)
    CurrentTool = mc.mcToolGetCurrent(inst)
    ToolChangePosition = mc.mcCntlGetPoundVar(inst, 500)
    RequestedToolPocket = mc.mcToolGetData (inst, mc.MTOOL_MILL_POCKET, RequestedTool)
    ...
}

Then use them like vars.Alarm and vars.AlarmState, etc...

I have seen some strange thing happen when the declared local variables exceed the 200 count limit.  And there is NO ERROR that says you have exceeded the limit!  I found out the hard way. 

Steve
Re: Mach closing randomly 4162
« Reply #5 on: July 10, 2019, 08:47:46 AM »
Steve, the error checking is just the mc.mcsignalwait that I'm using; just to be sure the pneumatic cylinders extend properly.
I'm not formatting any strings in my code; so I don't have to worry about that aspect of the LUA code right now.

I will change my locals to a table.  How would I use them after that?

local vars = {
    Alarm = mc.mcSignalGetHandle(inst, mc.OSIG_ALARM)
    POTUp = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT12)
    POTDown = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT13)
    CurrentTool = mc.mcToolGetCurrent(inst)
}

mc.mcSignalSetState(Vars.POTDown, 0)
mc.mcSignalSetState(Vars.POTUp, 1)

Is this correct above?
Chad Byrd

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Mach closing randomly 4162
« Reply #6 on: July 10, 2019, 03:37:35 PM »
Yes, that is the correct usage.  :)

Steve

Offline jbuehn

*
  •  101 101
    • View Profile
Re: Mach closing randomly 4162
« Reply #7 on: July 10, 2019, 04:00:20 PM »
I believe you'll need a comma or semicolon after each value in that table.

Steve - When something like the mcTouchOff module is loaded from a button, does that remain a separate lua chuck and have it's own 200 count limit on local variables?
Re: Mach closing randomly 4162
« Reply #8 on: July 10, 2019, 04:11:11 PM »
Steve, Thanks for the clarification.

As far as the 4162 closing randomly, still no luck; I was super frustrated with this closing and we need this machine going soon, so I went and bought another computer and reloaded 3804 on it and got everything working the way it is supposed to.
I really don't know what the issue with loading 4162 and then reverting back to 3804 was.  I ran the unistaller, deleted everything dealing with Mach4 off of the computer, reloaded 3804 and it still said I was missing a file; and when I reloaded 4162 it was still closing.  The new computer fixed my issue.  Maybe someone else will run into the same problem I had (I hope not!), I just don't have time to delve into it anymore.  Gotta start making chips soon!!

I will try 4162 on the next machine we get going.
Chad Byrd

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Mach closing randomly 4162
« Reply #9 on: July 10, 2019, 04:14:45 PM »
Since it is in a module, I believe it has it's own 200 count limit.  But we do the table thing in modules too. 

Chad:  Yeah, something strange is going on because we haven't had any complaints about 4162 just closing like that on it's own.

Steve