Page 1 of 1

MCodes and how to use them in an application

Posted: Tue Oct 08, 2019 10:13 am
by Juanjo-Lasing
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?

Re: MCodes and how to use them in an application

Posted: Tue Oct 08, 2019 5:44 pm
by TomKerekes
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

Re: MCodes and how to use them in an application

Posted: Fri Oct 11, 2019 7:45 am
by Juanjo-Lasing
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?

Re: MCodes and how to use them in an application

Posted: Fri Oct 11, 2019 5:27 pm
by TomKerekes
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.