MCodes and how to use them in an application

Moderators: TomKerekes, dynomotion

Post Reply
Juanjo-Lasing
Posts: 25
Joined: Wed Sep 04, 2019 11:56 am

MCodes and how to use them in an application

Post by Juanjo-Lasing » Tue Oct 08, 2019 10:13 am

Hello,

I have new questions, this time regarding the use and interpretation of MCodes. In KMCNC the user can modify the definitions of MCodes and change their behaviour when running a GCode (running a C file, stopping the program, etc). In the libraries I found the enumeration MCODE_TYPE where there are defining ten MCodes.

I don't know how to use this definitions. For example, when I write M4 in a GCode and run it (using my aplication), the interpreter ignores it, but when I write M0 the program stops.

My questions are:
  • Can I change the definitions of te MCodes? If I can, how I do it?
  • The definitions of the enumeration MCODES_TYPE affect the behavior of the GCode interpreter in any code?
  • Some definitions, like M4 or M5 are for running C programms. How can I indicate the C program they have to run?

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

Re: MCodes and how to use them in an application

Post by TomKerekes » Tue Oct 08, 2019 5:44 pm

Hi Juanjo-Lasing,

The GCode Interpreter has a method of invoking generalized "Actions". Actions can be invoked from MCodes, S Words, User Defined Buttons, or Special Actions. The Actions performed can be various operations such as changing the states of one or two I/O Bits, writing a Speed value to a DAC, Invoking a User C Program in KFLOP, Invoking a PC Program, Application Callback, or Executing GCode.

The link you provided to MCODE_TYPE defines what type of Action to perform. It is not related to an MCode Number. An Action consists of an MCODE_TYPE and several parameters (numeric and a string). The number and purpose of the parameters vary depending on the MCODE_TYPE.

The Interpreter allows you to configure about 30 MCodes to perform Actions. Several MCodes such as M0 (stop) and M30 (stop/rewind) have Interpreter functionality, but can also perform an additional Action. 20 MCodes (100-119) are for User use.

The Interpreter's 'S' word can also invoke an Action.

The KMotionCNC Application also uses Actions assigned to custom User Buttons and to "Special Actions" that are executed on operations such as Application Startup. All Actions are stored in an array and referenced by the index into the array (not necessarily the MCode number). See the chart in the wiki here.

You might read how KMotionCNC allows the MCode Actions to be configured in its Tool Setup. See here and here.

From .NET you can configure the Action Array using the KM_Interpreter.SetMcodeAction Method

After the Action Array in the Interpreter is configured any Interpreted MCode (or S) will perform the configured Action.

Note that MCodes can also set GCode Parameters (PQR words) into KFLOP persist variables. This is described here.

This Yahoo Thread may also help.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

Juanjo-Lasing
Posts: 25
Joined: Wed Sep 04, 2019 11:56 am

Re: MCodes and how to use them in an application

Post by Juanjo-Lasing » Fri Oct 11, 2019 7:45 am

Hi Tom,

Thank you as always. I managed to implement it in my application and now it works well.

Another question.
Several MCodes such as M0 (stop) and M30 (stop/rewind) have Interpreter functionality, but can also perform an additional Action.
I understand that M0-M9 have defined functionality, but if I change that functionality with KM_Interpreter.SetMcodeAction, then these MCodes will run the new functionality and ignore the original one?

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

Re: MCodes and how to use them in an application

Post by TomKerekes » Fri Oct 11, 2019 5:27 pm

Hi Juanjo-Lasing,
I understand that M0-M9 have defined functionality, but if I change that functionality with KM_Interpreter.SetMcodeAction, then these MCodes will run the new functionality and ignore the original one?
No. It will do that Action in addition to any normal functionality.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply