You are on page 1of 56

593GB

PROFINET Edition (Siemens SIMATIC S7-1200)

Documentation for the installation and configuration methods


of the controller, software, and CAD data can be downloaded
from the following URL.
www.keyence.com/xgx_support

Copyright© KEYENCE CORPORATION. All rights reserved.


PROFINET Edition SIMATIC S7-1200  Table of Contents

Table of Contents

1. Connecting over PROFINET 003


1.1 Connecting Devices 003

1.2 Checking the Connection 017

2. Controlling the Image Capture Timing 019

2.1 Checking the Timing Diagram 019

3. Outputting Measured Values and Judgment Values 021

3.1 Configuring Output Data Settings 019

3.2 Checking the Output Data 024

3.3 Checking the Data Output Flow Chart and Timing Diagrams 028

4. Controlling the Controller with Commands 032

4.1 Checking Custom Commands 032

4.2 Checking the Command Processing Flow Chart and 034


Timing Diagram

4.3 Command Execution Procedure Examples 037

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

1. Connecting over PROFINET


This document has been created on the assumption that it will be used
to check connections with the basic configuration.
Until a connection is successfully established, configure the settings
according to this document. Thereafter, change the settings as necessary.

This chapter explains how to establish a connection between the XG-X2000 and the PLC over
PROFINET.

1.1 Connecting Devices


1.1.1 Wiring

Use one of the following methods to connect the devices. Use a CAT5e or higher Ethernet cable.

Connecting in a 1 to 1 Configuration

XG-X2000 PLC
Ethernet cable

Connecting through a Hub


To give priority to the checking of the PROFINET connection, disconnect all devices other than
the XG-X2000 and the PLC from the hub before establishing the connection. To connect other devices,
first configure the settings as described in this document, successfully establish the connection,
set the IP address to an appropriate value, and then connect the other devices.

XG-X2000 HUB PLC


Ethernet cable Ethernet cable

Ethernet cable

Other
devices

Disconnect all devices other than the XG-X2000


and the PLC. If you have to connect other
devices, exercise caution to prevent
the duplication of IP addresses.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

1.1.2 Configuring XG-X2000 Settings

Configure the XG-X2000 to enable a connection over PROFINET using Ethernet.

(1) At the top of the setup mode screen, click "Global," point to "Communications & I/O," and then
click "PROFINET."

(2) Select "Enable PROFINET" for "Enable/Disable."

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(3) Click "Create GSDML File" to output the GSDML file to SD2 on the XG-X.
This file is used to configure the PLC settings, so save it on the PC.
(In advance, you have to insert the CA-SD1G or another SD card supported by the XG-X into
SD2 on the XG-X.)

(4) Click "OK" to display a confirmation dialog box for restarting the XG-X2000. Click "Restart now"
to restart the XG-X2000.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

1.1.3 Configuring PLC Settings

To establish a connection over PROFINET, use TIA (Totally Integrated Automation) PORTAL to set
the PLC. This manual was created with TIA version 13.

(1) Connect the PC and the PLC, start TIA PORTAL, click "Start," "Create new project," and then
click "Create."
(Set items such as "Project name" to appropriate values.)

(2) Click "Devices & networks."

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(3) Click "Add new device," select the model of the PLC to use, and then click "Add."

For the model of the PLC to use, you have to select a PLC that is listed in the XG-X
Communication Configuration Manual.

(4) Click "Manage general station description files (GSD)" on the "Options" menu.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(5) For "Source path," specify the location on the PC where you saved the GSDML file in step (3)
under "1.1.2 Configuring XG-X2000 Settings." Select the check box for the displayed XG-X2000
GSDML file, and then click "Install."

(6) When the installation is complete, click "Close."

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(7) In the "Project tree" window, click "Device configuration" under the PLC, and then click
the "Network view" tab.

(8) Add the "XG-X2XXX" to the network by dragging it from the "Hardware catalog."

Drag the item here.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(9) Open the "Device view" tab.

(10) Switch the displayed device to the PLC.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(11) Click the PLC image, click the "Properties" tab, click "Ethernet addresses," click "Add new
subnet," and then add "PN/IE."
Enter the IP address on the PLC side for "IP address" and "Subnet mask."

Here, enter the values shown below for "IP address" and "Subnet mask."

IP address: 192.168.0.20
Subnet mask: 255.255.255.0

Click this.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(12) Switch the displayed device to the XG-X2000.

(13) Click the XG-X2000 image, click the "Properties" tab, click "Ethernet addresses," and then
select "PN/IE" for "Subnet."
Set "IP address" to the IP address of the XG-X2000.
(The IP address of the XG-X2000 will be changed to the address that you set here.)

IP address :192.168.0.10

Click this.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(14) When you click the "Network view" tab, the network of the XG-X2000 will be "Not assigned,"
so click "Not assigned" and select the PLC to communicate with (here, this is PLC_1).

(15) Right-click the PLC, point to "Compile," and then click "Hardware and software (only changes)."

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(16) Right-click the PLC, point to "Download to device," and then click "Hardware and software
(only changes)."

(17) Select "PN/IE" for "Type of the PG/PC interface," the network adapter of the PC connected to
the PLC for "PG/PC interface," and the interface or subnet to which the PLC is connected
(here, select PN/IE_1) for "Connection to interface/subnet."

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(18) Select the "Show all compatible devices" check box and click "Start search" to display a list of
the PLCs connected to the subnet that you selected in step (15). Select the PLC to use this
time, and then click "Load."

(19) Check that no errors have occurred in the "Load preview" window, and then click "Load."

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(20) Check that no errors have occurred in the "Load results" window, select the "Start all" check
box, and then click "Finish."

(21) Switch the device displayed on the "Device view" tab to the XG-X2000, and then check
the "Device overview." You can check a list of the PLC addresses to which the various pieces
of XG-X2000 data have been assigned.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

1.2 Checking the Connection


1.2.1 Using the PROFINET Memory Monitor to Check
the Connection
Use the PROFINET memory monitor of the XG-X2000 to check whether it is connected to the PLC.

(1) Click "Utilities" at the top of the setup mode screen.

(2) Click "PROFINET" to open the PROFINET memory monitor.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200  1. Connecting over PROFINET

(3) If the "Communication Status" is "Connected," the connection is complete.

(4) If the "Communication Status" is "Dis- connected," the connection failed.


Check the details in "1.1 Connecting Devices" again.
When checking these details, use the exact values from the setting examples in this document
for items such as the device's connection configuration and IP address.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 2. Controlling the Image Capture Timing

2. Controlling the Image Capture Timing

This chapter explains how to output data such as inspection results and measured values from
the XG-X2000 to the PLC over PROFINET. Before configuring the settings shown below, connect
the XG-X2000 to a PLC according to the procedure in "1. Connecting over PROFINET."
Also, if operations are performed at high speed and images must be captured in real time
(that is, a very short time between the application of the trigger and the capturing of the image is
required), use I/O (the terminal block), not PROFINET, to apply the triggers.

2.1 Checking the Timing Diagram


Check the timing diagram when you are controlling the image capture timing with PROFINET.

2.1.1 Checking the Address Assignments

When controlling the image capture timing, use the data of the bit area shown below.
When seen from the XG-X2000, this data is assigned to the XG-X2000 byte addresses shown below.
When seen from the PLC, this data is assigned to the PLC addresses shown below.

The assignments shown below are examples. Use step (19) under "1.1.3 Configuring
PLC Settings" to check the PLC addresses to which the data has actually been assigned.

For the ON/OFF timing of each piece of bit data, see "2.1.2 Checking the Timing Diagram."

Bit Area Data Assignments

Bit data type XG-X2000 byte address PLC address

Trg1 Output data: Bit area: Address 1: Bit 0 Q2.0


Trg2 Output data: Bit area: Address 1: Bit 1 Q2.1
Trg3 Output data: Bit area: Address 1: Bit 2 Q2.2
Trg4 Output data: Bit area: Address 1: Bit 3 Q2.3
Trg1 Ack Input data: Bit area: Address 2: Bit 0 I3.0
Trg2 Ack Input data: Bit area: Address 2: Bit 1 I3.1
Trg3 Ack Input data: Bit area: Address 2: Bit 2 I3.2
Trg4 Ack Input data: Bit area: Address 2: Bit 3 I3.3
Trg1 Ready Input data: Bit area: Address 1: Bit 0 I2.0
Trg2 Ready Input data: Bit area: Address 1: Bit 1 I2.1
Trg3 Ready Input data: Bit area: Address 1: Bit 2 I2.2
Trg4 Ready Input data: Bit area: Address 1: Bit 3 I2.3

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 2. Controlling the Image Capture Timing

2.1.2 Checking the Timing Diagram

The timing diagram when you are controlling the image capture timing with PROFINET (when you are
applying triggers) is shown below. Use data combinations that correspond to the triggers you want to
use for Trg[n] Ready, Trg[n], and Trg[n] Ack. (For example, if you are using trigger 1, use
Trg1 Ready, Trg1, and Trg1 Ack.)
For the assignments of the addresses of the data, see "2.1.1 Checking the Address Assignments."

Trg[n] Ready (2) (3)

Trg[n] (1) (4)

Trg[n] Ack (2) (5)

(1) After checking that Trg[n] Ready is ON and Trg[n] Ack is OFF, the PLC turns Trg[n] ON.
(2) After receiving the trigger input, the controller starts capturing the image and turns Trg[n] Ready OFF
and Trg[n] Ack ON.
(3) When the image capture is finished and the controller is able to start the next image capture,
the controller turns Trg[n] Ready ON.
(4) After checking that Trg[n] Ack is ON (the controller has read that Trg[n] is ON), the PLC turns Trg[n]
OFF.
(5) Linked with (4), the controller turns Trg[n] Ack OFF.

To make the PLC check that the controller has received the applied trigger, check
that Trg[n] Ack is ON, not that Trg[n] Ready is OFF.
(If you attempt to check this with Trg[n] Ready being OFF, it may not be possible
to detect Trg[n] Ready being OFF from the PLC side if the time that Trg[n] Ready is
OFF is shorter than the PROFINET communication cycle.)

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

3. Outputting Measured Values and Judgment Values


This chapter explains how to output data such as inspection results and measured values from
the XG-X2000 to the PLC over PROFINET. Before configuring the settings shown below, connect
the XG-X2000 to a PLC according to the procedure in "1. Connecting over PROFINET."

3.1 Configuring Output Data Settings

3.1.1 Configuring XG-X2000 Settings

As an example, this section explains how to configure the settings in order to output the data
shown below.

PROFINET does not support the outputting of images or setup data.

00. Total judgment (%JgAll)


01. Pattern search (position X)
02. Pattern search (position XY)
03. Area
04. OCR (character string on line 1)
05. Pattern search (unit judgment value)
06. Area (unit judgment value)
07. Variable (#a)
08. Variable (#b)
09. Measurement time (%PrcTime)
10. Measurement count (%PrcCount)

(1) Add "Data Output" to the end of the flow.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

(2) Select the added "Data Output" to open the setup screen.

(3) Set the output destination to "PROFINET."

(4) Click "Add" to add output data.

(5) Select the data that you want to output.


Here, you will output the total judgment of the inspection (%JgAll), so first select
"System Variable."

Select the following output items for each output.

No. Output data: Output item


00. Total judgment (%JgAll): System variable
01. Pattern search (position X): Result data
02. Pattern search (position XY): Result data
03. Area: Result data
04. OCR (character string on line 1): Result data
05. Pattern search (unit judgment value): Result data
06. Area (unit judgment value): Result data
07. Variable (#a): Local variable
08. Variable (#b): Local variable
09. Measurement time (%PrcTime): System variable
10. Measurement count (%PrcCount): System variable

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

(6) Select the data that you want to output from the displayed list.

(7) Repeat steps (4) to (6) to add all the data that you want to output.

00. Total judgment (%JgAll)


01. Pattern search (position X)
02. Pattern search (position XY)
03. Area
04. OCR (character string on line 1)
05. Pattern search (unit judgment value)
06. Area (unit judgment value)
07. Variable (#a)
08. Variable (#b)
09. Measurement time (%PrcTime)
10. Measurement count (%PrcCount)

(8) When there are multiple instances of Data Output and there are duplicate output destination
addresses between these units, click "Settings" to set the output offset. (Prevent duplication
between the output destination of other Data Output instances and the byte address.)

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

3.2 Checking the Output Data

3.2.1 Checking the Output Data

This section explains how to check the output data on the XG-X2000.
To output data, first switch the XG-X2000 to run mode.
(Data is not output in setup mode.)

Switching the XG-X2000 to Run Mode

(1) Click "Go to Run Mode" at the top of the setup mode screen to switch to run mode.

(2) When a screen like the one shown below is displayed, the switch to run mode is complete.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

Using the XG-X2000 to Check the PLC Data Memory

Use the PROFINET memory monitor of the XG-X2000 to check the data output from the XG-X2000.

(1) Click "Utilities" on the "Function" menu.

(2) Click "PROFINET" to open the PROFINET memory monitor.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

(3) Check that "Communication Status" is "Connected," and then select the value for
"Multi BIT Outputs" under "XG-X Implicit Output Addressing (XG-X -> PLC)."

(4) The details of the output to the PLC data memory are displayed as a list.
(In the initial values, the data is output with 120 as the leading address.)

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

3.2.2 Checking the Format of the Output Data

This section explains the format of the data output from the XG-X2000 to the PLC.

As an example, this section explains the output formats when the measured values and judgment
values are as shown below with the XG-X2000 set as shown in "3.1 Configuring Output Data Settings."

00. Total judgment (%JgAll): NG = 1


01. Pattern search (position X): 744.050
02. Pattern search (position XY): X = 744.050 / Y = 578.199
03. Area: 249174
04. OCR (character string on line 1, character count: 10): KEYENCE
05. Pattern search (unit judgment value): OK = 0
06. Area (unit judgment value): NG = 1
07. Variable (#a): 96
08. Variable (#b): 123.456
09. Measurement time (%PrcTime): 116.718 ms
10. Measurement count (%PrcCount): 32

XG-X2000 input
Output data (decimal) Output format
data address
120 1 The judgment value (OK = 0/NG = 1) is stored using 2 words.
Decimal fraction data is multiplied by 1000 and stored in 2 words.
124 744050 (744.050 → 744050)
128 744050 When XY data is output, it is stored in the order of X followed by Y,
132 578199 with each piece stored in 2 words.
136 249174 Integer data is stored as-is in 2 words.
140 75
144 69
148 89 Character data is stored as ASCII code with 2 words used per character.
152 69 The number of characters output is determined by the value set for the
156 78 "number of characters on line 1" for the OCR unit.
160 67 Here this is set to "10," so even though the read character string only
consists of 7 characters, 20 words are used from 140 to 179 in order to
164 69
store 10 characters.
168 0
172 0
176 0
180 0
The judgment value (OK = 0/NG = 1) is stored using 2 words.
184 1
188 96000 All local variables are multiplied by 1000 and stored in 2 words.
192 123456 (96 → 96000, 123.456 → 123456)
196 116718 Integer data system variables are stored as-is in 2 words.
Decimal fraction data system variables are multiplied by 1000 and stored
200 32 in 2 words.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

3.3 Checking the Data Output Flow Chart and Timing


Diagrams
Use this section to check the command processing flow chart and timing diagrams when measured
values/judgment values are being output over PROFINET.

3.3.1 Checking the Address Assignments

The bit areas and the word areas shown below are used when outputting measured values and
judgment values. When seen from the XG-X2000, this data is assigned to the XG-X2000 byte
addresses shown below. When seen from the PLC, this data is assigned to the PLC addresses shown
below.

The assignments shown below are examples. Use step (19) under "1.1.3 Configuring PLC
Settings" to check the PLC addresses to which the data has actually been assigned.

For the ON/OFF timing of each piece of bit data and the output timing of each piece of
word data, see "3.3.2 Checking the Data Output Flow Chart" and
"3.3.3 Checking the Timing Diagrams."

Bit Area Data Assignments

Bit data type XG-X2000 byte address PLC address

Result ack flag Output data: Bit area: Address 0: Bit 3 Q1.3
Result ready flag Input data: Bit area: Address 0: Bit 3 I1.03
Result OR flag Input data: Bit area: Address 0: Bit 4 I1.04

Word Area Data Assignments

Word data type XG-X2000 byte address PLC address

Result Data1 Input data: Word area: Address 120 PID532


Result Data2 Input data: Word area: Address 124 PID536
Result Data3 Input data: Word area: Address 128 PID540
……… ……… ………

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

3.3.2 Checking the Timing Diagrams


The flow chart for when the result output unit outputs data over PROFINET is shown below.
For the assignments of the addresses of the data, see "3.3.1 Checking the Address Assignments."

Controller PLC

Execution of inspection flow chart

Result output
unit

Check that the Result ack flag is


OFF.(★1)

The data is written to the memory entry


Write the output data to Result Data.
corresponding to Result Data.

Confirm that the writing of the data is complete


When the writing is complete, turn the
with the Result ready flag turning ON,
Result ready flag ON.
and then read Result Data.

Detect that the Result ack flag has turned


ON, and then check that the reading of Turn the Result ack flag ON.
the data is complete.(★1)

Detect that the Result ready flag has turned


Turn the Result ready flag OFF.
OFF.

Turn the Result ack flag OFF.


To the next flow chart

★1 The flow chart shown above is from the case in which handshake is ON.
To turn handshake ON/OFF, select a value in the "Handshake" list in step (8) under
"3.1.1 Configuring XG-X2000 Settings."

When handshake is OFF, the controller overwrites data memory with the execution timing of the result output unit
regardless of the status of the Result ack flag.The Result ready flag also remains ON thereafter.
When it is necessary to check the completion of writing due to the Result ready flag changing from OFF to ON,
turn the Result ready flag OFF by turning the Result ack flag ON.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

3.3.3 Checking the Timing Diagrams

The timing diagrams for when the result output unit outputs data over PROFINET are shown below.
For the assignments of the addresses of the data, see "3.3.1 Checking the Address Assignments."

When Handshake Is ON

Result ack flag (3) (5)

Result ready flag (2) (4) (7)

Result OR flag Total judgment


Uncertain (1) (6) Total judgment result
(★2) result

Result Data nnn Uncertain (1) Output data (6) Output data

★2 When you are using the Result OR flag, it is necessary for at least 1 piece of data to be set to be output from
the result output unit to PROFINET.

(1) The controller updates the output data.


(2) After updating the output data, the controller turns the Result ready flag ON.
(3) After reading the output data, the PLC turns the Result ack flag ON.
(4) Linked with (3), the controller turns the Result ready flag OFF.
(5) The PLC turns the Result ack flag OFF.
(6) Receiving the signal from (5), the controller updates the output data if the next batch of output data is
present.
(7) In the same manner as (2), after updating the output data, the controller turns the Result ready flag ON.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 3. Outputting Measured Values and Judgment Values

When Handshake Is OFF

Result ack flag (5)

Result ready flag (2) (4) (5)

Result OR flag Total judgment


Uncertain (1) (3) Total judgment result
(★2) result

Result Data nnn Uncertain (1) Output data (3) Output data

★2 When you are using the Result OR flag, it is necessary for at least 1 piece of data to be set to be output from
the result output unit to PROFINET.

(1) The controller updates the output data.


(2) After updating the output data, the controller turns the Result ready flag ON.
(3) The controller updates the output data. (The data is updated regardless of the Result ack flag and
the Result ready flag.)
(4) After updating the output data, the controller updates the Result ready flag to ON.
(5) When the PLC turns the Result ack flag ON, the controller turns the Result ready flag OFF.
In this way, the Result ready flag turns ON the next time the data is updated, which makes it possible
to check that the data has been updated.
(If it is not necessary to check the updating of the data, step [5] is unnecessary.)

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4. Controlling the Controller with Commands


This chapter explains how to use commands to control the XG-X2000 from a PLC over PROFINET
(such as switching the program and overwriting the variables).
Before configuring the settings shown below, connect the XG-X2000 to a PLC according to
the procedure in "1. Connecting over PROFINET."

4.1 Checking Custom Commands


4.1.1 Checking Custom Command Numbers and Execution
Details
To control the XG-X2000 over PROFINET using commands, use the "custom commands" that have
been registered as the "execution details" of the specified command.
You can use the procedure shown below to check the details of custom commands.

(1) At the top of the setup mode screen, click "Global," and then click "Custom Instruction Settings."

(2) A list of the usable custom commands is displayed. Check the "command number" and
the "execution details."

(3) In the initial values, the custom commands shown below are registered.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.1.2 Checking How to Use Custom Commands


As you have checked in "4.1.1 Checking Custom Command Numbers and Execution Details,"
a variety of commands are registered to the custom commands in the initial values.
You will use this section to check how to use custom commands. The PW command, which is
registered to command number 2, will be used as an example.

Checking the Command Format


The format of the PW command (program switching), which is being used as an example in
this section, is shown below.

PW, "SD card number," "program number"

For example, when the command "PW, 1, 25" is executed, the program is switched to number "25,"
which is stored on SD card "1." To check the formats of the various commands, see chapter 2,
"Command Explanation" in the "XG-X2000 Series Communication Configuration Manual."

Registering Custom Commands


To use a custom command, you first have to register its "command number" and its
"execution details." For the PW command, the following "command number" and
"execution details" are registered in the initial values.

Command number Execution details


"*01" in the execution details is
substituted with the value
specified by the command parameters.

Therefore, in order to use custom command "PW, 1, *01" (which is registered in


command number 2) to switch to program number "25," specify "2" for the "command number" and
"25" for the "command parameters," and then execute the custom command.

Using PROFINET to Specify Custom Commands

To execute a custom command over PROFINET, enter the "command number" into the address to
which"Command Number" has been assigned, enter the "command parameters" into the address
to which"Command Parameter" has been assigned, and then execute the custom command.

For the detailed procedure, see "4.2 Checking the Command Processing Flow Chart and
Timing Diagram."

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.2 Checking the Command Processing Flow Chart and


Timing Diagram
Use this section to check the command processing flow chart and timing diagram when using custom
commands with PROFINET.

4.2.1 Checking the Address Assignments


The bit areas and the word areas shown below are used to execute custom commands over PROFINET.
When seen from the XG-X2000, this data is assigned to the XG-X2000 byte addresses shown below.
When seen from the PLC, this data is assigned to the PLC addresses shown below.

The assignments shown below are examples. Use step (19) under "1.1.3 Configuring PLC
Settings" to check the PLC addresses to which the data has actually been assigned.

For the ON/OFF timing of each piece of bit data and the output timing of each piece of byte
data, see "4.3.2 Checking the Command Process Flow Chart" and
"4.3.3 Checking the Timing Diagram."

Bit Area Data Assignments

Bit data type XG-X2000 byte address PLC address

Command request flag Output data: Bit area: Address 0: Bit 0 Q1.0
Command complete flag Input data: Bit area: Address 0: Bit 0 I1.0
Command error flag Input data: Bit area: Address 0: Bit 1 I1.1
Command ready flag Input data: Bit area: Address 0: Bit 2 I1.2

Word Area Data Assignments

Word data type XG-X2000 byte address PLC address

Command Number Output data: Word area: Address 016 PQD528


Command Parameter1 Output data: Word area: Address 020 PQD532
Command Parameter2 Output data: Word area: Address 024 PQD536
……… ……… ………
Command Result Input data: Word area: Address 020 PID532
Command Data1 Input data: Word area: Address 024 PID536
Command Data2 Input data: Word area: Address 028 PID540
……… ……… ………

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.2.2 Checking the Command Process Flow Chart

The flow chart for executing custom commands over PROFINET is shown below.
For the assignments of the addresses of the data, see "4.2.1 Checking the Address Assignments."

Controller PLC

Enter the custom command number into Command


Numberand the command parameters into Command
Parameter.

Check that the Command ready flag is ON.

Detects that the Command request flag has changed to


ON,and then reads the command number from Command
Turn the Command request flag ON.
Number and the command parameters from Command
Parameter.

Start executing the command.

Turn the Command ready flag OFF.

After the command execution is finished, write the reply


data into Command Data, the command execution result The reply data is written into Command Data and
into Command Result,and the error status into the error status into the Command error flag.
the Command error flag.(★1)

Detect that the Command complete flag has turned ON,


Turn the Command complete flag ON.
and then check the reply data and the error status.

Check that the Command request flag is OFF,


and then turn the Command complete flag and
Turn the Command request flag OFF.
the Command error flag OFF
and the Command ready flag ON.

★1 For commands that have no reply data, the reply data is not output to Command Data.
The value written to Command Result is a 0 when the command processing is successful and is the error
code when the command processing fails.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.2.3 Checking the Timing Diagram

The timing diagram for executing custom commands over PROFINET is shown below.
For the assignments of the addresses of the data, see "4.2.1 Checking the Address Assignments."

Command
(2) (7)
request flag

Command
(3) (7)
ready flag

Command
(5) (7)
complete flag

Command
(4) Error status (7)
error flag

Command
(1) Arbitrary value
Number

Command
(1) Arbitrary value
Parameter nnn

Command
Uncertain (4) Reply data (6) Uncertain
Data nnn

(1) The PLC stores the command number in Command Number and the command parameters in
Command Parameter.
(2) The PLC turns the Command request flag ON and executes the command.
(3) The controller turns the Command ready flag OFF.
(For this to turn OFF, at minimum, the link scan time is required after [2].)
(4) When the command is executed, the controller stores the reply data in Command Data and the error
status in the Command error flag.
(The Command error flag being ON indicates that the command processing failed. The Command error
flag being OFF indicates that the command processing was successful.)
(5) The controller turns the Command complete flag ON as the confirmation signal of command execution
completion.
(6) If there is reply data, the PLC reads the value of Command Data prior to step (7).
(7) To enable the next command execution, the PLC turns the Command request flag OFF,
and the controller turns the Command ready flag ON and the Command complete flag and
the Command error flag OFF in response.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.3 Command Execution Procedure Examples


This section explains the detailed procedure to follow in order to actually execute commands.
With some commands, an error occurs in setup mode, so follow the procedure shown below to
switch to run mode.

(1) Click "Go to Run Mode" at the top of the setup mode screen to switch to run mode.

There are commands that cannot be executed in setup mode.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.3.1 Checking Typical Command Applications

This manual explains detailed usage procedures for typical commands.


A list of the applications for these commands is shown below.

Command
Application Procedure reference
to use

Saving settings SS command "4.3.2 SS Command"

Switching the program number PW command "4.3.3 PW Command"

Obtaining the current program


PR command "4.3.4 PR Command"
number

Changing the OCR/1D code reader/


2D code reader judgment character CW command "4.3.5 CW Command"
string

Changing the name of the file output


for result output/image output/ OW command "4.3.6 OW Command"

history output

Overwriting a variable value MW command "4.3.7 MW Command"

Overwriting an array variable value MWX command "4.3.8 MWX Command"

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.3.2 SS Command (Saving Settings)


This section explains how to use the "SS command" as an example of the commands that do not use
command parameters.
The SS command saves the current program and system settings.
The SS command is registered asthe initial value of command number 0 ("SS") of the custom
commands.

Command Execution Procedure Example


(Saving the Current Program and System Settings)

(1) Enter "0," which is the command number of Address Value


the SS command, into the address (PQD528) to I1.0 0
I1.1 0
which Command Number has been assigned.
Q1.0 0
PID532 0
PQD528 0
PQD532 0

(2) Turn ON the address (Q1.0) to which the Address Value


Command request flag has been assigned. I1.0 0
I1.1 0
Q1.0 1
PID532 0
PQD528 0
(3) The SS command is executed. PQD532 0

(4) Check that the address (I1.0) to which the Address Value
Command complete flag has been assigned I1.0 1
I1.1 0
turns ON.
Q1.0 1
PID532 0

When the command is successful,


this remains "OFF."
(5) Check whether the address (I1.1) to which the
Command error flag has been assigned is Address Value
I1.0 1
ON or OFF.
I1.1 0
If it is OFF, the command has been processed normally. Q1.0 1
If it is ON, the command processing failed, so check the PID532 0
error code written to the address (PID532) to which
Command Result has been assigned. When the command fails, this
turns "ON," so check the error code.

Address Value
I1.0 1
I1.1 1
Q1.0 1
PID532 3

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.3.3 PW Command (Program Switching)


This section explains how to use the "PW command" as an example of the commands that use
command parameters. The PW command closes all the open dialog boxes and switches to
the specified program number. The PW command is registered as the initial value of command
number 31 ("PW, *01, *02") of the custom commands.

Command Execution Procedure Example


(Switching to Program Number 5 on SD1)

(1) Enter "31," which is the command number of Address Value


the PW command, into the address (PQD528) I1.0 0
I1.1 0
to which Command Number has been
Q1.0 0
assigned.
PID532 0
PQD528 31

(2) Enter in units of 2 words the parameters into Address Value


the addresses (starting with PQD532) to which I1.0 0
I1.1 0
Command Parameter has been assigned.
Q1.0 0
PID532 0
PQD532: 1 (SD card number to switch to)
PQD528 31
PQD536: 5 (program number) PQD532 1
PQD536 5

(3) Turn ON the address (Q1.0) to which the Address Value


Command request flag has been assigned. I1.0 0
I1.1 0
Q1.0 1
PID532 0
(4) The PW command is executed.

(5) Check that the address (I1.0) to which the Address Value
Command complete flag has been assigned I1.0 1
I1.1 0
turns ON.
When the command is successful,
(6) Check whether the address (I1.1) to which the
this remains "OFF."
Command error flag has been assigned is ON
Address Value
or OFF.
I1.0 1
If it is OFF, the command has been processed normally.
I1.1 0
If it is ON, the command processing failed, so check
the error code written to the address (PID532) to When the command fails,
which Command Result has been assigned. this turns "ON," so check the error code.

Address Value
I1.0 1
I1.1 1
Q1.0 1
PID532 3

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.3.4 PR Command (Program Number Reading)

This section explains how to use the "PR command" as an example of the commands that use
command data output. The PR command reads the current program number.
The PR command is registered as the initial value of command number 32 ("PR") of the custom
commands.

Command Execution Procedure Example


(Reading the Current Program Number)

(1) Enter "32," which is the command number of Address Value


the PR command, into the address (PQD528) to I1.0 0
I1.1 0
which Command Number has been assigned.
Q1.0 0
PID532 0
PQD528 32

(2) Turn ON the address (Q1.0) to which Address Value


the Command request flag has been assigned. I1.0 0
I1.1 0
Q1.0 1
(3) The PR command is executed. PID532 0

(4) Check that the address (I1.0) to which the Address Value
Command complete flag has been assigned I1.0 1
turns ON. I1.1 0

(5) Check whether the address (I1.1) to which the When the command is successful,

Command error flag has been assigned is this remains "OFF."


Address Value
ON or OFF.
I1.0 1
If it is OFF, the command has been processed I1.1 0
normally.
If it is ON, the command processing failed, so When the command fails,
check the error code written to the address this turns "ON," so check the error code.
(PID532) to which Command Result has been
Address Value
assigned.
I1.0 1
I1.1 1
Q1.0 1
PID532 3

(6) After it can be confirmed that the command was Address Value
processed normally in step (5), the reply data is I1.0 1
output in units of 2 words into the addresses I1.1 1
Q1.0 1
(starting with PQD536) to which Command Data
PID532 3
has been assigned, so check these addresses.
PQD536 1
PQD540 5
PQD536: 1 (program SD card number)
PQD540: 5 (program number)

You can see that the current program is program number 5 on SD1.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.3.5 CW Command (Overwriting the OCR/Code Reader


Judgment Character String)
This section explains how to use the "CW command" as an example of the commands that use
character strings for the command parameters. The CW command overwrites the REG (judgment
character string) value of the OCR/1D code reader/2D code reader. The CW command is registered
as the initial value of command number 55 ("CW, *01, *02, *03") of the custom commands.

Command Execution Procedure Example (Setting the Line 1 Judgment


Character String of the OCR Unit with Unit ID 2 to "ABCDE")
Using the XG-X2000 to set the judgment condition to REG
(the judgment character string)
The settings shown below are required for the OCR/1D code reader/2D code reader that will be
targeted with the CW command.

(1) Open the editing screen of the result output unit.

Here, edit the OCR unit with


unit ID 2.

(2) Select the judgment condition on the editing screen of the OCR unit.

(3) Enter the character string of the first line.

(4) Click "REG," and then click "OK."

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

Executing the command from the PLC

(1) Enter "55," which is the command number of Address Value


the CW command, into the address (PQD528) to I1.0 0
I1.1 0
which Command Number has been assigned.
Q1.0 0
PID532 0
PQD528 55

(2) Enter in units of 2 words the unit ID, line number, Address Value
and character string into the addresses I1.0 0
I1.1 0
(starting with PQD532) to which Command
Q1.0 0
Parameter has been assigned. PID532 0
PQD532: 2 (unit ID) PQD528 55
PQD532 2
PQD536: 1 (line number)
PQD536 1
PQD540: 65 ("A" in ASCII code)
PQD540 65
PQD544: 66 ("B" in ASCII code) PQD544 66
PQD548: 67 ("C" in ASCII code) PQD548 67
PQD552: 68 ("D" in ASCII code) PQD552 68
PQD556: 69 ("E" in ASCII code) PQD556 69
PQD560 0
PQD560: 0 (Be sure to use "0" as
the terminator of the character string.)

(3) Turn ON the address (Q1.0) to which the Address Value


Command request flag has been assigned. I1.0 0
I1.1 0
(4) The CW command is executed. Q1.0 1
PID532 0

(5) Check that the address (I1.0) to which the Address Value
Command complete flag has been assigned I1.0 1
I1.1 0
turns ON.

(6) Check whether the address (I1.1) to which the When the command is successful,
Command error flag has been assigned is this remains "OFF."
ON or OFF.
Address Value
If it is OFF, the command has been processed I1.0 1
normally. I1.1 0
If it is ON, the command processing failed, so
check the error code written to the address When the command fails, this turns
(PID532) to which Command Result has been "ON," so check the error code.
assigned.
Address Value
I1.0 1
I1.1 1
Q1.0 1
PID532 3

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.3.6 OW Command (Overwriting the Specified Character


String of the File Naming Rule)

This section explains how to use the "OW command" as an example of the commands that use
character strings for the command parameters. The OW command overwrites the specified character
string of the file naming rule of the "result output unit/image output unit/history archive (*1)."
The OW command is registered as the initial value of command number 105 ("OW, *01, *02") of
the custom commands. (*1)

※1 To set the specified character string of the naming rule of the history archive file, you have to register
the new custom command "OW, HIST, *01, *02."

Command Execution Procedure Example (Setting the Name of


the Output File of the Result Output Unit with Unit ID 2 to "ABCDE")

Configuring result output unit settings with the XG-X2000


The settings shown below are required for the result output unit that will be targeted with
the OW command.
(1) Open the editing screen of the result output unit.

Here, edit the result output unit


with unit ID 2.

(2) On the editing screen of the result output unit, select the output destination,
and then click "Settings."

You have to select "SD Card,"


"PC Application," "FTP," or
"USB HDD" for the output
destination.

(3) Change "File naming" to "Fixed Name," and then click "OK" to complete the settings.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

Executing the command from the PLC

(1) Enter "105," which is the command number of Address Value


the OW command, into the address (PQD528) to I1.0 0
I1.1 0
which Command Number has been assigned.
Q1.0 0
PID532 0
PQD528 105

(2) Enter in units of 2 words the unit ID and Address Value


character string into the addresses (starting with I1.0 0
I1.1 0
PQD5320) to which Command Parameter
Q1.0 0
has been assigned. PID532 0
PQD528 105
PQD532: 2 (unit ID)
PQD532 2
PQD536: 65 ("A" in ASCII code)
PQD536 65
PQD540: 66 ("B" in ASCII code) PQD540 66
PQD544: 67 ("C" in ASCII code) PQD544 67
PQD548: 68 ("D" in ASCII code) PQD548 68
PQD552: 69 ("E" in ASCII code) PQD552 69
PQD556 0
PQD556: 0 (Be sure to use "0" as
the terminator of the character string.)

(3) Turn ON the address (Q1.0) to which the Address Value


Command request flag has been assigned. I1.0 0
I1.1 0
Q1.0 1
(4) The OW command is executed.
PID532 0

(5) Check that the address (I1.0) to which the Address Value
Command complete flag has been assigned I1.0 1
I1.1 0
turns ON.

(6) Check whether the address (I1.1) to which the When the command is successful,
Command error flag has been assigned is this remains "OFF."
ON or OFF.
Address Value
If it is OFF, the command has been processed I1.0 1
normally. I1.1 0
If it is ON, the command processing failed, so
check the error code written to the address When the command fails, this turns
(PID532) to which Command Result has been "ON," so check the error code.
assigned.
Address Value
I1.0 1
I1.1 1
Q1.0 1
PID532 3

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

Command Execution Procedure Example (Setting the Name of


the Output File of the Image Output Unit with Unit ID 3 to "abc123")

Configuring image output unit settings with the XG-X2000

The settings shown below are required for the image output unit that will be targeted with the OW
command.
(1) Open the editing screen of the result
output unit.
Here, edit the image output unit
with unit ID 3.

(2) On the editing screen of the result output unit, click "Settings."

(3) Change "File naming" to "Specified" or "Sequential," and then click "OK" to complete
the settings.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

Executing the command from the PLC

(1) Enter "105," which is the command number of Address Value


the OW command, into the address (PQD528) to I1.0 0
I1.1 0
which Command Number has been assigned.
Q1.0 0
PID532 0
PQD528 105

(2) Enter in units of 2 words the unit ID and Address Value


character string into the addresses (starting with I1.0 0
I1.1 0
PQD5320) to which Command Parameter has
Q1.0 0
been assigned. PID532 0
PQD528 105
PQD532: 2 (unit ID)
PQD532 3
PQD536: 65 ("A" in ASCII code)
PQD536 97
PQD540: 66 ("B" in ASCII code) PQD540 98
PQD544: 67 ("C" in ASCII code) PQD544 99
PQD548: 68 ("D" in ASCII code) PQD548 48
PQD552: 69 ("E" in ASCII code) PQD552 49
PQD556 50
PQD556: 0 (Be sure to use "0" as
PQD560 0
the terminator of the character string.)

(3) Turn ON the address (Q1.0) to which Address Value


the Command request flag has been assigned. I1.0 0
I1.1 0
Q1.0 1
(4) The OW command is executed. PID532 0

(5) Check that the address (I1.0) to which Address Value


the Command complete flag has been assigned I1.0 1
I1.1 0
turns ON.
When the command is successful,
(6) Check whether the address (I1.1) to which
this remains "OFF."
the Command error flag has been assigned is
Address Value
ON or OFF. If it is OFF, the command has been
I1.0 1
processed normally. If it is ON, the command
I1.1 0
processing failed, so check the error code
written to the address (PID532) to which When the command fails, this turns
Command Result has been assigned. "ON," so check the error code.

Address Value
I1.0 1
I1.1 1
Q1.0 1
PID532 3

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

Command Execution Procedure Example (Setting the Name of


the Output File of the History Image of Archive Condition 0 to
"ABCDE")
Configuring history output settings with the XG-X2000

The settings shown below are required for the history archive that will be targeted with the OW
command.

(1) Click "Utilities" at the top of the setup mode screen.

(2) Click the "Image Archive Settings" icon to open the Image Archive Settings screen.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

(3) Select the archive condition to output. Here, select archive condition 0.

(4) Check that the "Enable" check box is selected, set "Output location" to a value
other than "None," and then click "Settings."

You have to select "SD Card,"


"PC Application," "FTP," or
"USB HDD" for "Output Location."

(5) Change "File Naming Rule" to "Sequential" or "Specified," and then click "OK" to complete
the settings.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

Setting the custom command

In the default settings, the OW command for history archives is not registered to the custom
commands, so add the execution details to a command number for a command that is not being used.

(1) At the top of the setup mode screen, click "Global," and then click "Custom Instruction Settings."

(2) Select an unused command (here we select number 120); overwrite the execution details to
"OW, HIST, *01, *02;" and then click "OK."

The command format when changing the naming rule


of the history archive file is "OW, HIST, 'history archive
condition number,' 'character string.'"
Therefore, when using the custom command registered
here, specify the history archive condition number for
the first command parameter and the character string
for the second command parameter.

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

Executing the command from the PLC

(1) Enter "120," which is the command number of Address Value


the OW command, into the address (PQD528) to I1.0 0
I1.1 0
which Command Number has been assigned.
Q1.0 0
PID532 0
PQD528 120

(2) Enter in units of 2 words the history archive Address Value


condition number and character string into I1.0 0
I1.1 0
the addresses (starting with PQD532) to which
Q1.0 0
Command Parameter has been assigned.
PID532 0
PQD532: 0 (history archive condition number) PQD528 120
PQD536: 65 ("A" in ASCII code) PQD532 0
PQD536 65
PQD540: 66 ("B" in ASCII code)
PQD540 66
PQD544: 67 ("C" in ASCII code) PQD544 67
PQD548: 68 ("D" in ASCII code) PQD548 68
PQD552: 69 ("E" in ASCII code) PQD552 69
PQD556: 0 (Be sure to use "0" as PQD556 0
the terminator of the character string.)

(3) Turn ON the address (Q1.0) to which the Address Value


Command request flag has been assigned. I1.0 0
I1.1 0
Q1.0 1
(4) The OW command is executed. PID532 0

(5) Check that the address (I1.0) to which the Address Value
Command complete flag has been assigned I1.0 1
I1.1 0
turns ON.
When the command is successful,
(6) Check whether the address (I1.1) to which the
this remains "OFF."
Command error flag has been assigned is
Address Value
ON or OFF.
I1.0 1
If it is OFF, the command has been processed I1.1 0
normally. If it is ON, the command processing
failed, so check the error code written to When the command fails,
the address (PID532) to which this turns "ON," so check the error code.
Command Result has been assigned.
Address Value
I1.0 1
I1.1 1
Q1.0 1
PID532 3

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.3.7 MW Command (Writing Variables)


This section explains how to use the "MW command" as an example of the commands that must be
registered as new custom commands. The MW command overwrites the specified scalar variable
(global variable or local variable). In the initial values, the MW command is not registered in
the custom commands, so you have to add a custom command.

If you have to change multiple variables, such as the X coordinate


and the Y coordinate, at the same time, see "Command Execution
Procedure Example (Overwriting Multiple Variables at the Same
Time)" below or "4.3.8 MWX Command (Writing Array Variables)."
If you overwrite variables separately, inspections may be executed
with an illegal combination of variables in the event that inspections
are executed while the variables are being overwritten.

Command Execution Procedure Example


(Overwriting #variable as "123")

Setting the custom command

(1) At the top of the setup mode screen, click "Global," and then click "Custom Instruction Settings."

(2) Select an unused command (here we select number 120); overwrite the execution details to
"MW, (variable name), *01;" and then click "OK." Here we will add a command for changing
the value of the variable "#variable." (The variable "#variable" must be added to the setup
data in advance with the variable settings.)

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

Executing the command from the PLC

(1) Enter "120," which is the command number of Address Value


the set custom command, into the address I1.0 0
I1.1 0
(PQD528) to which Command Number
Q1.0 0
has been assigned. PID532 0
PQD528 120

(2) Enter in units of 2 words the parameters into Address Value


the addresses (starting with PQD532) to which I1.0 0
I1.1 0
Command Parameter has been assigned.
Q1.0 0
PQD532: 123000 (value to overwrite PID532 0
the setting with) PQD528 120
PQD532 123000
The MW command handles command parameters
as decimal fractions (with 3 decimal places), so enter
the value to overwrite the setting with as its
initial value multiplied by 1000.
(If you want to overwrite the setting as "123," enter
"123000.") If the value that you want to overwrite
the setting with is an integer, use the IW command
instead of the MW command when the IW command
is registered as a custom command. The IW command
handles its arguments as integers. (If you want to
overwrite the setting as "123," enter "123.")

(3) Turn ON the address (Q1.0) to which the Address Value


Command request flag has been assigned. I1.0 0
I1.1 0
Q1.0 1
(4) The MW command is executed.
PID532 0

(5) Check that the address (I1.0) to which Address Value


the Command complete flag I1.0 1
I1.1 0
has been assigned turns ON.

(6) Check whether the address (I1.1) to which When the command is successful,
the Command error flag has been assigned is this remains "OFF."
ON or OFF.
Address Value
If it is OFF, the command has been processed I1.0 1
normally. If it is ON, the command processing I1.1 0
failed, so check the error code written to
the address (PID532) to which When the command fails, this turns
Command Result has been assigned. "ON," so check the error code.

Address Value
I1.0 1
I1.1 1
Q1.0 1
PID532 3

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

Command Execution Procedure Example


(Overwriting Multiple Variables at the Same Time)

This section explains how to overwrite local variables "#variable1" to "123.456," "#variable2" to
"999," and "#variable3" to "987.6" at the same time.
Multiple variables are overwritten at the same time, which prevents illegal combinations from
occurring even if inspections that reference these variables are performed while the overwriting is
in progress. (It prevents illegal combinations such as the X coordinate and the Y coordinate.)

By changing "Command Execution Procedure Example (Overwriting #variable as '123')," which was
explained previously, as shown below, you can overwrite multiple variables (up to 16) at the same
time.

(1) In step (2) of "Setting the custom command," change the execution details of the custom
command to "MW, #variable1, *01, #variable2, *02, #variable 3, *03."
(The variables "#variable1," "#variable2," and "#variable3," must be added to the setup data
in advance with the variable settings.)

(2) In step (2) of "Executing the command from Address Value


the PLC," change the parameters to enter into I1.0 0
the addresses (starting with PQD532) to which I1.1 0
Q1.0 0
Command Parameter has been assigned as
PID532 0
shown on the right. PQD528 120
PQD532: 123456 (#variable1 value) PQD532 123456
PQD536 999000
PQD536: 999000 (#variable2 value)
PQD540 987600
PQD540: 987600 (#variable3 value)

(3) The rest of the procedure is the same as "Command Execution Procedure Example
(Overwriting #variable as '123')."

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

4.3.8 MWX Command (Writing Array Variables)

This section explains how to use the "MWX command" as an example of the commands that must be
registered as new custom commands. The MWX command overwrites the specified scalar array
variable (global variable or local variable). In the initial values, the MWX command is not registered
in the custom commands, so you have to add a custom command.

Command Execution Procedure Example


(Overwriting #variable[] Values)
This section explains how to overwrite the entries in the local array variable "#variable[]" so that
the entry at index [0] becomes "123.456," the entry at index [1] becomes "999," and the entry at
index [2] becomes "987.6."

Setting the custom command

(1) At the top of the setup mode screen, click "Global," and then
click "Custom Instruction Settings."

(2) Select an unused command (here we select number 120); overwrite the execution details to
"MWX, (array variable name [index number at which to start writing]), *01;" and then click
"OK." Here we will add a command for changing the values starting at index [0] of the array
variable "#variable[]."
(The array variable "#variable[]" must be added to the setup data in advance with
the variable settings.)

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


PROFINET Edition SIMATIC S7-1200 4. Controlling the Controller with Commands

Executing the command from the PLC

(1) Enter "120," which is the command number of Address Value


the set custom command, into the address I1.0 0
I1.1 0
(PQD528) to which Command Number has
Q1.0 0
been assigned.
PID532 0
PQD528 120

(2) Enter in units of 2 words the parameters into Address Value


the addresses (starting with PQD532) to which I1.0 0
I1.1 0
Command Parameter has been assigned.
Q1.0 0
PQD532: 3 (number of variables) PID532 0
PQD528 120
PQD536: 123456 (#variable[0] value)
PQD532 3
PQD540: 999000 (#variable[1] value)
PQD536 123000
PQD544: 987600 (#variable[2] value) PQD540 999000
PQD544 987600
The MWX command handles arguments as decimal fractions,
so enter the value to overwrite the setting with as its initial value multiplied by 1000.
(If you want to overwrite the setting as "123," enter "123000.")
If the value that you want to overwrite the setting with is an integer,
use the IWX command instead of the MWX command when the IWX command is registered
as a custom command. The IWX command handles its arguments as integers.
(If you want to overwrite the setting as "123," enter "123.")

(3) Turn ON the address (Q1.0) to which the Address Value


Command request flag has been assigned. I1.0 0
I1.1 0
Q1.0 1
(4) The MWX command is executed. PID532 0

(5) Check that the address (I1.0) to which Address Value


the Command complete flag has been assigned I1.0 1
I1.1 0
turns ON.
When the command is successful,
(6) Check whether the address (I1.1) to which the
this remains "OFF."
Command error flag has been assigned is
Address Value
ON or OFF.
I1.0 1
If it is OFF, the command has been processed
I1.1 0
normally.
If it is ON, the command processing failed, so When the command fails, this turns "ON,"
check the error code written to the address so check the error code.
(PID532) to which Command Result has been
Address Value
assigned.
I1.0 1
I1.1 1
Q1.0 1
PID532 3

KEYENCE Corporation, Vision System Division www.keyence.com/xgxus


197188E 1028-2

You might also like