Материал: m012900e

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

Common MODBUS functions • 287

Function code FC5 (Write Coil)

6.2.5Function code FC5 (Write Coil)

With the aid of this function a single output bit is written.

Request

The request determines the address of the output bit. Addressing starts with 0. Example: The second output bit is set (address 1):

Byte

Field name

Example

Byte 0, 1

Transaction identifier

0x0000

 

 

 

Byte 2, 3

protocol identifier

0x0000

 

 

 

Byte 4, 5

length field

0x0006

 

 

 

Byte 6

unit identifier

0x01 not used

 

 

 

Byte 7

MODBUS function code

0x05

 

 

 

Byte 8, 9

reference number

0x0001

 

 

 

Byte 10

ON/OFF

0xFF

 

 

 

Byte 11

 

0x00

 

 

 

Response

 

 

Byte

Field name

Example

.....

 

 

 

 

 

Byte 7

MODBUS function code

0x05

 

 

 

Byte 8, 9

Reference number

0x0001

 

 

 

Byte 10

Value

0xFF

 

 

 

Byte 11

 

0x00

 

 

 

Exception

 

 

Byte

Field name

Example

.....

 

 

 

 

 

Byte 7

MODBUS function code

0x85

 

 

 

Byte 8

Exception code

0x01, 0x02 or 0x03

 

 

 

Modular I/O System

ETHERNET TCP/IP

288 • Common MODBUS functions Function code FC6 (Write single register)

6.2.6Function code FC6 (Write single register)

This function writes a value in one single output word (also ”Output register”).

Request

Addressing starts with 0. The inquiry determines the address of the first output word to be set. The value to be set is determined in the inquiry data field.

Example: The second output (address 0) is set to the value 0x1234.

Byte

Field name

Example

Byte 0, 1

Transaction identifier

0x0000

 

 

 

Byte 2, 3

protocol identifier

0x0000

 

 

 

Byte 4, 5

length field

0x0006

 

 

 

Byte 6

Unit identifier

0x01 not used

 

 

 

Byte 7

MODBUS function code

0x06

 

 

 

Byte 8, 9

reference number

0x0001

 

 

 

Byte 10, 11

Register Value

0x1234

 

 

 

Response

The reply is an echo of the inquiry.

Byte

Field name

Example

.....

 

 

 

 

 

Byte 7

MODBUS function code

0x06

 

 

 

Byte 8, 9

Reference number

0x0001

 

 

 

Byte 10, 11

Register Value

0x1234

 

 

 

Exception

 

 

Byte

Feldname

Example

.....

 

 

 

 

 

Byte 7

MODBUS function code

0x85

 

 

 

Byte 8

Exception code

0x01 or 0x02

 

 

 

Modular I/O System

ETHERNET TCP/IP

Common MODBUS functions • 289

Function code FC7 (Read Exception Status)

6.2.7Function code FC7 (Read Exception Status)

This function reads the first 8 bits of the process output image.

Request

 

 

 

 

 

Byte

Field name

Example

Byte 0, 1

Transaction identifier

0x0000

 

 

 

Byte 2, 3

protocol identifier

0x0000

 

 

 

Byte 4, 5

length field

0x0002

 

 

 

Byte 6

unit identifier

0x01 not used

 

 

 

Byte 7

MODBUS function code

0x07

 

 

 

Response

 

 

Byte

Field name

Example

...

 

 

 

 

 

Byte 7

MODBUS function code

0x07

 

 

 

Byte 8

Reference number

0x00

 

 

 

Exception

 

 

Byte

Field name

Example

...

 

 

 

 

 

Byte 7

MODBUS function code

0x85

 

 

 

Byte 8

Exception code

0x01 or 0x02

 

 

 

Modular I/O System

ETHERNET TCP/IP

290 • Common MODBUS functions Function code FC15 (Force Multiple Coils)

6.2.8Function code FC15 (Force Multiple Coils)

Using this function a number of output bits are set to 1 or 0. The maximum number is 256 bits.

Request

The first point is addressed with 0.

The inquiry message specifies the bits to be set. The requested 1 or 0 states are determined by the contents of the inquiry data field.

In this example 16 bits are set, starting with the address 0. The inquiry contains 2 bytes with the value 0xA5F0 or 1010 0101 1111 0000 in binary format.

The first byte transmits the 0xA5 to the addresses 7 to 0, whereby 0 is the lowest value bit. The next byte transmits 0xF0 to the addresses 15 to 8, whereby the lowest value bit is 8.

Byte

Field name

Example

Byte 0, 1

Transaction identifier

0x0000

 

 

 

Byte 2, 3

protocol identifier

0x0000

 

 

 

Byte 4, 5

Length field

0x0009

 

 

 

Byte 6

unit identifier

0x01 not used

 

 

 

Byte 7

MODBUS function code

0x0F

 

 

 

Byte 8, 9

reference number

0x0000

 

 

 

Byte 10, 11

Bit Count

0x0010

 

 

 

Byte 12

Byte Count

0x02

 

 

 

Byte 13

Data Byte1

0xA5

 

 

 

Byte 14

Data Byte2

0xF0

 

 

 

Response

 

 

 

 

 

Byte

Field name

Example

.....

 

 

 

 

 

Byte 7

MODBUS function code

0x0F

 

 

 

Byte 8, 9

Reference number

0x0000

 

 

 

Byte 10, 11

Bit Count

0x0010

 

 

 

Exception

 

 

 

 

 

Byte

Field name

Example

.....

 

 

 

 

 

Byte 7

MODBUS function code

0x8F

 

 

 

Byte 8

Exception code

0x01 or 0x02

 

 

 

Modular I/O System

ETHERNET TCP/IP

Common MODBUS functions • 291

Function code FC16 (Write multiple registers)

6.2.9Function code FC16 (Write multiple registers)

This function writes values in a number of output words (also ”Output register”).

Request

The first point is addressed with 0.

The inquiry message determines the registers to be set. The data is sent as 2 bytes per register.

The example shows how data is set in the two registers 0 and 1:

Byte

Field name

Example

Byte 0, 1

Transaction identifier

0x0000

 

 

 

Byte 2, 3

protocol identifier

0x0000

 

 

 

Byte 4, 5

length field

0x000B

 

 

 

Byte 6

Unit identifier

0x01 not used

 

 

 

Byte 7

MODBUS function code

0x10

 

 

 

Byte 8, 9

reference number

0x0000

 

 

 

Byte 10, 11

Word count

0x0002

 

 

 

Byte 12

Byte Count

0x04

 

 

 

Byte 13, 14

Register Value 1

0x1234

 

 

 

Byte 15, 16

Register Value 2

0x2345

 

 

 

Response

 

 

Byte

Field name

Example

.....

 

 

 

 

 

Byte 7

MODBUS function code

0x10

 

 

 

Byte 8, 9

Reference number

0x0000

 

 

 

Byte 10, 11

Register Value

0x0002

 

 

 

Exception

 

 

Byte

Field name

Example

.....

 

 

 

 

 

Byte 7

MODBUS function code

0x85

 

 

 

Byte 8

Exception code

0x01 or 0x02

 

 

 

Modular I/O System

ETHERNET TCP/IP