MCode Actions and custom buttons
Moderators: TomKerekes, dynomotion
MCode Actions and custom buttons
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?
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?
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: MCode Actions and custom buttons
Hi Moray,
Currently I believe you would need to reconfigure some Action and invoke it.
There is a function:
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
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.
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)
Code: Select all
int CScreen::DoAction(CStringW s)
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: MCode Actions and custom buttons
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?
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?
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: MCode Actions and custom buttons
Hi Moray,
Hope you feel better soon.
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.
Hope you feel better soon.
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.I'm aware of the ExecuteProgram() function in .NET, but I'm guessing that won't allow for the Wait/Sync options?
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.how could I implement all the Bit functions?
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.
Tom Kerekes
Dynomotion, Inc.
Re: MCode Actions and custom buttons
That is something I'm trying to be very aware off.TomKerekes wrote: ↑Wed Jan 03, 2024 1:26 amI 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.
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.
Re: MCode Actions and custom buttons
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)?
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)?
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: MCode Actions and custom buttons
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.
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.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: MCode Actions and custom buttons
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.
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.