1) What is the main differences between Holding and Input register? apart from their addresses, 3xxxx and 4xxxx
2) What is the main differences between Modbus code between 3 and 4?
You can't write to input registers - they are designated as Anlog Inputs. Holding Registers are addressed for Analog Outputs so are read and write
The biggest difference between the 3X and 4x is that 3x are read-only. They are primarily analog inputs whereas the holding registers are used for much more. The 3x registers are also limited to one word where two 4x registers can be put together to hold a double integer or floating point value.
Modbus code 4 only reads input registers and code 3 only reads holding registers. When you use these codes, you don't use the leading 3 or 4 in the register. You only specify the offset for the first register in the range you want to read. The code itself implies if it is a 3x or 4x register.
3xxx address can only be used for input whereas 4xxx address can be used for output and also for memory purpose. That's the main differences as I know.
Command 3 is to read 4x registers, and command 4 for 3x registers. A lot of PLC's can only poll using command 3 to access 4x registers.
Holding registers are read/write.
Input registers are read only. Values are generated by the device.
Function 3 reads holding registers, function 4 reads input registers.
Think of it as two pages of memory so that input data and holding data can be addressed up to 65536. Input registers are usually "inputs to the system" whereas the holding registers are outputs that are held by the system. I usually ignore them and just map both input/holding to the same address and it can be read with either function.
You've heard lots of "read-only" is the answer, so I'll give a more colorful, opinionated answer.
Unless you're creating a Master to poll unknown 3rd party products & have to support function 4, the 3x "Input Status registers" are obsolete. Some important embedded systems (like Modicon's I/O Scanner) *CANNOT* issue the function 4 command required to read them. Plus, when was the last time anyone really saw a raw Analog Input on a PLC that wasn't scaled & conditioned into 4x memory anyway?
If you are designing a new product, trying to separate your data into 3x and 4x tables will create marketing & field support problems. Defining some 3x data is Ok, but make sure it is also available using function 3 reads to 4x space. Writes to these mirrored 4x registers would of course fail.
- Lynn A Linse, www.digi.com