Modbus coils
Coils are single-bit values that a master can read and write. Use them for switches, relays, run and stop commands and alarm resets.
What a coil is
A coil holds one bit: on or off. The reference notation writes coils as 0xxxx, so 00001 is the first coil, sent on the wire as address 0. Coils are separate from holding registers: address 0 of the coils and address 0 of the holding registers are different values.
Reading coils: function 01
Function 01 (0x01) reads a block of coils. One request can read at most 2000 coils (0x07D0). The answer packs the bits into bytes, least significant bit first: the first coil is bit 0 of the first data byte. Unused bits in the last byte are zero.
Writing coils: functions 05 and 15
- Function 05 (0x05) writes one coil. The value is FF 00 for on and 00 00 for off. Other values are not valid.
- Function 15 (0x0F) writes several coils. One request can write at most 1968 coils (0x07B0).
Discrete inputs are read-only coils
Discrete inputs (1xxxx) use the same bit layout as coils but a master can only read them, with function 02. A device sensor or limit switch usually appears there, while a command to the device usually sits in a coil.
Common problems
- Exception 02 on a coil read: the address or the block end is outside the coils the device has. Coils and holding registers can have different ranges.
- The coil writes, but the device does not react: some devices lock coils while in a certain mode, or expect the write to go to a different unit ID.
- The bits look shifted: the first coil is the lowest bit of the first byte, not the highest. Check the bit order before blaming the device.
Test it in Busscope
Poll a coil block in a Busscope Master window and set the display format to binary to see each bit. The Modbus TCP tester page shows how to write a single coil and confirm the answer.
Try Busscope
Install Busscope and run it without a license key to see whether it fits your work. Evaluation mode is for trying the tool, not for production or commercial use.