Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Modbus
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Function code 01 (read coils) as an example of public function code ==== Function code 01 (read coils) allows reading the state from 1 to 2000 coils of a remote device. mb_req_pdu (request PDU) will then have 2 bytes to indicate the address of the first coil to read (from 0x0000 to 0xFFFF), and 2 bytes to indicate the number of coils to read. mb_req_pdu defines coil address by index 0, i.e the first coil has address 0x0. On a successful execution, mb_rsp_pdu will return one byte to note the function code (0x01), followed by one byte to indicate the number of data bytes it is returning (n), which will be the number of coils requested by mb_req_pdu, divided by 8 bits per byte, and rounded up. The remainder of the response will be the specified number (n) of data bytes.{{Sfn|MODBUS Application Protocol|2012|p=11|ps=}} That is, the mb_req_pdu and mb_rsp_pdu of function code 01 will take the following form:{{Sfn|MODBUS Application Protocol|2012|p=11|ps=}} :mb_req_pdu: :* Function code: 0x01 (1 byte) :* Starting Address (1st coil address to read): From 0x0000 to 0xFFFF (2 bytes) :* Quantity of coils to read: Range from 1 to 2000 (0x7D0) (2 bytes) :mb_rsp_pdu: :* Function code: 0x01 (1 byte) :* Byte count: 1 byte (n=quantity of coils/8, rounded up) :* Coil Status: n bytes For instance, mb_req_pdu and mb_rsp_pdu to read coils status from 20-38 will be:{{Sfn|MODBUS Application Protocol|2012|p=12|ps=, "6.1 01 (0x01) Read Coils"}} :mb_req_pdu: :* Function code: 0x01 :* Starting Address High byte: 0x00 :* Starting Address Low byte: 0x13 :* Quantity of Outputs High byte: 0x00 :* Quantity of Outputs Low byte: 0x13 ::Starting Address (2 bytes) is 0x0013, (or 19 in decimal) which is the 20th coil. ::Quantity of Outputs (2 bytes) is 0x0013, (or 19 in decimal) which corresponds to 19 values of status of coils 20th to 38th. :mb_rsp_pdu: :* Function code: 0x01 :* Byte Count: 0x03 :* Outputs status 27-20: 0xCD :* Outputs status 35-28: 0x6B :* Outputs status 38-36: 0x05 ::As 19 coils (20-38) are required, 3 bytes is used to indicate the coil's state. So that Byte Count is 0x03. States of coil from 20 to 27 is 0xCD, which is 1100 1101 in binary. So coil 27 is MSb, and coil 20 is LSb. Same for coil 28 to 35. With coil from 36 to 38, the state will be 0x05, which is 0000 0101. Coil 38 state is the 3rd bit (count from the right), i.e 1, coil 37 is 0, and coil 36 state is LSb bit, i.e. 1. 5 left bits are all 0.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)