Command File (cmdfile) Commands

See the following table for a list of commands, which can be used in a command file (<cmdfile>). The command file you then can call by a Command Line Commands. There is no case sensitivity. The command line will be displayed as a message in the message window and can be given out in a message file (see below) except the command is prefixed by a “@”.

All signs after a semicolon (;) will be ignored (comment). Parameters containing blanks must be embraced by quotation marks. Umlauts only may be used if the command file is created in ANSI code. Keywords can be used in the command parameters. A list of the keywords you find subsequent to the following tables of command descriptions.

Commands for controlling the subsequent commands:

onerror continue The subsequent commands will be executed even if an error occurs.
onerror break The subsequent commands will not be executed any more if an error has been detected.

Commands of the online menu:

online login Login with the loaded project (‘Online Login’)
online logout Logout (‘Online’ ‘Logout’)
online run Start of the application program (‘Online’ ‘Run’)
online stop Stop application program (‘Online’ ‘Stop’)
online bootproject Creation of a boot project. This command can be applied in offline and online mode! (See also description of command ‘Online’ ‘Create boot project’ ‘Online’ ‘Create boot project’!)
online sourcecodedownload Download of the sourcecode of the project to the PLC (‘Online’ ‘Sourcecode download’)
online sim Switch on of simulation mode ‘Online’ ‘Simulation’)
online sim off Switch off of simulation mode (‘Online’ ‘Simulation’)

Commands of the file menu:

file new A new project is created (‘File’ ‘New’)

file open <projectfile>

possible additions:

The project <projectfile> will be loaded (‘File’ ‘Open’)
/readpwd:<readpassword> The password for read access is given here so that no dialog asking for the password will appear when the read-protected project is opened.
/writepwd:<writepassword> The password for full access is given here, so that no dialog asking for the password will appear when the project is openend.
file close The current project will be closed (‘File’ ‘Close’)
file save The current project will be stored (‘File’ ‘Save’)

file saveas <projectfile>

optionally add: <type><version>

The current project will be saved with the file name <projectfile> (‘File’ ‘Save as’)

Default: Project will be saved as <projectfile>.pro under the current IEC 61131-3 editor version. If you want to save the project as an internal or external library or as project for an older IEC 61131-3 editor version, add the respective command:

Possible entries for <type>:

“internallib”  Save as internal library:

“externallib” Save as external library:

“pro”  Save as project for older version:

valid entries for <Version>: 15, 20, 21, 22 (product versions 1.5, 2.0, 2.1, 2.2)

Example: “file save as lib_xy internallib22”: The project “project xy.pro”, which is created in the current IEC 61131-3 editor version will be saved as “lib_xy.lib” for V2.2.

file saveas <projectfile> The current project will be saved with the file name <projectfile> (‘File’ ‘Save as’)

file printersetup <filename>.dfr

optionally add: pageperobject or

pagepersubject

Define a document frame file (‘File’ Printer setup’) and optionally define one of the print options ‘New page per object’ or ‘New page per subobject’; these settings affect the printing of the document (project documentation, see below)
file archive <filename>.zip The project will be archived in a zip-file with the given filename (‘File’ Save/Mail Archive’)
file quit IEC 61131-3 editor will be closed (‘File’ ‘Exit’)

Commands of the project menu:

project build The project that is loaded will be incrementally compiled (‘Project’ ‘Build’)
project rebuild or project compile The project that is loaded will be compiled in full (‘Project’ ‘Rebuild’)
project clean Compilation information and Online Change information in the current project will be deleted (‘Project’ ‘Clean Project’)
project check The project that is loaded will be checked (‘Project’ ‘Check all’)
project compile The current project will be compiled by “Rebuild all” (‘Project’ ‘Rebuild all’)
project check The current project will be checked (‘Project’ ‘Check’)
project build The current project will be built (‘Projekt’ ‘Build’)
project import <file1> … <fileN> The files <file1> … <fileN> get imported into the current project (‘Project’ ‘Import’). Regard: Wildcards can be used, e.g. “project import C:\projects\*.exp” will import all files with extension *.exp found in directory C:\projects.
project export <expfile> The current project will be exported in the file <expfile> (‘Project’ ‘Export’)
project expmul Each object of the current project will be exported in an own file, which gets the name of the object.
project documentation The entire project will be printed on the default printer (‘Project’ ‘Documentation’, see also above “file printersetup”)

Commands for the control of the message file:

out open <msgfile> The file <msgfile> opens as message file. New messages will be appended
out close The currently shown message file will be closed.
out clear All messages of the currently opened message file will be deleted.

Commands for the control of messages:

echo on The command lines will be displayed as messages.
echo off The command lines will not be displayed as messages.
echo <text> <text> will be displayed in the message window.

Commands for the control of replace of objects respectively for the control of files for import, export, copy:

replace yesall Replace all (any ‘query on’ command will be ignored; no dialogs will open)
replace noall Replace none (any ‘query on’ command will be ignored; no dialogs will open)
replace query If a ‘query on’ command is set, then a dialog will open regarding the replacing of the objects even if there is a ‘replace yesall’ or ‘replace noall’ command

Commands for the control of the default parameters of the dialogs:

query on Dialogs are displayed and need user input
query off ok All dialogs respond as if the user had clicked on the ‘OK’ button
query off no All dialogs respond as if the user had clicked on the ‘No’ button
query off cancel All dialogs respond as if the user had clicked on the ‘Cancel’ button

Command for calling command files as subprograms:

call <parameter1> … <parameter10> Command files will be called as subprograms. Up to 10 parameters may be passed. In the file that is called, the parameters can be accessed with $0 - $9.
call <parameter1> … <parameter10> Command files are called as subroutines. Up to ten parameters can be consigned. In the subroutine called you can access the parameters using $0 - $9.

Setting of used directories: ( -> project options dialog, category ‘Directories’, subcategory ‘General’):

If several directories are defined with one of the following commands, these must be separated by a semicolon + emptyspace and the whole row of directories must be embraced by double quotation marks.

Example, two paths: dir     lib "D:\\codesys\\Libraries\\Standard; D:\\codesys\\Libraries\\NetVar"

dir lib <libdir> Sets <libdir> as the library directory
dir compile <compiledir> Sets <compiledir> as the directory for the compilation files
dir config <configdir> Sets <configdir> as the directory for the configuration files
dir upload <uploaddir> Sets <uploaddir> as the directory for the upload files

Delaying processing of the CMDFILE:

delay 5000 Waits 5 seconds

Controlling the Watch and Receipt Manager:

watchlist load <file> Loads the Watchlist saved as <file> and opens the corresponding window (‘Extras’ ‘Load Watchlist’)
watchlist save <file> Saves the current Watchlist as <file> (‘Extras’ ‘Save Watchlist’)
watchlist set <text> The watchlist is set active (corresponds to selecting a watchlist in the left part of the Watch and Receipt Manager)
watchlist read Updates the values of the Watch variables (‘Extras’ ‘Read receipt’)
watchlist write Fills the Watch variables with the values found in the Watchlist (‘Extras’ ‘Write receipt’)

Linking libraries:

library add <library file1> <library file2> .. <library fileN> Attaches the specified library file to the library list of the currently open project. If the file path is a relative path, the library directory entered in the project is used as the root of the path.
library delete [<library1> <library2> .. <libraryN>] Deletes the specified libraries from the library list of the currently open project.

Copying objects:

object copy <source project file> <source path> <target path>

Copies objects from the specified path of the source project file to the target path of the already opened project.

If the source path is the name of an object, this will be copied. If it is a folder, all objects below this folder will be copied. In this case, the folder structure below the source folder will be duplicated.

If the target path does not yet exist, it will be created.

Read-only access for particular objects :

object setreadonly <TRUE|FALSE> <object type> | <object name>

Sets read-only access to a object; Define the object type and in case of object types pou, dut, gvl, vis also the name of the object.

Possible object types: pou, dut (data type), gvl (global variables list), vis (visualization), cnc (CNC object), liblist (Libraries), targetsettings, toolinstanceobject (particular Tools instance), toolmanagerobject (all instances in the Tools tree), customplconfig (PLC configuration), projectinfo (Project information), taskconfig (task configuration), trace, watchentrylist (Watch- and Recipe Manager), alarmconfig (Alarm configuration)

e.g. “object setreadonly TRUE pou plc_prg” will set the PLC_PRG to read-only access

Entering communications parameters (gateway, device):

gateway local Sets the gateway on the local computer as the current gateway.
gateway tcpip <Address> <Port>

Sets the gateway in the specified remote computer as the current gateway.

<Address>: TCP/IP address or hostname of the remote computer

<Port>: TCP/IP port of the remote gateway

Important: Only gateways that have no password set can be reached!

device guid <guid>

Sets the device with the specified GUID as the current device.

GUID must have the following format:

{01234567-0123-0123-0123-0123456789ABC}

The curly brackets and the hyphens must appear at the specified positions.

device instance <Instance name> Sets the instance name for the current device to the name specified
device parameter <Id> <Value> Assigns the specified value, which will then be interpreted by the device, to the parameter with the specified ID.

System call:

system <command> Carries out the specified operating system command.

Select target system:

target <Id> Sets the target platform for the current project. If IEC 61131-3 editor is getting started with command line option “/notargetchange”, only by this command a target can be set.

Query system state:

state offline Returns “S_OK”, if currently there is no connection between programming system and target system (offline mode), otherwise “HRESULT[0x800441f0)” (online mode).
state online Returns “S_OK”, if currently there is a connection between programming system and target system (online mode), otherwise “HRESULT[0x800441f0)” (offline mode).

Password for user group:

With the following settings  - when opening a project which is protected by user group passwords - you can enter the password for a certain user group. Thus, even if the display of the user input dialogs is switched off ( “query off…”, see above), a password-protected project can be opened via the command file. The entries for the user group and the password must be placed before the command “file open…”!

Example:

user level 0
user password aaa
file open "D:\codesys\projects\xxxx.pro"
query off ok
user level User group, the password for which is defined in the project and is given by the subsequent command “user password”.
user password Password for user group specified by the preceding command “user group”.

Visualization settings:

visual settings… Corresponds to the possible settings which can be done for a visualization in ‘Extras’ ‘Settings’, category Language, or in the Target Settings, category Visualization
…   language file on || off Option ‘Language file gets activated (on) or deactivated (off). In case of activation the option ‘Dynamic texts’ will be deactivated.
…   set languagefile <path language file>

Specification of the language file to be used (.tlt or .vis).

Example: “visual settings set languagefile proj1.tlt”

…   dynamictexts on || off Option ‘Dynamic texts’  will be deactivated (on) or deactivated (off). In case of activation the option Language file will be deactivated.
…   dynamictextfiles <file path> | <file path> | …

Specification of a list of language file paths to be used. The previous list will be deleted.

Example: “visual settings D:\dynfiles\p1.xml D:\dynfiles\p2.xml”

…   dynamictexthideelements on || off Activation or deactivation of option ‘Suppress elements if no text replacement has taken place’.
…   language <language> Specification of the language to be used; Example: “visual settings language German”
…   tablekeyboardusage_web on || off Activation or deactivation of option ‘Keyboard usage for tables’ in the web visualization (Target Settings).
…   tablekeyboardusage_codesys on || off Activation or deactivation of option ‘Keyboard usage for tables’.
visual webvisuactivation on || off Activation or deactivation of option web visualization.

Commands concerning managing the project in the ENI project database:

In the following in the description of the commands placeholders are used:

<category>: Replace by “project” or “shared” or “compile” depending on which of the following database categories is concerned: Project Objects, Shared Objects, Compile Files

<POUname>: Name of the object, corresponds to the object name which is used.

<Objecttype>: Replace by the shortcut, which is appended as an extension to the POU name of the object in the database, and which reflects the object type (defined by the list of object types, see ENI Administration, ‘Object Types’). Example: Object “GLOBAL_1.GVL” -> the POU name is “GLOBAL_1”, the object type is “GVL” (global variables list).

<comment>: Replace by a comment text (embraced by single quotation marks) which will be stored in the version history with the particular action.

eni on

eni off

The option ‘Use source control (ENI)’ will be activated or deactivated

(Dialog ‘Project’ ‘Options’ ‘Project source control’)

eni project readonly on

eni project readonly off

The option ‘Read only’ for the database category ‘Project objects’ will be activated or deactivated.

(Dialog ‘Project’ ‘Options’ ‘Project objects’)

eni shared readonly on

eni shared readonly off

The option ‘Read only’ for the database category ‘Shared objects’ will be activated or deactivated.

(Dialog ‘Project’ ‘Options’ ‘Shared objects’)

eni set local <POUname>

The object will be assigned to category ‘Local’, i.e. it will not be stored in the project database.

(Dialog ‘Project’ ‘Object’ ‘Properties’ ‘Data base-connection’)

eni set shared <POUname>

The object will be assigned to category ‘Shared objects’.

(Dialog ‘Project’ ‘Object’ ‘Properties’ ‘Data base-connection’)

eni set project <POUname>

The object will be assigned to category ‘Project objects’.

(Dialog ‘Project’ ‘Object’ ‘Properties’ ‘Data base-connection’)

eni <category> server <TCP/IP_Address> <Port> <Projectname> <Username> <Password>

Configures the connection to the ENI Server for the category ‘Project objects’.

(Dialog ‘Project’ ‘Options’ ‘Project data base’);

Example: eni project server localhost 80 batchtest\\project EniBatch Batch

(TCP/IP-Address = localhost, Port = 80, Project name = batchtest\project, User name = EniBatch, Password = Batch)

eni compile sym on

eni compile sym off

The option ‘Create ASCII symbol information (.sym)’ for the objects of category ‘Compile files’ will be activated/deactivated.

(Dialog ‘Project’ ‘Options’ ‘Project source control’ ‘ENI settings’ for ‘Compile files’)

eni compile sdb on

eni compile sdb off

The option ‘Create binary symbol information (.sym)’ for the objects of category ‘Compile files’ will be activated/deactivated.

(Dialog ‘Project’ ‘Options’ ‘Project source control’ ‘ENI settings’ for ‘Compile files’)

eni compile prg on

eni compile prg off

The option ‘Create boot project’ for the objects of category ‘Compile files’ will be activated/deactivated.

(Dialog ‘Project’ ‘Options’ ‘Project source control’ ‘ENI settings’ for ‘Compile files’)

Commands of the menu ‘Project’ ‘Data Base Link’ for working with the database:

eni set <category> The object gets assigned to the named database category (‘Define’)
‘eni set <category>set <Objecttype>:<POUname> <Objecttype>:<POUname>

The objects which are listed separated by spaces will be assigned to the named database category. (‘Multiple Define’)

Example: “eni set project pou:as_fub pou:st_prg

-> the objects (pou) as_fub and st_prg get assigned to category ‘Project objects’

eni <category> getall The latest version of all objects of the named category will be called from the database (‘Get All Latest Versions’)
‘eni <category>get <Objecttype>:<POUname> <Objecttype>:<POUname>

The objects of the named category, which are listed separated by spaces will be called from the database. (‘Multiple Define’). (‘Get latest version’)

Example: “eni project get pou:as_fub gvl:global_1

-> the POU as_fub.pou and the global variables list global_1.gvl will be called from the database

eni <category> checkoutall “<comment>” All objects of the named category will be checked out from the database. The defined comment will be stored with the check-out-action in the version history.
eni <category> checkout “<comment>” <Objecttype>:<POUname> <Objecttype>:<POUname>

All objects (Objecttype:POUname) which are listed separated by spaces will be checked out from the database. The defined comment will be stored with the check-out-action in the version history for each particular object.

Example: “eni project checkout "for working on     xy" pou:as_fub gvl:global_1

-> The POU as_fub and the global variables list global_1 will be checked out and the comment “for working on xy” will be stored with this action

eni <category>checkinall “<comment>” All objects of the project, which are under source control in the project database, will be checked in. The defined comment will be stored with the check-in-action.
eni <category> checkin “<comment>” <Objecttype>:<POUname> <Objecttype>:<POUname>

All objects (Objecttype:POUname) which are listed separated by spaces will be checked in to the database. The defined comment will be stored with the check-in-action in the version history for each particular object. (see above: check out)

The defined comment will be stored with the check-in-action in the version history for each particular object.

Keywords for the command parameters:

The following keywords, enclosed in “$”, can be used in command parameters:

$PROJECT_NAME$ Name of the current IEC 61131-3 editor project (file name without extension “.pro”, e.g. “project_2.pro”)
$PROJECT_PATH$ Path of the directory, where the current IEC 61131-3 editor project file is (without indication of the drive and without a backslash at the end, e.g. “projects\sub1”).
$PROJECT_DRIVE$ Drive, where the current IEC 61131-3 editor project is (without backslash at the end, e.g. “D:”)
$COMPILE_DIR$ Compile directory of the current IEC 61131-3 editor project (with indiciation of the drive and without backslash at the end, e.g. “D:\codesys\compile”)
$EXE_DIR$ Directory where the codesys.exe file is (with indication of the drive and without backslash at the end, e.g. D:\codesys)

Example of a command file:

A command file like shown below will open the project file ampel.pro, will then load a watch list, which was stored as w.wtc, will then start the application program and write after 1 second delay - the values of the variables into the watch list watch.wtc (which will be saved) and will finally close the project.

file open C:\projects\CoDeSys_test\ampel.pro
  query off ok
  watchlist load c:\work\w.wtc
  online login
  online run
  delay 1000
  watchlist read
  watchlist save $PROJECT_DRIVE$\$PROJECT_PATH$\w_update.wtc
  online logout
  file close

This command file will open the project ampel.pro, will load an existing watchlist w.wtc, will start the application program, after 1 second will write the variables values to the watch list w_update.wtc, which will be saved in the directory “C:\projects\CoDeSys_test” and then will close the project again.

A command file is called in a command line as shown here:

"<path of codesys.exe>" /cmd     "<path of cmd file>"