Hello Guest it is March 28, 2024, 06:22:01 PM

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

0 Members and 1 Guest are viewing this topic.

Offline Bill_O

*
  •  563 563
    • 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,544 1,544
  • "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
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline Bill_O

*
  •  563 563
    • 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

*
  •  563 563
    • 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
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'