Hello Guest it is December 11, 2019, 05:35:24 AM

Author Topic: Mach4 Lua for Dummies  (Read 468 times)

0 Members and 1 Guest are viewing this topic.

Offline Bill_O

*
  •  250 250
    • View Profile
Mach4 Lua for Dummies
« on: March 29, 2019, 08:09:06 AM »
I am not a programmer and even though all the information is out there and plenty of people are willing to help I thought this might help some people like me.
Please all of you experts look it over and let me know if I made any mistakes.
I plan on updating this as I learn more.
I hope this helps some people get started without feeling like an idiot.

Bill

Offline smurph

*
  • *
  •  1,155 1,155
  • "That there... that's an RV."
    • View Profile
Re: Mach4 Lua for Dummies
« Reply #1 on: March 29, 2019, 08:07:03 PM »
That is a good notebook! The only think I would comment on is that it is MUCH better to get or change the data that drives a DRO or LED than getting/setting the value with scr.Get/SetProperty().  One of your examples was getting the current Y position:

Code: [Select]
local StartPos = scr.GetProperty (‘dro Current Pos Y’, ‘Value’)

The better solution is to use the main API:

Code: [Select]
local StartPos, rc = mcAxisGetPos(<instance>, mc.Y_AXIS)
if (rc == mc.MERROR_NOERROR) then
    --We successfully got the Y axis position.
end

Why is this better?  Well...  Because the screen controls are updated on an interval.  This is called the screen refresh interval.  It may not be the MOST current value of the data.  The system may have a value of 3.401" for the Y axis but the DRO may have not been updated to that value because the screen has not refreshed yet when the code was run.  Also, the main API functions return defined error codes that can be checked for success or fail after calling the API function.  Checking the the API return codes is VERY important for developing robust processes.  I like to say "If you check the return codes, there will be no mysteries."

As mentioned in another post, this is why the scr.* functions are not documented.  Because there is a better (and documented) ways to do most things.   

But that is a fine collection of useful information! 

Steve

Re: Mach4 Lua for Dummies
« Reply #2 on: March 29, 2019, 09:33:33 PM »
Hi BillO,
I agree, great effort to pull stuff together for newcomers to Mach4.

I have written this about using the Signal Library Table in Mach4 to monitor inputs like switches or buttons.
While it is a very elegant method it relies on several principles which are by no means obvious. Once understood
however it gives a glimpse of the true power and flexibility of Mach4/Lua.

Craig
My wife left with my best friend...
     and I miss him!

Offline Bill_O

*
  •  250 250
    • View Profile
Re: Mach4 Lua for Dummies
« Reply #3 on: April 01, 2019, 05:49:58 PM »
Steve,

I actually use what you were saying for getting an axis position.
I was just quickly trying to get a more standard value for my example.
I am going to add yours stating that it is better to use the mc calls when you can.

Bill

Offline Bill_O

*
  •  250 250
    • View Profile
Re: Mach4 Lua for Dummies
« Reply #4 on: April 01, 2019, 05:52:56 PM »
Craig,

I am going to need to play with what you have in your "Using Mach4 Signals - Intro"
If I can get my head wrapped around it I can add a link your post.

Thanks,
Bill
Re: Mach4 Lua for Dummies
« Reply #5 on: April 01, 2019, 06:15:11 PM »
Hi,
the Signal Script and Signal Library table were always the intended means of detecting inputs in Mach4.
It is not straight forward at first, but it is elegant.

Craig
My wife left with my best friend...
     and I miss him!