Syntax For Fanuc Command Files (.CM)
Syntax For Fanuc Command Files (.CM)
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.
Quote
I am working on some small Karel software solution, that is sold to our customers as a "software package". To make the installation easier for the customer, I have prepared a .CM file
that loads all necessary files (.PC, .VR, .TP, .TX etc.) to the robot and it works great. The thing is, that I would also like the file to do some more advanced changes or be flexible
(allowing it to react to some unpredicted situations). As far as I know, it is doable, but can't seem to find any help on the syntax.
The commands that I use in the current file are taken from some other Fanc .CM files. These are:
# PRINT
# PCLOAD
# VRLOAD
# TPLOAD
# KCL LOAD FORM (this one allows me to think, that it is possible to use the KCL commands in the .CM files, but that does not help a lot, as I would also like to check some values and
use conditional instructions if possible)
EDIT:
Okay, so this topic became a sticky one :icon_mrgreen: I will gather all the syntax posted in this topic in the first post, so that it is easy to find. Also, I will try to explain as much on the
.CM files as I can find.
Please feel free to post anything you find out on .CM files, your suggestions, corrections or anything else which can make this topic better :)
The list contains .CM instructions grouped according to their functionality. Instructions in each group are listed alphabetically (at least more-or-
less :icon_wink:).
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.
Code: [Select]
PRINT "#############################"
PRINT "# Installing a program #"
PRINT "#############################"
https://www.robot-forum.com/robotforum/fanuc-robot-support-forum/syntax-for-command-files-(-cm)/?action=printpage 1/10
3/6/2019 Print Page - Syntax for command files (.CM)
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.
====================================================================================================
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 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...
Code: [Select]
IF VAR $APPLICATION[2] "V7.30P/*"
SETVAR $CCSCB2_GRP[1].$FS_TYP2 1
ELSE
IF VAR $APPLICATION[2] "V7.40P/*"
SETVAR $CCSCB2_GRP[1].$FS_TYP2 1
ELSE
IF VAR $APPLICATION[2] "V7.50P/*"
SETVAR $CCSCB2_GRP[1].$FS_TYP2 1
ELSE
IF VAR $APPLICATION[2] "V7.60P/*"
SETVAR $CCSCB2_GRP[1].$FS_TYP2 1
ENDIF
ENDIF
ENDIF
ENDIF
IF ORDER xxxx ... ELSE ... ENDIF - evaluates the robot specification.
Code: [Select]
IF ORDER J737 J738 !this syntax I assume means "OR"
...
ENDIF
Code: [Select]
IF ORDER J654 J655 J656
PRINT "Load"
PRINT "SHELLSTART"
runpc inst
ENDIF
OPERATIONS ON VARIABLES:
SETVAR $VarName VarValue - sets the specified system variable to the specified value. Be sure to use same data types.
Code: [Select]
SETVAR $UALRM_MSG[1] "Invalid Argument"
OPERATIONS ON IOs:
This instruction comes from this reply (https://www.robot-forum.com/robotforum/fanuc-robot-forum/syntax-for-command-files-(-
cm)/msg99133/#msg99133) 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
35=Flag
index is just an index number of the IO point
sim_mask:
0 = signal unsimulated
https://www.robot-forum.com/robotforum/fanuc-robot-support-forum/syntax-for-command-files-(-cm)/?action=printpage 2/10
3/6/2019 Print Page - Syntax for command files (.CM)
1 = signal simulated
unsim_val is the value in UNSIMULATED mode
sim_val is the value in SIMULATED mode
Code: [Select]
!***************
!DI 33 SET Sim Mode and True
SETIOVAL 1 33 1 0 1
!***************
!DO 33 SET Sim Mode and True
SETIOVAL 2 33 1 0 1
!************
!RI 1 SET Sim Mode and True
SETIOVAL 8 1 1 0 1
!************
!Flag[10] = true
SETIOVAL 35 10 0 1 0
!Flag[11] = false
SETIOVAL 35 11 0 0 0
PROGRAMS, FILES:
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.
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):
Code: [Select]
DELFR FRS:\CTRLRSTR.DAT
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 (https://www.robot-forum.com/robotforum/fanuc-robot-forum/syntax-for-command-files-(-
cm)/msg103057/#msg103057) 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:
Code: [Select]
FRCOPY frs:diocfgsv.io MD:diocfgsv.io
Can be also used just with a program name (without the path) - the program will be loaded from the currently selected device:
Code: [Select]
PCLOAD ProgName ! notice, that the .PC extension is omitted in this case!
RUNPC ProgramName - runs the specified .PC program that is loaded to the robot (no .PC-extension in the instruction!)
https://www.robot-forum.com/robotforum/fanuc-robot-support-forum/syntax-for-command-files-(-cm)/?action=printpage 3/10
3/6/2019 Print Page - Syntax for command files (.CM)
TPLOAD programname.tp or TPLOAD device:program.tp - loads the specified .TP program to the robot memory (.TP-extension required!),
for example:
Code: [Select]
TPLOAD my_tpprogram.tp
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:
Code: [Select]
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.
Code: [Select]
WR_FILE MED:AUKEPDCS.DAT "Don't init DCS safety parameter"
OTHER INSTRUCTIONS:
@path:\file.cm - 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: [Select]
@md:setup.cm ! executes setup.cm from MD:
@ud1:\program\setup.cm ! executes setup.cm from UD1:\program
@setup.cm ! executes setup.cm from the currently selected location (device/path)
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).
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.
Code: [Select]
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:
Code: [Select]
SPEP_OFF
COPY MD:\MEMORY.DG MED:\00\TEMP\TEMP_MEMORY_STAT.DG
SPEP_ON
SPEP_OFF
DEL MED:AUKEPDCS.DAT
WR_FILE MED:AUKEPDCS.DAT "Don't init DCS safety parameter"
SPEP_ON
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!
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:
Code: [Select]
IF VAR $APPLICATION[2] "V7.30P/*"
SETVAR $CCSCB2_GRP[1].$FS_TYP2 1
ELSE
IF VAR $APPLICATION[2] "V7.40P/*"
SETVAR $CCSCB2_GRP[1].$FS_TYP2 1
ELSE
IF VAR $APPLICATION[2] "V7.50P/*"
SETVAR $CCSCB2_GRP[1].$FS_TYP2 1
ELSE
IF VAR $APPLICATION[2] "V7.60P/*"
SETVAR $CCSCB2_GRP[1].$FS_TYP2 1
ENDIF
ENDIF
ENDIF
ENDIF
https://www.robot-forum.com/robotforum/fanuc-robot-support-forum/syntax-for-command-files-(-cm)/?action=printpage 4/10
3/6/2019 Print Page - Syntax for command files (.CM)
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:
PROGRAM CONTROL:
.PC Programs:
DELPC programname - deletes the specified .PC program from the robot memory
PCLOAD programname - loads the specified .PC program from a current device
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
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
[/quote]
i got two *as file, however, I really dont understand about it's rules in it.
https://www.robot-forum.com/robotforum/fanuc-robot-support-forum/syntax-for-command-files-(-cm)/?action=printpage 5/10
3/6/2019 Print Page - Syntax for command files (.CM)
e.g.
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.
Hi Chander_hxj
Fabian
Hi Fabian,
I'm sorry to make this mistake.
Chandler_HXJ
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.
PROGRAM CONTROL:[/b]
.PC Programs:
DELPC programname - deletes the specified .PC program from the robot memory
PCLOAD programname - loads the specified .PC program from a current device
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
1.#SPEP_ON.........#SPEP_OFF
2.#FRCLRPR.........#FRSETPR
https://www.robot-forum.com/robotforum/fanuc-robot-support-forum/syntax-for-command-files-(-cm)/?action=printpage 6/10
3/6/2019 Print Page - Syntax for command files (.CM)
I have also seen these SPEP instructions in some .CM files, but have no idea what they do...
Ciao
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:
KCL SET VAR $ ATCELLSETUP. $ HOME_MACRO = 'BLA_BLA'
KCL SET VAR $ ACC_MAXLMT = 15
KCL SET VAR $ AP_AUTOMODE = TRUE
that SETVAR... comes from some Fanuc .CM, that's why I mentioned it. The KCL SET VAR instructions are listed already. Thx for your input!
:merci:
Ciao
MKDIR UD1:test
IGALBKUP UD1:\test
EXIT
This code will automatically create a TEST folder on the USB and put AOA and IMAGE on it :)
!***************
!DI 33 SET Sim Mode and True
SETIOVAL 1 33 1 0 1
!***************
!DO 33 SET Sim Mode and True
SETIOVAL 2 33 1 0 1
!************
!RI 1 SET Sim Mode and True
SETIOVAL 8 1 1 0 1
!************
!Flag[10] = true
SETIOVAL 35 10 0 1 0
!Flag[11] = false
SETIOVAL 35 11 0 0 0
https://www.robot-forum.com/robotforum/fanuc-robot-support-forum/syntax-for-command-files-(-cm)/?action=printpage 7/10
3/6/2019 Print Page - Syntax for command files (.CM)
great, thanks!
I have just added a few more instructions to the list (WR_FILE, SPEP_ON/SPEP_OFF, COPY) and updated descriptions of a few others.
Pls let me know if this is still readable for you. Should I change the format of the list or divide it into more detailed sections?
I recently used a Command File to populate UALRMs on several(16) robots. It took minutes, instead of hours to do.
I was quickly and easily able to implement 200+ User Alarms :top:
Sample of syntax:
SETVAR $UALRM_MSG[1] "Invalid Argument"
SETVAR $UALRM_MSG[3] "BG Logic 1 not running"
SETVAR $UALRM_MSG[4] "BG Logic 2 not running"
SETVAR $UALRM_MSG[5] "BG Logic 3 not running"
SETVAR $UALRM_MSG[6] "BG Logic 4 not running"
SETVAR $UALRM_MSG[7] "BG Logic 5 not running"
SETVAR $UALRM_MSG[8] "BG Logic 6 not running"
SETVAR $UALRM_MSG[9] "BG Logic 7 not running"
DELTP program - deletes the specified .TP program from the Robot memory
Use this before TPLOAD device:program.tp (like loading from USB). It won't alarm if the file exists in Robot memory where the TPLOAD will
if the file exists & it ends the execution of the .cm file.
Hi bencor21, I've added these to the OP, thanks for your input. Could you be more specific about that overwriting?
If the .tp file already exists in the Robot controller, say TEST.tp & the TPLOAD UT1:Test.tp command is given, there will be a message
displayed "Program already exists" & you will have it hit F4 (OK), it's the only choice given. At that point, the .cm file has not completed. Just
to be on the redundant side, on the line before the TPLOAD command, give it the DELTP TEST, & even if that file does not exist in the Robot, all
will be fine.
great, thanks! This is actually what I was already missing a couple of times, never came to an idea to try that one.
Another way to work around the overwriting problem is to use the Karel equivalent in the CM file:
Instead of:
TPLOAD ALARM.TP (which will abort the CM if the file already exists)
https://www.robot-forum.com/robotforum/fanuc-robot-support-forum/syntax-for-command-files-(-cm)/?action=printpage 8/10
3/6/2019 Print Page - Syntax for command files (.CM)
I'm not sure, I've seen something similar on the R-J2's but these were called .cf files and were actually a set of KCL commands.
yes. According to the Karel manual (Chapter: File System): ".CF: KCL command files are ASCII files that contain a sequence of KCL commands
for a command procedure."
Do you have example code of how User Frames can be created using a .cm program? I am able to create User Models and CPC models easily,
but having trouble finding the variables needed to create frames in the system for CPC user frame definitions.
try finding the appropriate variables in the system and then editing them in the .CM file.
Does anyone know how to create an image backup on the USB instead of an AOA?
the code that you quoted seems to create both AoA and Image backup.
I've found some other instruction regarding backups, it's called ALL_BKUP, so it probably creates only an AoA.
DELAY #
Delays execution of the .cm file by that many milliseconds. DELAY 1000 will wait 1 second.
Just wondering if anybody had some luck with this. There is the Variable $MNUFRAME and MNUTOOL, but there is no way to access the
individual XYZWPR elements. I seen in some Karel and tp programs you can assign data to a pr and reference the pr to transfer the values, but
a XYZWPR variable needs to be declared.
it's not possible to create variables in .cm files. What you can do is create a small Karel program to do what you need, load, execute and delete
it.
Ok thanks. I did find out how to write to the MNUFRAME and MNUTOOL:
I am having trouble with the payload variables. they are all write protected even controlled start. Any ideas on how to get around this. I have
something like this:
https://www.robot-forum.com/robotforum/fanuc-robot-support-forum/syntax-for-command-files-(-cm)/?action=printpage 9/10
3/6/2019 Print Page - Syntax for command files (.CM)
KCL SET VARIABLE $PLST_GRP1[1].$PAYLOAD_IX = 0.9010
KCL SET VARIABLE $PLST_GRP1[1].$PAYLOAD_IY = 1.3140
KCL SET VARIABLE $PLST_GRP1[1].$PAYLOAD_IZ = 1.3140
https://www.robot-forum.com/robotforum/fanuc-robot-support-forum/syntax-for-command-files-(-cm)/?action=printpage 10/10









