Modbus Function Code 5

Good Morning,

I am new to Modbus.
I have a question about how "Read and Write Discrete Outputs" works.
When Writing coils, does the register number refer to a 16-bit register, or does it refer to a specific bit?
For example, if I wanted to write the coil at register #7 - does this mean that I set the 7th 16-bit register to 1 or do I set the 7th bit in byte 1?

If you haven't looked at it already, take a look at the Modbus spec here (section 6.5 details Function Code 5 Write Single Coil):

From that section, "The Request PDU specifies the address of the coil to be forced."

Therefore, when writing coils the address refers to a specific coil.

Ok, getting the obvious out of the way, here's some additional details that may help you understand better.

In Modbus there are 4 different types of data:
Holding Registers - Read/Write 16-bit integers
Input Registers - Read-only 16-bit integers
Coils - Read/Write ON/OFF values
Discrete Inputs - Read-only ON/OFF values

Modbus uses different function codes for reading and writing the above types. A Modbus server/slave device may expose data using any/all of the above types. For example, this is what the register list may look like for a theoretical, overly-simplified variable frequency drive (VFD). Note that the numbers used are arbitrarily chosen.

Holding Register 1 - Frequency Command
Holding Register 2 - Acceleration Time
Holding Register 3 - Deceleration Time
Input Register 1 - Running Frequency
Coil 1 - Run/Stop Command
Coil 2 - Forward/Reverse Direction
Discrete Input 1 - Running Status
Discrete Input 2 - Running Direction
Discrete Input 3 - Fault Status

From a Modbus perspective, if a client/master wants to command this theoretical VFD to run, it would send a Function Code 5 request to the VFD to write Coil 1 - Run/Stop Command to ON.

Now internally on the VFD, Coil 1 - Run/Stop Command and Coil 2 - Forward/Reverse Direction may both be mapped to individual bits of a single 16-bit control word. However, the Modbus client/master does not need to know, nor does it care, how each coil is implemented in the VFD.