MCode Actions and custom buttons

Moderators: TomKerekes, dynomotion

Post Reply
Moray
Posts: 282
Joined: Thu Apr 26, 2018 10:16 pm

MCode Actions and custom buttons

Post by Moray » Mon Jan 01, 2024 10:49 pm

I'm aware of the G Code Action Table, and that there are only 10 indexes available for user buttons.

In the previous screens of my app, I copied the 10 KMotionCNC custom button setup, with them being hidden unless functionality is set. However with my new screen designer, there is the possibility to have however many custom buttons a user wants. Would this mean having to re-setMcodeAction() if there are more than 10 buttons?
Or is there some other mechanism I could use?

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: MCode Actions and custom buttons

Post by TomKerekes » Tue Jan 02, 2024 1:21 am

Hi Moray,

Currently I believe you would need to reconfigure some Action and invoke it.

There is a function:

Code: Select all

int CGCodeInterpreter::InvokeAction(int i, BOOL FlushBeforeUnbufferedOperation, MCODE_ACTION *p)
That allows an action to be created, configured, and passed as a parameter to be invoked (rather than as an index into the fixed table of actions). An index of -1 is passed to do this. However this function is not exposed to .NET. We could expose it if it would help. This is how the many buttons in the KMotionCNC Custom Screen handles it. See function

Code: Select all

int CScreen::DoAction(CStringW s)
I suppose another approach would be to just perform the Action yourself. For example if the button is to run a C Program then instead of configuring an Action to run the C Program and then Invoking the Action, just run it yourself.
Regards,

Tom Kerekes
Dynomotion, Inc.

Moray
Posts: 282
Joined: Thu Apr 26, 2018 10:16 pm

Re: MCode Actions and custom buttons

Post by Moray » Tue Jan 02, 2024 10:28 pm

Thanks Tom.

I'll have a look over the next few days, as I've finally succumb to a cold/flu that's been doing the rounds locally, and my brain isn't quite up to thinking about much right now.

I'm aware of the ExecuteProgram() function in .NET, but I'm guessing that won't allow for the Wait/Sync options?
Also, how could I implement all the Bit functions?

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: MCode Actions and custom buttons

Post by TomKerekes » Wed Jan 03, 2024 1:26 am

Hi Moray,

Hope you feel better soon.
I'm aware of the ExecuteProgram() function in .NET, but I'm guessing that won't allow for the Wait/Sync options?
Its not common to need or want those options for a button. But the wait option could be implemented by waiting until the Thread goes inactive indicating it terminated. See the Main Status ThreadActive property.
how could I implement all the Bit functions?
You can easily set/clear IO bits from the .NET App. One way is to Create a KM_IO object and use its SetDigitalValue method. Another simple method is to use WriteLine() to send a Console Command such as SetBit46.

I suppose the real issue isn't how to write code to do things but more how to allow the Operator to configure to do things without him writing code.
Regards,

Tom Kerekes
Dynomotion, Inc.

Moray
Posts: 282
Joined: Thu Apr 26, 2018 10:16 pm

Re: MCode Actions and custom buttons

Post by Moray » Wed Jan 03, 2024 10:47 pm

TomKerekes wrote:
Wed Jan 03, 2024 1:26 am
I suppose the real issue isn't how to write code to do things but more how to allow the Operator to configure to do things without him writing code.
That is something I'm trying to be very aware off.
I have ideas, and have actually got as far as implementing one of them (can create a basic init file via selecting settings, with no manual editing required), but my main goal is to get a functional C# alternative to KMotionCNC just now that can be expanded later.

Moray
Posts: 282
Joined: Thu Apr 26, 2018 10:16 pm

Re: MCode Actions and custom buttons

Post by Moray » Wed Jan 17, 2024 9:01 pm

I've just finished adding the code to control bits, and was making some checks with KMotionCNC.

As part of executing programs with a User Button, I noticed KMotionCNC allows you to set a Var.
Is this ever used with a User Button, as I can't think of how it'd actually be used, given I don't think a user button can transfer any data (unlike something like a M6 setting which would transfer the requested speed)?

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: MCode Actions and custom buttons

Post by TomKerekes » Wed Jan 17, 2024 10:48 pm

With an Execute C Program Action the Action will place the Action Index into the Persist Variable. This allows the same C Program to be used by multiple User Buttons and allows the C Program to determine which Button invoked it.

Additional Screen Script Button Actions are created dynamically and do not have an index so the index is passed as -1 to indicate this. In this case the Action places the 3rd floating point parameter of the Action into the Persist Variable. This allows the C Program to receive a parameter which could be used to identify the Button or be used as a parameter for example as a distance to move.

Here a value of 22 is passed to cause a probe of type 22.

ActionParameter.png
ActionParameter.png (5.94 KiB) Viewed 156 times
Regards,

Tom Kerekes
Dynomotion, Inc.

Moray
Posts: 282
Joined: Thu Apr 26, 2018 10:16 pm

Re: MCode Actions and custom buttons

Post by Moray » Wed Jan 17, 2024 11:14 pm

Thanks Tom.

I'll add it to the list of things to think about, as although I'm not using Action Indexes for my own user buttons, I can see the benefit of replicating that functionality in some form.

Post Reply