日本語 English

How to Communicate with the KEYENCE KV Series (HostLink and CIP Communication)

Overview

Performs message communication with the built-in Ethernet port of the KEYENCE KV series to read and write PLC status and memory
This page provides a library that communicates with the KV series using the following two kinds of messages

In both cases the KEYENCE PLC is the server, and no ladder is needed on the KEYENCE side

Differences between HostLink communication and CIP communication

Differences between HostLink communication and CIP communication
ItemHostLinkCIP
Speed△◎
Settings◎ △
Compatibility◎ ○
EtherNet/IP× ○

Host Link communication is KEYENCE's proprietary communication method, sending and receiving messages as ASCII strings
It supports TCP/IP and UDP/IP and uses port number 8501 (default)

FB list

Namespace: KvLink

List
HostLinkRunModeReadCheck operating mode
HostLinkRunModeChangeChange mode
HostLinkUnitTypeInquire model
HostLinkErrClrClear error
HostLinkErCheck error number
HostLinkSetTimeSet time
HostLinkSetForce set
HostLinkResetForce reset
HostLinkStsContinuous force set
HostLinkRssContinuous force reset
HostLinkReadRead data
HostLinkReadsRead consecutive data
HostLinkWriteWrite data
HostLinkWritesWrite consecutive data
HostLinkMBRMonitor read (bits)
HostLinkMWRMonitor read (words)
HostLinkUDPSend Host Link command UDP
HostLinkTCPSend Host Link command TCP

HostLinkRunModeRead (check operating mode)

HostLink check operating mode
Input
IpAddress
STRING[200]
Destination IP address
Output
ReciveData
STRING[10]
0=PROGRAM, 1=RUN

HostLinkRunModeChange (change mode)

HostLink change mode
Input
IpAddress
STRING[200]
Destination IP address
RunMode
BOOL
FALSE=PROGRAM, TRUE=RUN
Output
ReciveData
STRING[10]
Received data

HostLinkUnitType (query model)

HostLink query model
Input
IpAddress
STRING[200]
Destination IP address
Output
ReciveData
STRING[10]
Received data: PLC model
PLC model
KV-8000 : 57KV-8000A : 58KV-7300 : 54
KV-7500 : 55KV-3000 : 51KV-5000 : 52
KV-5500 : 53KKV-NC32T : 128KV-N60xx : 132
KV-N40xx : 133KV-N24xx : 134

HostLinkErrClr (clear error)

HostLink clear error
Input
IpAddress
STRING[200]
Destination IP address
Output
ReciveData
STRING[10]
Received data: PLC model

HostLinkEr (check error number)

HostLink check error number
Input
IpAddress
STRING[200]
Destination IP address
Output
ReciveData
STRING[10]
Received data: error number

HostLinkSetTime (set time)

Matches the time of the source PLC

HostLink set time
Input
IpAddress
STRING[200]
Destination IP address
Output
ReciveData
STRING[10]
Received data

HostLinkSet (force set)

HostLink force set
Input
IpAddress
STRING[200]
Destination IP address
Address
STRING[8]
Bit device
Output
ReciveData
STRING[10]
Received data

HostLinkReset (force reset)

HostLink force reset
Input
IpAddress
STRING[200]
Destination IP address
Address
STRING[8]
Bit device
Output
ReciveData
STRING[10]
Received data

HostLinkSts (continuous force set)

HostLink continuous force set
Input
IpAddress
STRING[200]
Destination IP address
Address
STRING[8]
Bit device
Size
USINT
Number to write
Output
ReciveData
STRING[10]
Received data

HostLinkRss (continuous force reset)

HostLink continuous force reset
Input
IpAddress
STRING[200]
Destination IP address
Address
STRING[8]
Bit device
Size
USINT
Number to write
Output
ReciveData
STRING[10]
Received data

HostLinkRead (read data)

HostLink read data
Input
IpAddress
STRING[200]
Destination IP address
Address
STRING[10]
Word device
Output
ReciveData
STRING[20]
Received data

HostLinkReads (continuous read data)

HostLink continuous read data
Input
IpAddress
STRING[200]
Destination IP address
Address
STRING[10]
Word device
Size
USINT
Number to write
Output
ReciveData
STRING[1986]
Received data, space-separated

HostLinkWrite (write data)

HostLink write data
Input
IpAddress
STRING[200]
Destination IP address
Address
STRING[10]
Word device
WriteData
STRING[16]
Write data
Output
ReciveData
STRING[10]
Received data, space-separated

HostLinkWrites (continuous write data)

HostLink continuous write data
Input
IpAddress
STRING[200]
Destination IP address
Address
STRING[10]
Word device
Size
STRING[16]
Number to write; write data digits within 1968 bytes
WriteData
STRING[1975]
Write data, space-separated
Output
ReciveData
STRING[10]
Received data

HostLinkMBR (monitor read (bits))

HostLink monitor read (bits)
Input
IpAddress
STRING[200]
Destination IP address
Devices
STRING[1981]
Bit devices, space-separated
Output
ReciveData
STRING[1986]
Received data

HostLinkMWR (monitor read (words))

HostLink monitor read (words)
Input
IpAddress
STRING[200]
Destination IP address
Devices
STRING[1981]
Word devices, space-separated
Output
ReciveData
STRING[1986]
Received data

HostLinkUDP (send Host Link command UDP)

HostLink send Host Link command
Input
IpAddress
STRING[200]
Destination IP address
Command
STRING[1986]
Host Link command
Output
ReciveSize
UINT
Number of bytes received
In-out
ReciveData
BYTE[*]
Received data

HostLinkTCP (send Host Link command TCP)

HostLink send Host Link command TCP
Input
IpAddress
STRING[200]
Destination IP address
Command
STRING[1986]
Host Link command
Output
ReciveSize
UINT
Number of bytes received
In-out
ReciveData
BYTE[*]
Received data

Bit devices

R0, B0, MR0, LR0, CR0, T0, C0, CTC0, VB0, etc.

Word devices

R0, B0, MR0, LR0, CR0, VB0, DM0, EM0, FM0, ZF0, W0, TM0, Z1, T0, TC0, TS0, C0, CC0, CS0, AT0, CM0, VM0, etc.

Data format
.U .S .D .L .H can be specified

Response (ReciveData)

Normal

OK[CR][LF]

With data

Data 1spData 2spData 3sp...Data n[CR][LF]
sp = space

Error

E?[CR][LF]
E0Device number error
E1Command error
E2Program not registered
E3Write protected
E4Command error
E5Main unit error
E6No comment

Host Link communication program example

HostLinkSet (force set)

Force set
HostLink force set
FB input variables
Address 'MR0'
FB output variables
ReciveData 'OK$R$L'

HostLinkRead (read data)

Read data
HostLink read data
FB input variables
Address 'MR0'
FB output variables
ReciveData 'OK$R$L'

HostLinkReads (continuous read data)

Read consecutive data
HostLink continuous read data
FB input variables
Address 'MR0'
Size 5
FB output variables
ReciveData '0 0 0 0 0$R$L'

HostLinkWrites (continuous write data)

Write consecutive data
HostLink continuous write data
FB input variables
Address 'MR0'
Size 3
WriteData '0 1 1'
FB output variables
ReciveData 'OK$R$L'

HostLinkMWR (monitor read (words))

Monitor read (words)
HostLink monitor read (words)
FB input variables
Devices 'DM0 DM10'
FB output variables
ReciveData '00257 30683$R$L'

HostLinkTCP (send a Host Link command)

Send a Host Link command
HostLink send a Host Link command
FB input variables
Command 'BE 1$R'
FB output variables
ReciveData 4F 4B 0D 0A ('OK$R$L')

CIP communication

CIP communication reads data and so on using the message communication (server) function of the EtherNet/IP unit

Namespace: KvLink
FB list
CipRunModeRead Check operating mode
CipRunModeChangeChange mode
CipUnitType Inquire model
CipErrClr Clear error
CipEr Check error number
CipReads Read consecutive data
CipWrites Write consecutive data
CipClass3 Send CIP command Class 3

CipRunModeRead (read operating mode)

CIP read operating mode
Input
RoutePath
STRING[50]
Route path
Output
RespDat
BYTE
00=PROGRAM, 01=RUN

CipRunModeChange (change mode)

CIP change mode
Input
RoutePath
STRING[50]
Route path
RunMode
BOOL
FALSE=PROGRAM, TRUE=RUN
Output
RespDat
BYTE
Received data

CipUnitType (query model)

CIP query model
Input
RoutePath
STRING[50]
Route path
Output
RespDat
BYTE
Received data: PLC model
PLC model
KV-8000 : 39KV-8000A : 3AKV-7300 : 36
KV-7500 : 37KV-3000 : 33KV-5000 : 34
KV-5500 : 35KV-NC32T : 80KV-N60xx : 84
KV-N40xx : 85KV-N24xx : 86

CipErrClr (clear error)

CIP clear error
Input
RoutePath
STRING[50]
Route path
Output
RespDat
BYTE
Received data

CipEr (check error number)

CIP check error number
Input
RoutePath
STRING[50]
Route path
Output
RespDat
BYTE
Received data: error number

CipReads (continuous read data)

CIP continuous read data
Input
RoutePath
STRING[50]
Route path
Device
\\KvLink\DeviceCode
Device type
Address
UDNT
Device number
DataType
BYTE
0=default, 1=word, 2=2 words, 3=bit
ReadSize
UINT
Number of devices
Output
RespSize
UINT
Number of bytes received
RespDat
BYTE[512]
Received data

CipWrites (continuous write data)

CIP continuous write data
Input
RoutePath
STRING[50]
Route path
Device
\\KvLink\DeviceCode
Device type
Address
UDNT
Device number
DataType
BYTE
0=default, 1=word, 2=2 words, 3=bit
WriteSize
UINT
Number of bytes to write
WriteData
BYTE[500]
Write data
Output
RespDat
BYTE
Received data

Send CIP command Class 3

Send CIP command Class 3
Input
RoutePath
STRING[50]
Route path
ServiceCode
UINT
ClassID
UDNT
Device number
InstanceID
UINT
AttributeID
UINT
ServiceDat
BYTE[512]
Send service data
Size
UINT
Number of send elements
Output
RespSize
UINT
Response size
In-out
RespDat
BYTE[*]
Response data

Response (RespDat)

When memory is in the following state
MR0 MR1 MR2 MR3 MR4 MR5 MR6 MR7
ON ON ON ON OFF ON OFF OFF
When DataType = 3 (bit)
01 01 01 01 00 01 00 00
When DataType = 1 or 2 (word)
FF 02

CIP communication program example

CIP communication program example
CIP communication program example

CipReads (continuous read data)

Input
RoutePath
'02\192.168.250.31'
Device
\\KvLink\DeviceCode#MR
Address
0
DataType
0
ReadSize
10
Output
RespSize
10
RespData
01 01 01 01 00 01 00 00 00 00

CipWrites (continuous write data)

Input
RoutePath
'02\192.168.250.31'
Device
\\KvLink\DeviceCode#MR
Address
0
DataType
0
WriteSize
10
WriteData
01 01 01 01 00 01
Output
RespData
00

CIP Communication with Tag Specification

Reads tag values using the message communication (server) function of CIP communication

Supported models

KV-8000

Tag settings on the KV side

In KV STUDIO tag settings, set the Class 3 tag to [Input/Output]
Tag settings on the KV side

Ladder on the NJ side

Reads the tag value using the standard FB CIPUCMMRead instruction
Ladder on the NJ side
Input
RoutePath
STRING[50]
Route path
Timeout
UINT
Timeout (0.1 s units)
SrcDat
STRING
Remote variable name
Size
UINT
Number of elements to read
Output
RespSize
UINT
Size of data read
In-out
DstDat
ANY
Value of the data read

Related pages

TCP and UDP communication test tool

Analyze and test TCP and UDP communication

ComCom

An application that sends messages you create using Ethernet socket communication

CIP communication analysis tool

Analyze and test EtherNet/IP / CIP communication

CipMes

An application that sends CIP messages using Ethernet socket communication

Python Host Link communication

KEYENCE Host Link Communication

Host Link communication with KEYENCE PLCs

KvLink library

By downloading, you are deemed to have agreed to the Terms of Use

Files included with the library

  • KvLink.slr (library file)
  • KvLink.csm2 (library source file)
  • KvLinkSample.csm2 (sample using the library)
  • KvLink.md (library description)

Comments