
Direct UTP/IP connectivity with Siemens S7
and Allen-Bradley PLCs
Document/Revision No. IM-EN-PLC: Rev. 1.0
Eective: April 9, 2019
Instruction Manual

Table of contents
1 Direct connecon to PLC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Direct UDP/IP connecon between SIEMENS S7 PLC and K-Patents refractometer . 3
2.1 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Using the KP_REFRACTOMETER AOI in Rockwell Studio 5000 for
Allen-Bradley PLCs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.1 Instrucons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4 Accessing the refractometer web interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1
1 Direct connecon to PLC
A PR-43 or PR-33 refractometer or a PR-23 system can be connected over direct UDP to a
Siemens S7 or Allen-Bradley PLC. K-Patents provides the soware components that enable direct UDP communicaon between refractometer and PLC. For the connecon, customers only
need to insert the ready-made soware components into their PLC program. The programming
soware components are available for download free of charge at hp://www.kpatents.com/.
The direct UDP/IP connecon allows transmission of refractometer measurement values to the
PLC program. However, only measurement data is transmied, therefore calibraon and other
conguraon sengs cannot be made via this connecon.
1 2 3
4 5 6
7 8 9
- 0 .
BACK
ENTER
25.31
25.31
A
A
max. 200m (656ft)
PR-8230
PR-23 sensor cable
PLC
Programmable Logic Controller
PR-23 REFRACTOMETER
DTR dual transmitter
PR-8438, Internal Ethernet Cable
M12-4 pin, D-code, F, RJ-45
Ethernet, 0,5m
max. 90m (295ft)
PR-8330
Ethernet converter cable
M12-4 pin, D-code, M
Ethernet (RJ45)
Power 100-240 VAC
mA OUTPUT
Figure 1.1 Connecng a PR-23 system to PLC
+ Blue
- Brown
- Black
+ White
mA-OUTPUT (4-20mA)
24VDC in
F M
PR-33 REFRACTOMETER
M-12-4 pin, A-code, M
M-12-4 pin, D-code, F
non-Ex
PR-8330-010
Cat 5e Ethernet cable (PVC), OD = 6,0mm
10m (30ft) standard, max. 100m (300ft)
PR-8350-010
Cable 4 x 0,75mm2 (PUR), OD = 6,0mm (0.24”)
10m (30ft) standard, max. 100m (300ft)
PLC
Programmable Logic Controller
Figure 1.2 Connecng a PR-33 refractometer to PLC

MFF
PR-43 REFRACTOMETER
M-12-8 pin, A-code, M
non-Ex
10m (33ft)
1m (3,3ft)
PR-8431
Split cable M12
M12-8 pin, A-code, F
Ethernet (M12-4 pin, D-code,M)
PR-8442-001
mA, 24V
Ethernet converter cable
M12-4 pin, A-code, F
Ethernet (RJ45)
PLC
Programmable Logic Controller
mA, 24V
Figure 1.3 Connecng a PR-43 refractometer to PLC
ETHERNET
mA OUTPUTPower 100-240VAC
JB-UN-PCE/SS-U/M/AC
Junction box for P4 refractometers
Screw terminals
Ethernet, Ground, 24VDC, mA
F
max. 90m (295ft)
PR-8437
Platform 4 cable
M12-8 pin, A-code, F
Open end
Ethernet, mA, 24V
PR-43-AX
REFRACTOMETER
M-12-8 pin, A-Code, M
Unclassified area
PLC
Programmable Logic Controller
Figure 1.4 Connecng a PR-43 refractometer with juncon box to PLC

3
2 Direct UDP/IP connecon between SIEMENS S7 PLC
and K-Patents refractometer
All measurement and diagnosc data can be received from a K-PATENTS refractometer via
UDP/IP communicaon. This follows a simple protocol: a device sends a request to the refractometer and it sends the data in return. This document and the aached les present an
implementaon of this communicaon on a SIEMENS S7 PLC.
The aached project le is made with TIA Portal V15. It contains a funcon block called “REFRACTOMETER_CONNECTION”. It can be used in other projects, and it gives an instant soluon
of the task. All used FB and DB blocks must be copied as well.
2.1 Usage
IP address of the refractometer must be set in the “TUSEND_address” DB, which is used in
Network 4 inside of “REFRACTOMETER_CONNECTION”.
To establish connecon, “UDP_connect” must be set to “1”, while “UDP_disconnect” is “0”. If
successful, “UDP_ready” will change to “1”.
To send data request, “UDP_send” must change from “0” to “1”. Aer that, refractometer
will send the data. Then the values of the local tags on the right side of the “REFRACTOMETER_CONNECTION” FB will be updated.
To have constantly updang values, “UDP_send” should change from “0” to “1” cyclically. A
bit of CPU clock memory, or a mer (see an example for that in the aached project: Main
program, Network 2.) can be used.

4
3 Using the KP_REFRACTOMETER AOI in Rockwell Stu-
dio 5000 for Allen-Bradley PLCs
The KP_REFRACTOMETER Add-On Instrucon, downloadable at www.kpatents.com, enables
Rockwell users to easily extend their PLC soware with K-Patents refractometer connecon.
3.1 Instrucons
1. Import the AOI to your project, by right-clicking the “Add-On Instrucons” folder in the
Controller Organizer. In the pop-up window, locate the AOI and import it. It will appear
in the “Add-On Instrucons” folder aerwards. It will also import some user-dened data
types that it requires (See them also in the Controller Organizer).
2. Add an instance of KP_REFRACTOMETER to your ladder diagram. You will nd it on the
Add-On page of the ladder elements.
3. Create new controller level tags that will be needed for the operaon (the names are just
examples here, but the tags will be menoned with these names later in the document):
NAME (EXAMPLE) TYPE VALUE
kp_1 KP_REFRACTOMETER no need to set
use_refr BOOL no need to set
status String no need to set
rr READ_RESP_DATA no need to set
CREATE MESSAGE see below this table
DELETE MESSAGE see below this table
SEND MESSAGE see below this table

5
READ MESSAGE see below this table
SOCKET REQUEST_PARAMETERS Type: 2
Family: 2
Port: any unused available port
Read_Data_Req READ_DATA_REQ Timeout: 1000
BufLen: 300
Write_Data_Out WRT_DATA Timeout: 3000
ToAddr.Family: 2
ToAddr.Port: 50023, which is 1100
0011 0110 0111 binary. Port must be
entered in reversed byte order, which
is 0110 0111 1100 0011, and in
decimal view will be represented as
-15513
ToAddr.Addr: The IP address of the
refractometer. Also must be entered
in reverse byte order.
Buer.LEN: 12
Buer.BUFF: all zeros, except for
byte[3] which is 1, and byte[7] which
is 4.
4. Set up the messages. First, on the KP_REFRACTOMETER instance, set the message tags CREATE, DELETE, READ and SEND for the inputs CREATE_UDP_SOCKET, DELETE_UDP_SOCKET,
READ_UDP_DATA and SEND_UDP_DATA respecvely. Then, to the right of each input you
will see a pushbuon with the text “…”. Click it, and a pop-up window will appear where
message properes can be set.
Type: 2
Family: 2
Port: any unused, available port
Timeout: 1000
BufLen: 300
Timeout: 3000
ToAddr.Family: 2
ToAddr.Port: 50023, which is
1100 0011 0110 0111 binary. Port
must be entered in reversed byte
order, which is 0110 0111 1100
0011, and in decimal view will be
represented as -15513
ToAddr.Addr: The IP address of
the refractometer. Also must be
entered in reverse byte order.
Buffer.LEN: 12
Buffer.BUFF: all zeros, except for
byte[3] which is 1, and byte[7]
which is 4.
4. Set up the messages. First, on the KP_REFRACTOMETER instance, set the message tags
CREATE, DELETE, READ and SEND for the inputs CREATE_UDP_SOCKET, Delete_All_MSG,
READ_UDP_DATA and SEND_UDP_DATA respectively. Then, to the right of each input you will
see a pushbutton with the text “…”. Click it, and a pop-up window will appear where message
properties can be set.

6
a. For CREATE:
i. Service Type: Socket Create
ii. Source Element: Socket
iii. Desnaon Element: kp_1.SockNum
iv. On the communicaon page, Path: 1,0
b. For DELETE:
i. Service Type: DeleteSocket
ii. Instance: 0
iii. On the Communicaon page, Path: 1,0
c. For READ:
i. Service Type: ReadSocket
ii. Instance: any number
iii. Source Element: Read_Data_Req
iv. Desnaon Element: rr
v. On the Communicaon page, Path: 1,0
d. For SEND:
i. Service Type: WriteSocket
ii. Instance: any number
iii. Source Element: Write_Data_Out
iv. Source Length: 28
v. On the Communicaon page, Path: 1,0
5. Set the tags kp_1, use_refr, rr, status for the KP_REFRACTOMETER instance, and the inputs
“START”, “Read_Response” and “StatusValueStr” respecvely.

7
4 Accessing the refractometer web interface
Conguring a refractometer is not possible through direct UDP/IP connecon with PLC, because direct UDP/IP connecon provides only measurement and status data. The refractometer
can be congured, veried and diagnosed by accessing its built-in web server homepage. The
homepage is accessed by connecng a computer to a refractometer via a switch, a router or a
direct cable connecon. A connecon between refractometer and PLC can be temporarily disconnected while changing refractometer parameters – the connecon recovers automacally
aer the connecon is restored. See refractometer manual for details of the refractometer
network sengs.

K-Patents Oy
P.O. Box 77
FI-01511 Vantaa, Finland
tel. +358 207 291 570
fax +358 207 291 577
info@kpatents.com
K-Patents, Inc.
1804 Centre Point Circle,
Suite 106
Naperville, IL 60653, USA
tel. (630) 955 1545
fax (630) 955 1585
info@kpatents-usa.com
K-Patents (Shanghai) Co., Ltd
Room 1509,
Tomson Commercial Building, No.710
Dongfang RD
Pudong District, Shanghai, China
tel. +86 21 5087 0597/0598
fax +86 21 5087 0598
www.kpatents.com