Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: native34 on December 17, 2019, 08:07:26 AM

Title: Mach 4 Exit button for touchscreen
Post by: native34 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
Title: Re: Mach 4 Exit button for touchscreen
Post by: SwiftyJ on December 17, 2019, 08:11:19 AM
Try using scr.Exit(true)
Title: Re: Mach 4 Exit button for touchscreen
Post by: native34 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?
Title: Re: Mach 4 Exit button for touchscreen
Post by: mcardoso 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
Title: Re: Mach 4 Exit button for touchscreen
Post by: native34 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
Title: Re: Mach 4 Exit button for touchscreen
Post by: native34 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.
Title: Re: Mach 4 Exit button for touchscreen
Post by: native34 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.
Title: Re: Mach 4 Exit button for touchscreen
Post by: native34 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
Title: Re: Mach 4 Exit button for touchscreen
Post by: SwiftyJ 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

Title: Re: Mach 4 Exit button for touchscreen
Post by: native34 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?
Title: Re: Mach 4 Exit button for touchscreen
Post by: mcardoso on December 18, 2019, 09:48:15 AM
Quote
How does one know which API's are usable inside this programming for Mach, or is it open to any API?
.

Typically API is used to refer to the Mach 4 interfaces here. If you are asking about wxWidgets or another LUA library, that is a different thing.

In general, all the Mach API commands can be used anywhere. Some have restrictions based on the state of the machine. There are other restrictions/limitations once you start playing with LUA panels and macros, but I am not qualified to provide information on this.

wxWidgets is fully supported in Mach4, however it can get quite complicated once you get beyond the basic features. There are other libraries for LUA included in the Mach 4 install (such as RS232 serial support) and others might be able to be added, but I'm not knowledgeable in doing so.
Title: Re: Mach 4 Exit button for touchscreen
Post by: native34 on December 18, 2019, 09:57:56 AM
Is there a list of all the API commands available in Mach
Title: Re: Mach 4 Exit button for touchscreen
Post by: joeaverage on December 18, 2019, 11:38:33 AM
Hi,
yes, look in Mach4Hobby/Docs for API.chm.

Can also be accessed when Mach is enabled by clicking <Help Docs?> button in the File Ops tab.

Craig
Title: Re: Mach 4 Exit button for touchscreen
Post by: native34 on December 19, 2019, 12:34:43 PM
Ok so i'm trying to get mach to recognize an Enter keypress. Here is the code i found pertaining to keypress in LUA. I have a textbox that i want to enter code and when i press the enter key i want the code to run as an MDI command. The code below is supposed to recognize when an enter key is pressed, I have all this in the On Modify Script of the textbox. When i write something in the textbox and press enter nothing happens. What is the purpose of the On Modify Script, and the On Update Script?

while true do
    if keyPress(13)==true then
        wx.wxMessageBox("You Just Pressed Enter")
    end
end
Title: Re: Mach 4 Exit button for touchscreen
Post by: joeaverage on December 19, 2019, 04:35:22 PM
Hi,
to be honest I think you are going about this the wrong way.

I still find myself hitting <Enter> occasionally after typing an MDI, a hang over from Mach3 days but I don't find using the
<MDI Cycle Start> button that onerous....but perhaps you do. What you are trying to do here is 'fix a perceived
problem that is in fact no problem at all, just a new, Mach4, way of doing things'.

Given that proviso......then you can use the keyboard plugin to capture any <Enter> keypress. If you so desire
you can cause such a keypress to issue an MDI Cycle Start.

I forsee a problem that there are a number of circumstances that you would use <Enter> keypress, not all of them
associated with MDI, are you sure you want to issue an MDI Cycle Start at EVERY <Enter> keypress?

Of course using the keyboard plugin as I am proposing you could choose other than Enter as a keypress to start an MDI command,
maybe the <Space Bar> for instance. That might reduce the number of occasions that you accidentally start an MDI command.

There is a video by Daz-the-Gaz about using the keyboard plugin.

https://www.machsupport.com/forum/index.php?topic=31585.msg219180#msg219180 (https://www.machsupport.com/forum/index.php?topic=31585.msg219180#msg219180)


The upshot is that the keyboard plugin can launch a number of 'Mach Actions' in response to a defined keypress....but what happens
if one of Machs stock actions is not what you want. That is what Daz's video is about.

You can cause the keyboard plugin to trigger a Mach signal, mc.ISIG_INPUT33, for example. Now every time you press the <Space Bar>
Input #33 would trigger. Now you just have to put Input #33 into the SigLib{} table as you would with any other input signal
and cause the appropriate action. If you are not familiar with the SigLib{} table......you are in for a treat!! It is a very VERY VERY
clever way to deal with signals, both input and output, that is new to Mach4 and not even dreamt about in Mach3. Look at my .pdf on it:

https://www.machsupport.com/forum/index.php?topic=40051.msg267764#msg267764 (https://www.machsupport.com/forum/index.php?topic=40051.msg267764#msg267764)

Craig
Title: Re: Mach 4 Exit button for touchscreen
Post by: joeaverage on December 19, 2019, 05:57:07 PM
Hi,
re-reading the whole thread there is another possibility that may avoid the situation where a random <Enter> keypress would cause an MDI
command to be initiated.

You say you have a text box for MDI input?
Did you use wxWidgets to do it? If so why don't you include an enter event. Then the only time that the enter event would be tested is while
the text box is active.

If you haven't already tried, wxFormBuilder is the premier development tool/system for generating wxWidgets code with a Lua wrapper.
I used to try to avoid it but trying to manually craft wxWidgets code is hard going. wxFormbuilder has taught me alot about wxWidgets.

Craig
Title: Re: Mach 4 Exit button for touchscreen
Post by: jbuehn on December 19, 2019, 08:19:06 PM
I believe (you'd have to test this) it will also work using the text box screen element from the screen editor. Put the code you want executed when pressing <enter> in the On Modify Script. To get the text you entered in the text box, something like:

local textInput = select(1, ...)

It'd be good to only enable that text box when the machine is enabled, similar to how the "Cycle Start MDI" button can only be pressed if the machine is enabled.

Personally, I like the multi-line MDI  :)
Title: Re: Mach 4 Exit button for touchscreen
Post by: joeaverage on December 19, 2019, 09:53:41 PM
Hi,

Quote
Personally, I like the multi-line MDI  :)

Me too! I often write 'chesey' little Gcode scripts in the MDI panel then hit <MDI Cycle Start> each time I want the script to run,
so simple and immediate.

Craig
Title: Re: Mach 4 Exit button for touchscreen
Post by: native34 on December 20, 2019, 10:20:34 AM
I also like the multi line MDI as well, but when im doing setups i like to do quick verification as im locating edges and stuff like that. So i also like to have a single line mdi textbox to perform these. We have a Tormach at work and they use a similar type textbox that i can enter a single line and hit enter and the code runs. This is what im trying to acheive.

My idea for the MDI single line textbox has always been that i would type some code into the texbox and ht enter and when i hit enter it will run. If the MDI textbox is empty then nothing happens when i hit enter. I would only like it to be triggered when there is code in the textbox. That was how i planned for not having unwanted enter events. The textbox would only be available in an idle state and not when the machine is running a program. Im sorry i should have prefaced my original post with this information so that people would know what im trying to acheive. Being very new to mach programming and LUA i am really lost at what i can do and how to get it to perform what i need. I used to previously use VB.NET and i really liked that it had event handlers like textbox.on_Enter. It made programming what i want a lot easier.

I have tried to put a simple messagebox() command in the on Modify script of the textbox but have not had success even getting that to run. When i run Mach and type code into the box and hit enter nothing happens. Im having trouble understanding when the on Modify script is triggered. I can get this same code to work if i put it into a button on click script. It will read the textbox text and display it in a messasgebox(), just won't work in the textbox on modify script.
Title: Re: Mach 4 Exit button for touchscreen
Post by: jbuehn on December 20, 2019, 11:38:34 AM
If you put just this line:

Code: [Select]
wx.wxMessageBox("You just pressed enter")
in the On Modify Script of the text box, you click in the text box and hit enter...it does nothing?
Title: Re: Mach 4 Exit button for touchscreen
Post by: native34 on December 20, 2019, 04:38:19 PM
Correct, when i place the cursor in the text box and hit enter it does nothing. I'm not sure how the on modify script is supposed to work.
Title: Re: Mach 4 Exit button for touchscreen
Post by: jbuehn on December 20, 2019, 05:50:38 PM
In C:\Mach4Hobby\docs there is a Screen Editor PDF that explains a bit about it.