// LEARN · Host Link Guide

Host Link command and response format (RD, RDS, WR, WRS)

How to write KEYENCE KV series Host Link commands and read their responses, walked through with real examples. Covers the separating spaces, device notation, the digits of the .U, .S, .D, .L and .H data formats, timer/counter reads and 32-bit values.

Updated

A Host Link command is a single line of text: the command name, the device, the count and the data, separated by spaces. This article walks through the format using the manual’s example of reading and writing three words from DM200 as signed 16-bit values.

Basic rules

  • Fields are separated by a single space (0x20)
  • The device type and number are written together (DM200)
  • The data format goes right after the number (DM200.S)
  • The relay prefix R can be omitted (RDS 100 4 is the same as RDS R100 4)
  • Leading zeros of device numbers, counts and write data can be omitted, and so can the + of positive write values

Continuous read: RDS

This command reads the three words DM200–DM202 as signed 16-bit values.

Command
RDS Command continuous read
␣
First device
DM Device type
200 Number
.S Data format signed 16-bit
␣
3 Count
CR Terminator

RD reads one point; RDS reads consecutive points up to the given count. The response lists the values separated by spaces.

Response
+15025 DM200
␣
-25400 DM201
␣
+00000 DM202
CR LF Terminator

Data formats and digits

The data format tells the PLC how to read or write the value. The number of digits in the response is fixed for each format.

FormatMeaningResponse digitsRange
nonebit10 / 1
.Udecimal 16-bit unsigned5 (zero-padded)00000–65535
.Sdecimal 16-bit signed6 (with sign)-32768–+32767
.Ddecimal 32-bit unsigned100000000000–4294967295
.Ldecimal 32-bit signed11 (with sign)-2147483648–+2147483647
.Hhexadecimal 16-bit40000–FFFF

With .S and .L, zero is also returned with a sign, as in +00000.

When the format is omitted, each device has a default:

  • bit: R, B, MR, LR, CR, VB
  • .U: DM, EM, FM, ZF, W, TM, Z, CM, VM
  • .D: T, TC, TS, C, CC, CS, CTH, CTC, AT

Adding a format such as .U to a bit device (R, B, MR, LR, CR, VB) reads or writes 16 or 32 bits at once. If you start from a bit other than the first of a channel (R002, for example), the read runs on into the next channel.

Continuous write: WRS

For writes, the data follows the count, separated by spaces.

Command
WRS Command continuous write
␣
DM200.S First device
␣
3 Count
␣
+15025 Data 1
␣
-05400 Data 2
␣
200 Data 3
CR Terminator

When the write succeeds, the PLC returns OK.

Response
OK Success
CR LF Terminator

To write a single point, leave out the count, as in WR DM200.S -100. Writing T or C with WR changes the current value; WS / WSS change the set value.

Timers and counters return three values

Reading T, C, CTC or CTH returns three values per point: contact, current value and set value. The contact is 0 / 1; the current and set values use the given format (.D by default).

RD T0
0,0000000010,0000000010

The manual’s figures mix commas and spaces, but a real KV-7500 returned them separated by commas. To read only the current or set value, use TC / TS (CC / CS for counters).

32-bit values use two words

.D and .L treat two words as one value: the given number is the low word and the next number is the high word. RD DM100.L, for example, reads DM100 (low) and DM101 (high).

Relay numbers are “channel + 2-digit bit number”

R, MR, LR and CR numbers are a decimal channel number followed by a two-digit bit number (00–15).

  • R100: channel 1, bit 00
  • MR1015: channel 10, bit 15
  • R199915: channel 1999, bit 15

Since bit numbers stop at 15, there is no such number as MR1016.

B, VB and W numbers, on the other hand, are hexadecimal (B7FF, W1A0 and so on). All other devices are decimal.

How to write it with KcpX

In KcpX, you give the device type as a Prefix and the number as a string. The data format follows from the type: short is .S, ushort is .U, int is .L and uint is .D.

// Same as RDS DM200.S 3
short[] values = kcpx.BatchRead<short>(Prefix.DM, "200", 3);

// Same as WRS DM200.S 3 +15025 -05400 200
kcpx.BatchWrite<short>(Prefix.DM, "200", [15025, -5400, 200]);

// Contact, current value and set value of T0
TimerCounterValue t0 = kcpx.ReadTimerCounter(Prefix.T, "0");

The next article looks at the response you get when something goes wrong.

Sources

  • KEYENCE KV-EP21V/KV-8000(A)/KV-7500/KV-5500/KV-NC1EP User's Manual, EtherNet/IP Functions (Japanese edition) chapter 8 pp.8-17–8-26, 8-37