You are on page 1of 41

【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

Table of Contents
I. Configuration (Hardware/Software)
I. SIEMENS Products Hardware Configuration
II. SIEMENS Products Software Configuration
III. KEYENCE Hardware Configuration
IV. KEYENCE Software Configuration

II. Connection
I. Communication Cable Connecting Diagram between CP1241<->N-R2
II. Overall Connecting Diagram

III. Configuration of KEYENCE Code Reader


I. Communication Setting and Terminal Setting for KEYENCE Code Reader

IV. Configuration of SIEMENS S7-1200


I. Device Connection between PC and S7-1200
II. Operation of Totally Integrated Automation [Basic Configuration + Communication Setting]

V. Creating S7-1200 RS-232C Communication Programme


I. Creating DB
II. Creating FC
III. Editing Main

VI. Programme Operation Test (Command Trigger)


I. Creating Watch Table
II. Downloading and Monitoring the Project

VII. Sample Programme (Command Trigger)


I. Overall Configuration of Sample Programme
II. Introduction of Sample Programme (Common Parts)
III. Introduction of Sample Programme (LAD: Ladder)
III. Introduction of Sample Programme (FBD: Function Block Diagram)

VII. Sample Programme (Hard Trigger)


I. Overall Configuration of Sample Programme
II. Introduction of Sample Programme (Common Parts)
III. Introduction of Sample Programme (LAD: Ladder)
III. Introduction of Sample Programme (FBD: Function Block Diagram)

IX. Troubleshooting

1/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

I. Configuration (Hardware/Software)
I. SIEMENS Products Hardware Configuration
Mark Function Model number Order number
A CPU Unit CPU 1211C DC/DC/DC 6ES7 211-1AD30-0XB0
B RS-232C Communication Unit CM1241 RS232 6ES7 241-1AH30-0XB0
C Memory Card 2Mbyte Memory Card 6ES7 954-8LF00-0AA0

A B
C

II. SIEMENS Products Software Configuration


i Totally Integrated Automation
Software for configuration of SIEMENS PLC and programming
Languages available: ladder, function block diagram

III. KEYENCE Hardware Configuration

KEYENCE Code Reader Communication unit and cable
Barcode Reader 2D Code Reader Communication Cross Cable
BL-1300 Series SR-600 Series Unit N-R2

IV. KEYENCE Software Configuration


AutoIDNavigator
Software for configuration of KEYENCE Code Reader and peripheral devices
Interface: RS-232C, USB, Ethernet

2/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

II. Connection
I. Communication Cable Connecting Diagram between CM1241<->N-R2
Connect CM1241 and N-R2 (KEYENCE Code Reader communication unit) as the following diagram.

Signal name Pin No. Pin No. Signal name


Connector case Connector case

II. Overall Connecting Diagram


I In case of Command Trigger
24V

0V

Code
Reader

3/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

II In case of Hard Trigger


24V

0V

*2

*1

Code
Reader

*1 *2

DC24V 24VDC 1M 0V *2
DC0V 0V I0.0
I0.1
*1 IN COM I0.2
IN1 I0.3
IN2 I0.4
I0.5
DC24V OUTCOM 3L+ 24V *1
OUT1 3M 0V
OUT2 Q0.0
OUT3 Q0.1
*2 OUT4 Q0.2
Q0.3

4/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

III. Configuration of KEYENCE Code Reader


I. Communication Setting and Terminal Setting for KEYENCE Code Reader

I Communication Setting for BL-1300 Series


BL-1300 Series enable communication in default setting when S7-1200 configuration is
the same as described in IV-II-IV (BL-1300).
If you want communication setting other than below, you also have to change the communication
setting for CP1241-RS232C as mentioned in IV-II-IV.

Setting item Parameter Setting item Parameter


Baud rate 9600bps PLC Link Disable
Parity Even Handshaking None
Data bits 7 bits Format Length Excluded
Stop bit 1 bit Checksum Excluded
Multi-drop link Disable Header None
RTS/CTS Disable Delimiter CR

II Terminal Setting for BL-1300 series

Setting item Setting


IN1 Function Timing

OUT1 Function OK
OUT2 Function NG+ERROR
OUT3 Function ERROR
OUT4 Function BUSY

5/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

II Communication Setting for SR-600 Series


SR600 Series enable communication in default setting when S7-1200 configuration is
the same as described in IV-II-IV (SR-600).
If you want communication setting other than below, you also have to change the communication
setting for CP1241-RS232C as mentioned in IV-II-IV.

Setting item Parameter Setting item Parameter


Baud rate 115200bps PLC Link Disable
Parity Even Handshaking None
Data bits 8 bits Format Length Excluded
Stop bit 1 bit Checksum Excluded
Multi-drop link Disable Header None
RTS/CTS Disable Delimiter CR

Ⅱ Terminal Setting for SR-600 series

Setting Item Setting


IN1 Function Timing

OUT1 Function OK
OUT2 Function NG+ERROR
OUT3 Function ERROR
OUT4 Function BUSY

6/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

IV. Configuration of SIEMENS S7-1200


I. Device Connection between PC and S7-1200
Connect PC to which Totally Integrated Automation are installed and
S7-1200 with a LAN cable.

Engineering
PC
LAN cable

II. Operation of Totally Integrated Automation [Basic Configuration + Communication Setting]

I Creating a New Project

Activate Totally Integrated Automation and create an arbitrary name for the new project.
(In this sample of this document, the project is named as ”S7-1200 RS-232C").

7/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

II Creating a New Object

Select the newly created project.


Select "Devices & Networks" -> "Add new device" -> "CPU".
(6ES7 211-1AD30-0XB0 is used in this sample example.)

III Totally Integrated Automation Hardware Configuration

i Double click Devices & Networks for the hardware configuration.

8/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

ii Adding the Communication Unit RS-232C


From the Hardware catalog on the right side of the screen, select Communication
module -> RS232C and drag & drop 6ES7 241-1AH30-0XB0 to add.

9/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

IV Communication Setting for RS232C

i Configuration of CM241 RS232C port


Click CM241 RS232C port to select Properties at the screen below.
Open Port configuration to configure the communication settings.
Adjust the communication setting to Code Reader.

Default setting for BL-1300 Series

Default setting for SR-600 Series

* The above shows communication setting for S7-1200.


Adapt this setting to communication setting of KEYENCE Code Reader.
All procedures for communication setting for CP1241-RS232C is completed.
Close the Devices & Networks window.

10/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

V. Creating S7-1200 RS-232C Communication Programme


I. Creating DB

Programme overview
Create a Data block (DB) to be used on the programme.
Create DB20, a Data block to store the data received from the code reader, and
DB21, a Data block to store the send command to the code reader.

i Creating DB20 (Data block to sore the received data)

Navigate in the following order: PLC Programming -> Add new block -> Data block ->
Name -> Global DB -> Select Manual -> Number(20) -> Create.

Configure the Data block as shown below.


"Name -> Data" "Data type -> Array [0..64] of byte"

11/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

ii Creating DB21 (Data block to store the send command)

Navigate in the following order: PLC Programming -> Add new block -> Data block ->
Name -> Global DB -> Select Manual -> Number (21) -> Create

Configure the Data block as shown below.


"Name -> Data" "Data type -> Array [0..64] of byte"

12/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

II.Creating FC

I. Creating INITIAL function

Programme overview
Create normal ON flag and normal OFF flag.

i Add FC (function created by users) to Blocks

As shown on the diagram below, input "100" in Number in Manual setting to create
the initial programme.

ii Create Normal ON flag and Normal OFF flag


Double click INITIAL FC to activate ladder editor and create the circuit as shown below.
《FC100 : INITIAL》 * Users can freely specify the name of FC No.

13/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

II. Creating BL Communication Setting

Create a trigger circuit for the code reader initiated by command output as well as
a receiving circuit for the data read by the code reader.

i Add FC (function created by users) to Blocks.

Input "201" in Number in Manual setting to create the initial programme as shown below.

ii Create an Interface
Double click INITIAL FC to activate ladder editor to create the circuit as shown below.
《FC100: INITIAL》 * Users can freely specify the name of FC No.

14/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

iii Creating a network to receive data from the code reader.

From Instruction on the right side of the screen, select Extended instruction ->
Communications and drop & drag RCV_PTP to insert.

(1) Just above RCV_PTP, specify DB No. to be used. (DB201 as for this sample)
(2) To the left of RCV_PTP, specify the value to be input.
(3) To the right of RCV_PTP, specify an address to be output (created TEMP address).

RCV_PTP Parameter
Name Type Data type Description
EN_R INPUT BOOL Check for the received messages when this input is True.
Messages received correctly will be transferred from the
module to CPU.When False, check for received messages in
CM and set the Status output. However, the messages will
not be transferred to CPU.
PORT INPUT PORT Communication port identifier

BUFFER INPUT Variant Reception of buffer starts from this point. Requires buffers
larger than the maximum length of reading data.
NDR OUTPUT BOOL Returns True for a single scan when new data is ready and
operation has been completed successfully.
ERROR OUTPUT BOOL Returns Error for a single scan process when there are
errors in the operation.
STATUS OUTPUT WORD Execution condition code

LENGTH OUTPUT Uint Length of returning message

15/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

iv Creating a network to transmit triggers to the code reader.

v Store Laser ON (LON) and Laser OFF (LOFF) commands to the code reader in DB21.

16/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

vi Creating the pulse to send a command transmission request to the code reader.

vii Creating a network to send command to the code reader.

From Instruction on the right, go to Extended instruction -> Communications to drag & drop
and insert SEND_PTP.

(1) Just above SEND_PTP, specify DB No. to be used. (DB202 as for this sample)
(2) To the left of SEND_PTP, specify the value to be input.
(3) To the right of SEND_PTP, specify an address to be output (created TEMP address).

17/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

SEND_PTP Parameter
Name Type Data type Description
REQ INPUT BOOL Activate the requested transfer at positive edge.

PORT INPUT PORT Communication port identifier

BUFFER INPUT Variant Specify the location to start sending the send command.

LENGTH INPUT UInt Byte count of the transmission frame.

PTRCL INPUT BOOL Protocol selection

DONE OUTPUT BOOL Returns True for a single scan process after successful
completion for the request.
ERROR OUTPUT Uint Returns Error for a single scan process when there are
errors in the operation.
STATUS OUTPUT Uint Execution condition code.

viii Creating a timer for reading timeout of code reader

III. Editing Main

Create a programme to call INITIAL and BL_Communication Setting for Main.

18/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

VI. Programme Operation Test (Command Trigger)


I. Creating Watch Table

Select Watch table from the Project tree below and select "Add new Watch table".

Register variables in the Watch table as shown below.

19/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

II. Downloading and Monitoring the Project


I Downloading the project

Connect a PC and S7-1200 using a LAN.


Click a download button (red frame) to download the project to S7-1200.

II Monitoring the Project Execution

i Open the Watch table to enable monitoring.

ii Turn ON the command trigger bit for the code reader

-> Make sure the laser of the code reader is flashing.

20/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide
iii Reading the sample barcode
When the sample barcode is read as shown below, "KEYENCE$R" will be input in each
address starting from DB20.DBW0.
When the sample barcode is not read and the reading is not completed within
READ TIME OUT (1sec) set in the sample programme,
ERROR will appear in each address starting from DB21.DBW0.

Sample Barcode

* K E Y E N C E *

Read data

Send command

21/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

VII. Sample Programme (Command Trigger)


I. Overall Configuration of the Sample Programme

Programme Description of functions of the programme


Main This is the main function of the programme activated on the system, and while
the programme is running, it is repeatedly executed in a cycle.
BL_Communication This programme creates a trigger circuit for the code reader and a receiving
Setting circuit for the data read by the code reader.
INITIAL Creates Normal ON flag and Normal OFF flag.

DB20 Data block to store data received from Code Reader.

DB21 Data block to store send command to Code Reader.

IEC_TIMER_1 DB that is automatically created when the timer is created.

RCV_PTP_DB DB created when RCV_PTP is used.

SEND_PTP_DB DB created when SEND_PTP is used.

22/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

II. Introduction of Sample Programme (Common Parts)

I Data block to store received data

This is a data block to store the data read by the code reader.

II Data block to store the send command

This is a data block to store commands for the code reader.

III Create Watch table

Table to check the performance.


Check whether the trigger bit is turned ON or OFF, the received data, and the send
command.

23/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

III Introduction of Sample Programme (LAD: Ladder)

I Main (Organization block)

This is the main function of the programme activated on the


system, and while the programme is running, it is repeatedly executed in a cycle.

Call INITIAL and execute


the programme.

Call FC101 and execute the


programme.

II INITIAL(FC100)

Normal ON and Normal OFF circuits

M0.1
Normal OFF

M0.0
Normal ON

24/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

III BL Communication Setting (FC201)

This programme creates a trigger circuit for the code reader and a receiving circuit for the
data read by the code reader.

Temporary memory
usable within this FC
only.
Used to exchange and
monitor the values.

Set input/output parameters


of FB for the
CM1241(RS232C)
communication unit
reception.

* See "V-II-II-iii
BL_Communication
Setting" for details.

Trigger for Laser ON comes


on when turning M100.0
ON.

25/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

Store Laser ON command


"LON [CR]" in send command
DB.

Store Laser OFF command


"LOFF [CR]" in send
command DB.

26/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

Turn the send command


request ON.

Send the command stored in


DB21 to the code reader
with #REQ as a trigger.

Configuring the timer.


Trigger to send Laser OFF
command comes ON upon
the timeout.

27/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

IV Introduction of Sample Programme (FBD: Function Block Diagram)

I Main (Organization block)

This is the main function of the programme activated on the


system, and while the programme is running, it is repeatedly executed in a cycle.

Call INITIAL and execute


the programme.

Call FC101 and execute the


programme.

II INITIAL(FC100)
Normal ON and Normal OFF circuits

M0.1
Normal OFF

M0.0
Normal ON

28/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

III BL Communication Setting(FC201)

This programme creates a trigger circuit for the code reader and a receiving circuit for the
data read by the code reader.

Temporary memory usable


within this FC only.
Used to exchange and
monitor the values.

Set input/output
parameters of FB for the
CM1241(RS232C)
communication unit
reception.

* See "V-II-II-iii
BL_Communication
Setting" for details.

Trigger for Laser ON


comes on when turning
M100.0 ON.

29/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

Store Laser ON command "LON


[CR]" in send command DB.

Store Laser OFF command


"LOFF [CR]" in send command
DB.

30/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

Turn the send command


request ON.

Send the command stored in


DB21 to the code reader with
#REQ as a trigger.

Configuring the timer.


Trigger to send Laser OFF
command comes ON upon the
timeout.

31/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

VIII. Sample Programme (Hard Trigger)


I. Overall Configuration of the Sample Programme

Programme Description of functions of the programme


This is the main function of the programme activated on the system, and while
Main
the programme is running, it is repeatedly executed in a cycle.
BL_Communication This programme creates a trigger circuit for the code reader and a receiving
Setting circuit for the data read by the code reader.
INITIAL This programme creates Normal ON flag and Normal OFF flag.

Data block to store data received from Code Reader.


DB20

IEC_TIMER_1 DB that is automatically created when the timer is created.

RCV_PTP_DB DB that is created when RCV_PTP is used.

32/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

II. Introduction of Sample Programme (Common Parts)


I Data block to store received data.

This is a data block to store the data read by the code reader.

II Create Watch table

Table to check the performance.


Check whether the trigger bit is turned ON or OFF and the received data and send command.

33/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

III Introduction of Sample Programme (LAD: Ladder)

I Main (Organization block)

This is the main function of the programme activated on the


system, and while the programme is running, it is repeatedly executed in a cycle.

Call INITIAL and execute the


programme.

Call FC101 and execute the


programme.

II INITIAL(FC100)

Normal ON, Normal OFF circuits.

M0.1
Normal OFF

M0.0
Normal ON

34/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

III BL Communication Setting(FC201)

This programme creates a trigger circuit for the code reader and a receiving circuit for the
data read by the code reader.

Temporary memory usable


within this FC only.
Used to exchange and
monitor the values.

Set input/output parameters


of FB for the
CM1241(RS232C)
communication unit
reception.

* See "V-II-II
BL_Communication Setting"
for details.

Trigger for Laser ON comes


on when turning M100.0 ON.

35/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

Turn ON the laser ON bit


(Q0.0) of code reader.

Monitoring circuit for OK


signal (I0.0).

Monitoring circuit for


NG/ERROR signal (I0.1).

Monitoring circuit for ERROR


signal (I0.2).

Monitoring circuit for BUSY


signal (I0.3).

36/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

Set the timer starting from


turning ON the code reader
until the laser is turned OFF.

Turn off the Code reader


reading when the signal from
the code reader is ON or timer
times out.

37/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

IV Introduction of Sample Programme (FBD: Function Block Diagram)


I Main (Organization block)

This is the main function of the programme activated on the


system, and while the programme is running, it is repeatedly executed in a cycle.

Call INITIAL and execute the


programme.

Call FC101 and execute the


programme.

II INITIAL(FC100)
Normal ON, Normal OFF circuits.

M0.1
Normal OFF

M0.0
Normal ON

38/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

III BL Communication Setting(FC101)

This programme creates a trigger circuit for the code reader and a receiving circuit for the data read
by the code reader.

Temporary memory usable


within this FC only.
Used to exchange and
monitor the values.

Set input/output parameters


of FB for the
CM1241(RS232C)
communication unit
reception.

* See "V-II-II
BL_Communication
Setting" for details.

Trigger for Laser ON comes


on when turning M100.0
ON.

Turn ON the laser ON bit


(Q0.0) of code reader.

39/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

Monitoring circuit for OK


signal (I0.0).

Monitoring circuit for


NG/ERROR signal (I0.1).

Monitoring circuit for ERROR


signal (I0.2).

Monitoring circuit for BUSY


signal (I0.3).

Set the timer starting from


turning ON the code reader until
the laser is turned OFF.

Turn off the Code reader


reading when the signal from
the code reader is ON or timer
times out.

40/41
【KEYENCE CODE-READER】 【SIEMENS S7-1200】 Connection Guide

IX. Troubleshooting

Q Communication is not available even though the code reader is connected to a LAN cable

A You may have a different IP address.

Click Accessible Device on the tool bar to search the CPU from accessible IP address.

Check IP address of the CPU. Change the IP address to have the same subnet.

Q Laser does not come out even though TRG of M100.0 is True.

A Communication may not be properly set.

· In the case of command trigger


Check if the RD lamp in N-R2 turns ON at the moment TRC is switched ON.
If not, check for errors in the communication configuration, wire connection,
and other settings.

· In the case of hardware trigger


Check if IN1 lamp in N-R2 turns ON at the moment TRG is switched ON.
If not, check for errors in wire connection and the other settings.

41/41

You might also like