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
Rcan be omitted (RDS 100 4is the same asRDS 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.
RDS Command continuous readDM Device type 200 Number .S Data format signed 16-bit3 Count CR Terminator RD reads one point; RDS reads consecutive points up to the given count. The response lists the values separated by spaces.
+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.
| Format | Meaning | Response digits | Range |
|---|---|---|---|
| none | bit | 1 | 0 / 1 |
.U | decimal 16-bit unsigned | 5 (zero-padded) | 00000–65535 |
.S | decimal 16-bit signed | 6 (with sign) | -32768–+32767 |
.D | decimal 32-bit unsigned | 10 | 0000000000–4294967295 |
.L | decimal 32-bit signed | 11 (with sign) | -2147483648–+2147483647 |
.H | hexadecimal 16-bit | 4 | 0000–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.
WRS Command continuous writeDM200.S First device 3 Count +15025 Data 1 -05400 Data 2 200 Data 3 CR Terminator When the write succeeds, the PLC returns OK.
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,0000000010The 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 00MR1015: channel 10, bit 15R199915: 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