Hello Guest it is March 29, 2024, 12:37:47 AM

Author Topic: Mach 4 Exit button for touchscreen  (Read 2722 times)

0 Members and 1 Guest are viewing this topic.

Mach 4 Exit button for touchscreen
« on: December 17, 2019, 08:07:26 AM »
I am trying to create a button that i can use to close out Mach 4 when done using it. Im using a touchscreen and hitting the red x is not an option as it is to small in the corner of the screen to get my fingers in there. So i am trying to create a button to perform this task, what i have is the code listed below, but it doesn't seem to work. When the button is clicked I would like it to check to see if the system is enabled or disabled. If it is disabled it can procede to shutting down Mach 4, If the system is Enabled it will display a message telling you to disable the machine before shutting down. I can't seem to find The system variables that will produce the desired results. I'm also not a great programmer either.

if (mc.OSIG_MACHINE_ENABLED == nil) then
   os.exit()   
else
   wx.wxMessageBox("Machine Must Be Disabled Before Exitting!")      
end
Re: Mach 4 Exit button for touchscreen
« Reply #1 on: December 17, 2019, 08:11:19 AM »
Try using scr.Exit(true)
Re: Mach 4 Exit button for touchscreen
« Reply #2 on: December 17, 2019, 09:46:12 AM »
Thank you, not sure how that is different from os.exit(). It seems to do the same thing. The part i'm having issue with is getting the code to determine the enabled/disabled state. Is there any documentation on how to work with the form elements in Mach 4?
Re: Mach 4 Exit button for touchscreen
« Reply #3 on: December 17, 2019, 09:52:08 AM »
You can check OSIG_MACHINE_ENABLED. You'll need to read this like any other I/O point in Mach by getting the handle first, then reading the state.

This signal mimics the status of the machine as you toggle the Enable button in the lower left hand corner.

Edit: Looking back, I see that you have found the OSIG_MACHINE_ENABLED, however you are failing to actually read the signal.

You will need to first get the register then read it:

local hReg = mc.mcSignalGetHandle(inst, mc.OSIG_MACHINE_ENABLED)
local machEnabled = mc.mcSignalGetState(hReg)

Mike
« Last Edit: December 17, 2019, 09:55:31 AM by mcardoso »
Re: Mach 4 Exit button for touchscreen
« Reply #4 on: December 17, 2019, 10:15:04 AM »
Thank you for the help got it working. The following code is what works in case someone else is having the same issue

local hReg = mc.mcSignalGetHandle(inst, mc.OSIG_MACHINE_ENABLED)
local machEnabled = mc.mcSignalGetState(hReg)

if (machEnabled == 0) then

   scr.Exit(true)   
   
else
   
   wx.wxMessageBox("Machine Must Be Disabled Before Exitting!")   
   
end
Re: Mach 4 Exit button for touchscreen
« Reply #5 on: December 17, 2019, 10:45:02 AM »
How does one go about accessing form elements in LUA? For instance I have a form with a button and i want to change its text label using code instead of the properties table, or other properties. I used to be able to do things like this in Visual Basic and .NET, when i dabbled in this suff. I'm just trying to get my Mach 4 screen to look and feel a certain way, I'm not trying to become a Mach programmer, so im not into knowing the complete ins and outs of Lua and mach programming.
Re: Mach 4 Exit button for touchscreen
« Reply #6 on: December 17, 2019, 10:48:47 AM »
One of the things i would like to have happen is implement a textbox for single MDI commands. I would like to be able to enter the Gcode into the textbox and hit enter and have the code run on enter, and not have an additional button for enter.
Re: Mach 4 Exit button for touchscreen
« Reply #7 on: December 17, 2019, 01:30:58 PM »
Is it possible to get a tool table embedded into the screen of Mach 4 instead of the popup window, without having to go the route of Mach 4 Industrial
Re: Mach 4 Exit button for touchscreen
« Reply #8 on: December 18, 2019, 03:13:04 AM »
To modify GUI items without going into the screen editor you can use the following API commands.
scr.SetProperty('ControlName', 'PropertyName', 'Value')

ControlName is the name of the control as seen in the screen editor tree
PropertyName can be any of the properties you see in the properties table in the screen editor
Value is just the value to change it to.

These 3 things must be entered as strings.

For example, to change the name of a button:
scr.SetProperty('btnZeroX', 'Label', 'ZeroX').

There is also the scr.GetProperty which you can use to retrieve properties from controls e.g. text from labels.

Regarding using 'Enter' to execute the MDI, you could set up a label and use the 'On Modify Script' to read the text entered and then execute it. But the 'On Modify Script' also runs when focus is lost from the label so may not always behave correctly.

Embedding the tool table into Mach4 hobby may be possible using wxwidgets but would be a lot of work unless you're already familiar with it. You can set a screen button to display the tool table rather than going through View>Tool Table if that is any better.

Hope this helps

Re: Mach 4 Exit button for touchscreen
« Reply #9 on: December 18, 2019, 09:40:33 AM »
Thank you for the information. That gives me a good place to start. How does one know which API's are usable inside this programming for Mach, or is it open to any API?