Syntax for command files (.CM)

  • Hi!

    I made this topic to show you a very nice feature that is not listed in any manual from Fanuc.

    The following quote is my original post (from which this topic came), you can generally skip it and go straight to the description of the .CM files.

    Please feel free to contribute and leave a Thank you :icon_wink:

    The list contains .CM instructions grouped according to their functionality. Instructions in each group are listed alphabetically (at least more-or-less :icon_wink:).

    What is a .CM file?

    I guess it's a tool dedicated for Fanuc software developers. Basically, it's a file that can be executed using the FILE menu of the robot. It can perform various operations on files, programs (including .PC), variables (in specific programs or the system), print out information etc. It's a perfect solution for changing the robot configuration or creating installation procedures for custom software. For example, it is possible to:

      • quickly change the robot configuration from delivery state to a specification that you use as standard, by operating on system variables

      • create a kind of "installation wizards" for your custom-made software: loading files, running programs, setting up desired system variables etc. Hint: what Fanuc does (and what I have also implemented) is creating various .PC programs which perform operations more advanced than the .CM syntax allows, but loading, running, then deleting them and their variables using the .CM file, according to the logic evaluated in the .CM file)

      • ...and many more, the possibilities here are really great!

    .CM files can be executed in Cold/Hot- and Controlled-Start modes of the controller.

    How do I create a .CM FILE?

    .CM files are just text files that contain a set of instructions for the controller (they do not even have to be placed in separate lines). You can create a .CM file using any text editor (including a standard Windows Notepad). You just write the instructions, save the file with a .CM extension and that's it. Example (based on a software package's installation .CM-file that I have created):

    How do I run a .CM FILE?

    Create a .CM file, load it to a memory device (like an USB-stick), connect it to the robot, find the file using the FILE menu and then just select it, press ENTER and confirm with F4 - YES. The .CM files are not loadable, you just execute them from where they are.
    Just remember to run your .CMs in the main window of the Teach Pendant (the left one when the screen is split). The file will be executed, with an appropriate information after the successful completion (that you should confirm with F4 - OK). That's all!


    General remarks:

      • Be careful when trying to make your file clearer by implementing spaces and/or tabulators in the layout. SOME INSTRUCTIONS DO NOT WORK WITH TABs (e.g. PCVLOAD), AND OTHERS WITH SPACES (e.g. KCL) BEFORE THE ACTUAL INSTRUCTION. Either do not use tabs/spaces before instructions, or test the file for proper function when using them.


    KCL (Karel Command Language):

    KCL anyKCLcommand - this allows you to use KCL commands, listed in the Karel Reference Manual. You can use it for operations on variables, files etc, for example:

    KCL SET VARIABLE [ProgramName] variable=value



    This is definitely the most powerful tool for .CM files, as the KCL commands (described in the Karel manual) allow you a better control over the performed operations, and the command palette is much wider than the one of standard .CM instructions.


    IF statement - note: arguments listed one after another seem to be interpreted as OR - see the 2nd example of ORDER evaluation with IF.

      • IF VAR VarName "VarValue" ... ELSE ... ENDIF - evaluates the value of the specified variable. Be sure to compare the variable with a correct data type. This function seems to have problems when working with variable arrays, like the $CUSTOMMENU variable...

      • IF ORDER xxxx ... ELSE ... ENDIF - evaluates the robot specification.

    IF ORDER J737 J738 !this syntax I assume means "OR"

    IF ORDER J654 J655 J656
    PRINT "Load"
    runpc inst


    SETVAR $VarName VarValue - sets the specified system variable to the specified value. Be sure to use same data types.

    SETVAR $UALRM_MSG[1] "Invalid Argument"


    This instruction comes from this reply by lexx905. I've done some interpretation of the instruction's parameters and I hope it's ok. Multiple examples provided below should help. I haven't tested this instruction yet, but I assume, that standard limitations to IOs apply here (so setting unsimulated inputs may be impossible).
    SETIOVAL type index sim_mask unsim_val sim_val - sets an IO point of selected type to a selected value in a selected mode, where:

      • type:
        1 = DI
        2 = DO
        8 = RI
        9 = RO

      • index is just an index number of the IO point

      • sim_mask:
        0 = signal unsimulated
        1 = signal simulated

      • unsim_val is the value in UNSIMULATED mode

      • sim_val is the value in SIMULATED mode


    Note, that:

      • instructions which are type-specific (designed to work with a particular filetype, like PCLOAD for PC-files only, VRCLEAR for .VR, etc.) should all work as described for PCLOAD - with full path, or just a filename (with the extension ommited in this case). However, there are some exceptions (like VRLOAD or TPLOAD) - as this is not an official feature, the syntax is a bit messy sometimes...

      • generally, adressing goes as follows: you can use dev:filename when the addressed file is in the root folder of the selected device, but you have to use dev:\folder\...\filename.filetype if it is located deeper in the structure.

    ASLOAD filename - loads namefile.AS (assembly files - used internally)

    COPY device:\(path\)sourcefile.filetype device:\(path\)targetfile.filetype - copies sourcefile to targetfile.


    DEL filepath:\filename.filetype\ - deletes filename.filetype located in filepath

    DELFR FR:\filename.filetype - deletes filename.filetype from FROM (can also be used to delete files from FRS - internal system memory, not accessible via TP):


    DELPC ProgramName - deletes the specified .PC program from the robot memory

    DELTP ProgramName - deletes the specified .TP program from the robot memory. Important: this instruction will simply ignore a non-existing .TP program. This means it can be used before TP loading instructions to make sure they do not hit an existing file (which leads to .CM file execution being aborted). More in THIS post.

    FRCOPY fr_:\targetfile.filetype dev:\sourcefile.filetype - copies a source file to specified location on FROM. fr_ is for FR, FRS, FRSU, FRB - however, have no idea what the last two mean). Can be used to copy any type of files, including .SV and .IO:


    MKDIR device:folder - creates a folder under a specified address

    ! create a folder "test" on USB stick in the controller's USB port
    MKDIR UD1:test

    PCCLEAR filename - clears namefile.PC (removes from program stack)

    PCLOAD Device:\PathToProgram\ProgName.PC - loads the specified .PC program


    Can be also used just with a program name (without the path) - the program will be loaded from the currently selected device:

    PCLOAD ProgName ! notice, that the .PC extension is omitted in this case!

    PCVLOAD filename - loads filename.SV (no .SV-extension in the instruction!)

    RUNPC ProgramName - runs the specified .PC program that is loaded to the robot (no .PC-extension in the instruction!)

    TPLOAD or TPLOAD - loads the specified .TP program to the robot memory (.TP-extension required!), for example:


    TXPLOAD filename - loads filename.TX (no .TX-extension in the instruction!)

    VRCLEAR ProgramName - deletes the .VR file of the specified program from the robot's memory (no .PC- or .VR-extension in the instruction!)

    VRLOAD device:filename.vr - loads a specified .VR file to the robot's memory (.VR-extension required!), for example:

    VRLOAD UT1:my_vrfile.vr

    WR_FILE device:filename.filetype "text" - attaches a given text to the contents of the given file. I guess this instruction can only modify files in the root folder of a selected device.

    WR_FILE MED:AUKEPDCS.DAT "Don't init DCS safety parameter"


    @path:\ - executes another .CM file from within the current .CM file. Can be used without path - in this case, the current device and path will be used. If the .CM file is located in the root folder of the memory device, backslash can be ommited in path. Examples:

    Code ! executes from MD:
    @ud1:\program\ ! executes from UD1:\program ! executes from the currently selected location (device/path)

    CLRALMH - clears alarm history

    DELAY # - delays execution of the .cm file by # milliseconds. DELAY 1000 will wait 1 second.

    EXIT - finishes the .CM file execution. Can be used in IFs, to finish the execution before the whole program is completed (on errors for example).

    IGALBKUP device:\folder - stores an AoA backup in a specified folder

    ! store an AoA in a folder "test" on USB stick in the controller's USB port
    IGALBKUP UD1:\test

    PRINT "string" - displays the specified string. If you do not use quotation marks, only the string up to the first space will be displayed. If you use quotation marks, the whole string between them will be displayed, BUT including the marks.

    PRINT "Hello user"

    SPEP_ON / SPEP_OFF - not sure what these instructions do, but Fanuc uses SPEP_OFF right before operations like MKDIR, DEL, COPY or other istructions which operate on the structure of files or folders, and SPEP_ON right after these instructions, like in the example below (taken straight from a .CM file made by Fanuc)
    EDIT: these instructions allow you to ignore errors from some instructions and avoid breaking the whole sequence because of one instruction returning an error. SPEP_OFF makes the .CM execution ignore the errors, SPEP_ON makes it vulnerable to faults again.
    In the example below, if file TEMP_MEMORY_STAT.DG doesn't exist or any other fault is encountered by the COPY... instructions, the execution of the .CM file will not be aborted:

    WR_FILE MED:AUKEPDCS.DAT "Don't init DCS safety parameter"

    There are also instructions like COLDSPEP_ON and COLDSPEP_OFF, but found them only in 1 file and ofc have no idea what they do...

    RE_POWER - cycles power on the controller. Be careful with this instruction - I have only tested it in Roboguide so far and it works OK when the .CM file is executed in Cold-Start, but causes a VARS-204 Power-off incomplete fault when in Controlled-Start!

  • AD
  • It is unfortunate that this is not documented anywhere, but I found the IF statement synax in one of Fanuc's .cm files.

    Here it is:

    Check out the Fanuc position converter I wrote here!

  • Thanks. I guess Fanuc keeps that syntax to themselves... I have found exactly the same function in some .CM file. I guess that there are some limits with using array variables in that IF function which I am not aware of (I have tried changing some items in CUSTOMMENU variable array, but no luck), but that is a start.

    Maybe we could make a topic like the one with BG-Logic for these .CM files? What would moderators say to that? I could just add things posted in this topic to the first post and make a nice list this way... So, for example:


    .PC Programs:

    DELPC programname - deletes the specified .PC program from the robot memory

    PCLOAD programname - loads the specified .PC program from a current device

    RUNPC programname - runs the specified .PC program

    VRCLEAR programname - deletes the .VR file of the specified program

    Edited once, last by bidzej ().

  • More commands found in various .CM files :

    # PCVLOAD namefile - to load namefile.SV
    # TXPLOAD namefile - to load namefile.TX
    # ASLOAD namefile - to load namefile.AS (assembly files - used internally)

    #PCCLEAR namefile - to clear namefile.PC
    #DELFR FR:namefile.filetype - to delete namefile.filetype from FROM
    #DEL filepath:\filename.filetype\ - to delete filename.filetype located in filepath

  • You are a very great guy, nobody can learn these great info. from any FANUC manual.
    I have a question about '*.as file' which seems that you are good at it, I got a as-file, however, I can not understand the code inside.
    by the way,can you share more about karel software development, I am also interested in it.

  • Honestly, don't remember what exactly is in the .AS files and don't have an appropriate manual at the moment. Maybe someone else can help here?

    When it comes to Karel... Well, there is a separate manual for that, but to really be able to do some sensible programming, you need experience. Mainly because not everything works as described in the manual, especially things that have anything to do with motion. As far as I know, these motion instructions are somewhat old and not always compatible with the newest controllers, as Fanuc gave up the development of KAREL motion some time ago.

  • Quote

    I have a question about '*.as file' which seems that you are good at it, I got a as-file, however, I can not understand the code inside.

    .as files are Assembly files, basically they are used to perform direct manipulation of internal memory (or registry) of the Operating system

  • thanks for your advice
    I'm totally agree with you, the info., in the karel manual, sometimes makes me waste much time to understand, because some incorrect info. will mislead me and i have to do many experiments to get one point from it.
    as you said, the motion part in J3iB Karel manual can not be found in the new manual. however, as a software developer, it's important.
    I am learning from your *.CM FILE, and I'll work hard on karel programming, there's so much fun in it.
    if you have any info, about karel, i will be your first fan to follow it.

  • .as files are Assembly files, basically they are used to perform direct manipulation of internal memory (or registry) of the Operating system

    i got two *as file, however, I really dont understand about it's rules in it.
    1:% ASM #2 EMCD #2#1
    2:$0a000000 #31 $F4 !Online shift use$CUSTOMMENU[4]

    i can understand the first line, but, I cant transfer the second line's code one by one
    i can guess the function about the second line.

    the other prog.
    1:% ASM #2 TOPK #2#3#1
    2:07000000#31 $F5 !F7:CAN/STR(CANCEL/Start line)
    3:08000000#31 $F6 !F8:LOG/END(Log/End line)
    4:09000000#31 $F7 !F9:CAN/STR(Start/Convert)

    if you have any advance to share, feel free. thanks.

  • I've been learning cm.file for two weeks, and I found [PCVLOAD] also used in the *.vr and *.pc files.
    when used in *pc.file load, it's also same to PCLOAD.
    if anything is incorrect, thanks for your suggestion.

  • Hi,master bidzej
    I'll add some syntax about CM-file, which I also don't know about its function.However, I wish master bidzej or someone will fix it out oneday. :nanananana:
    the structure is

    another question is about [How to Start the CM.file]
    if there's no KCL command in the cm.file,I can start the CM.file.
    However, if the cm.file contains the KCL command, I need to set the varaible [$RMT_MASTER] to '1', disable the teach pedant, and switch to AUTO mode. In the case, I can start the CM.file finally

  • And still, using such a construction -> SETVAR $ CCSCB2_GRP [1]. $ FS_TYP2 1, you do not ever refer to a variable of type STRING.
    It is better to refer to the variables like this:

  • Change Status - Di\Do\Ri\Ro\Flag

    !DI 33 SET Sim Mode and True
    SETIOVAL 1 33 1 0 1

    !DI 34 SET Sim Mode and False
    SETIOVAL 1 34 1 0 0

    !DI 35 SET UnSim Mode
    SETIOVAL 1 35 0 0 0

    !DO 33 SET Sim Mode and True
    SETIOVAL 2 33 1 0 1

    !DO 34 SET Sim Mode and False
    SETIOVAL 2 34 1 0 0

    !DO 35 SET False
    SETIOVAL 2 35 0 0 0

    !DO 36 SET TRUE
    SETIOVAL 2 36 0 1 0

    !RI 1 SET Sim Mode and True
    SETIOVAL 8 1 1 0 1

    !RO 1 SET Sim Mode and True
    SETIOVAL 9 1 1 0 1

    !Flag[10] = true
    SETIOVAL 35 10 0 1 0

    !Flag[11] = false
    SETIOVAL 35 11 0 0 0

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account
Sign up for a new account in our community. It's easy!
Register a new account
Sign in
Already have an account? Sign in here.
Sign in Now