Skip to content

M198: calling a program from external memory

M198 calls a program that is not in the control memory but on an external device: a card, a USB drive or a shared network folder. The control reads it as it runs it, which lets you work with programs far larger than internal memory can hold, typically 3D machining programs out of CAM. When it finishes it hands control back to the program that called it, just like M98, and the device setup is done by the machine builder.

For reference only: syntax changes with the control, the post-processor and the machine parameters. Check the official manual and run a simulation before cutting. Legal notice.

The brands and control names mentioned belong to their owners and are used only to identify the equipment. GetGCode is not affiliated with or endorsed by any manufacturer, ISO or ASME: this is our own content, not official documentation. Legal notice.

Family
Subprograms
Machine
Milling, Turning, Mill-turn
Risk
Medium
Example
M198 P1234 (Fanuc) / M198 P1234 (Haas)

Syntax by control

Fanuc
M198 P1234
Calls program 1234 on the configured external device. The program has to be in the correct folder and carry the name the control expects, which depends on a machine setting.
Haas
M98 (<path>/O01234)
M198 is not listed as a standard Haas code. To call a subprogram on another device, Haas uses M98 with the program path. Check the format in the manual for your software version.
Running directly from the device
DNC mode or run-from-external-memory mode
Alternative to M198: instead of calling the external program from another one, you run the external file directly. This is what is used for complete 3D machining programs.
Mazak
Depends on control and version
Mazak controls may offer equivalent functions with their own nuances. Before moving a program to a Mazak, check how this call behaves on that control.

Address letters used with it

LetterWhat it setsUnit
PNumber or name of the external program being called. The format, and whether it accepts a path, depend on the machine configuration.program number
Configured deviceCard, USB drive or network folder it reads from. The control only looks where it has been told to, and that setup was done by the machine builder or the integrator.path or device
M99The external program ends with M99 to hand control back to the calling program, like any subprogram.no parameters
Read speedThe control has to read blocks at the rate it executes them. In programs with very short moves, a slow connection can become the bottleneck.blocks per second

Worked example

Main program in memory that does the roughing and calls a 3D finishing program of several megabytes stored on the network. The example shows where the call goes and what precautions to take so that a lost connection does not leave the tool stopped inside the part.

O1980 (PRINCIPAL CON ACABADO 3D EXTERNO)
( Main program header; this one does sit in the control memory. )
(COMPROBAR CONEXION ANTES DE LANZAR LA SERIE)
( Operational reminder: the external call depends on the device being available. )
G21 G17 G40 G49 G80
( Safety block. )
T2 M06
( Roughing end mill. )
G90 G54 G00 X0. Y0.
( Work offset and positioning. )
G43 H02 Z50. M03 S4000 M08
( Length offset, spindle and coolant. )
(desbaste completo en el programa principal)
( The roughing is a short program that fits in memory with room to spare. )
G00 Z100. M09
( Retract to a safe height before the change. )
G91 G28 Z0.
( Z to the reference point. )
T5 M06
( Finishing ball end mill. )
G90 G54 G00 X0. Y0.
( Back to the origin with the new tool. )
G43 H05 Z50. M03 S12000 M08
( Finishing conditions. )
M198 P5000
( Calls the 3D finishing program stored on the network. The control reads it as it runs it, so the connection has to hold for the whole operation. )
(el programa externo hace el acabado y termina con M99)
( When it finishes it returns control here, to the next block. )
G00 Z100. M09
( Retract and coolant off. )
G91 G28 Z0. M05
( Z to the reference point and spindle stop. )
G90 M30
( End of the main program. )
Open the simulator to check the example

Practical keys to using M198 in the workshop

What this function is for

CNC control memory is limited, and a 3D finishing program for a mold can take up tens of megabytes with hundreds of thousands of blocks. It does not fit, and even if it did it would take up all the machine's memory. The solution is for the control to read the file from outside as it runs it, keeping in memory only a window of blocks ahead. That allows programs of any size, at the cost of the machine depending on a connection for the whole operation.

Depending on the connection

The price of reading from outside is that execution stops if the device goes away. A USB drive that works loose, a network that goes down or a server that restarts leaves the machine with no blocks to run and the tool stopped wherever it was. In a finish pass, that leaves a mark on the surface. That is why in production you check the connection before starting the run, you prefer a wired connection to a wireless one and, when size allows, you copy the program to the control memory.

Read speed and cycle time

In 3D machining with very short moves, the machine can execute several hundred blocks per second, and the control has to be able to read them at the same rate. A slow connection or a low-speed card becomes the bottleneck and the machine moves in jerks, with a worse finish and a longer cycle time than planned. If a program that should run smoothly stutters, check where it is being read from before blaming the machine parameters.

Mistakes that cost you a part (or a tool)

  • Starting a production run without checking that the external device is connected and that the program is where the control looks for it.
  • Using an unstable wireless connection for a finishing operation that lasts hours.
  • Leaving the external program without an M99 at the end, so it does not return control to the main program.
  • Saving the file with a name or in a folder other than what the machine configuration expects.
  • Assuming performance will be the same as from internal memory in programs with very short moves.
  • Not leaving the machine in a known position before the call, so the external program depends on wherever the tool happened to be.

Frequently asked questions

How is it different from M98?

M98 calls a subprogram in the control memory; M198 calls one on an external device, which the control reads as it runs it. Everything else is the same: the called program ends with M99 and returns control to the next block.

Where does the program have to be?

On the device and in the folder the machine is configured for, with the name the control expects. That setup was done by the machine builder or the integrator and you can look it up in the settings. It is the most common reason for the call to fail with a program that exists, just not where the control is looking.

What happens if the connection drops?

The control runs out of blocks and stops the program with an alarm, with the tool stopped wherever it was. In a finish pass that leaves a mark. That is why you want a wired connection, a check beforehand and, if the program fits, a copy in the machine memory.

Can I run the external file directly without M198?

Yes, most controls let you run directly from the external device, which is the usual way for complete 3D machining programs. M198 makes sense when the main program is in memory and only one part, normally the largest, lives outside.

Does it run slower than from internal memory?

It can run slower in programs with very short moves, where the control needs to read hundreds of blocks per second. With a fast wired connection the difference is usually irrelevant; with a slow card or a saturated network, the machine moves in jerks and the finish suffers.

Related codes

M98/M99Mazak M96/M198/M199G65M30

Other codes in Subprograms

See the full list of G and M codes

Related apps