23.03.2017 Views

wilamowski-b-m-irwin-j-d-industrial-communication-systems-2011

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

36-4 Industrial Communication Systems<br />

36.4 Modbus Application Layer<br />

The Modbus protocol defines three distinct APDUs (Figure 36.3) used in the Modbus application layer.<br />

All three APDUs start with a single-byte value indicating the Modbus function being requested or to<br />

which a reply is being made. Following the “function” byte value come all data and parameters of that<br />

specific function. Data and parameters have a variable number of bytes, depending on the function in<br />

question, and the number of memory registers that are being accessed.<br />

All APDUs are, however, limited in size to a maximum of 253 bytes, due to limitations imposed by<br />

the underlying EIA/TIA-485 layer. The Modbus protocol also specifies that all 16 bit addresses and data<br />

items are encoded using big-endian representation. This means that when a numerical quantity larger<br />

than a single byte is transmitted, the most significant byte is sent first. Nevertheless, some device manufacturers<br />

allow the user to specify whether the device should use big or little-endian encoding.<br />

The request APDU is sent by the client to the server. Upon successful completion of the desired<br />

function, the server replies with a response APDU. If the server encounters an error, the server notifies<br />

the client with an exception response APDU.<br />

36.4.1 Data Access Functions<br />

The Modbus protocol defines a large list of functions. The most often used functions are those associated<br />

with accessing the memory areas (Table 36.2).<br />

All functions listed in Table 36.2, with the exception of functions 0x14, 0x15, 0x16, and 0x18,<br />

Âsimply request that some data be read or written to a specific memory area. Function codes 0x05 and<br />

0x06 are used to write to a single element (coil or holding register, respectively). The remaining functions<br />

allow the client to read from or write to multiple contiguous elements of the same memory area.<br />

Function code (F)<br />

Function code (F)<br />

Exception function code (F + 0 × 08)<br />

Request data<br />

Reply data<br />

Exception code<br />

Request APDU<br />

Response APDU<br />

Exception response APDU<br />

FIGURE 36.3<br />

General format of APDU frames.<br />

TABLE 36.2<br />

Functions Used for Data Access<br />

Memory Area<br />

Function Name<br />

Function<br />

Code (Hex)<br />

Addressable<br />

Elements<br />

Possible Response<br />

Error Codes<br />

Discrete Inputs Read discrete inputs 0x02 1–2000 01, 02, 03, 04<br />

Coils Read coils 0x01 1–2000 01, 02, 03, 04<br />

Coils Write single coil 0x05 1 01, 02, 03, 04<br />

Coils Write multiple coils 0x0F 1–1976 01, 02, 03, 04<br />

Input registers Read input registers 0x04 1–125 01, 02, 03, 04<br />

Holding registers Read holding registers 0x03 1–125 01, 02, 03, 04<br />

Holding registers Write single register 0x06 1 01, 02, 03, 04<br />

Holding registers Write multiple registers 0x10 1–123 01, 02, 03, 04<br />

Holding registers Read/write multiple registers 0x17 1–121 (write) 01, 02, 03, 04<br />

1–125 (read)<br />

Holding registers Mask write register 0x16 1 01, 02, 03, 04<br />

Holding registers Read FIFO queue 0x18 1–32 01, 02, 03, 04<br />

Files Read file record 0x14 01, 02, 03, 04, 08<br />

Files Write file record 0x15 01, 02, 03, 04, 08<br />

© <strong>2011</strong> by Taylor and Francis Group, LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!