G
<pre>
Thanks to Lenore, Curt, & M for the speedy and thorough
replies to my May 12 request for a Modbus overview. Today I
try a technical question.
My company is not a Modbus anything, yet. We have a customer
asking for Modbus functionality and it is my job to
integrate it into an existing product (or prove that
implementing it is so expensive we can't possibly make a
profit).
I have read all 3 Modbus specs and am trying to specify the
maximum size for my Modbus ASCII buffers. I am condensing
what I got from the spec, which confuses me.
An intelligent system can be monitored & controlled by
access to variables I call parameters.
Parameters that can be: | I call:
------------------------+--------------------
Read only | Status parameters
Read and written | Control parameters
Expressed as 1 bit | Binary parameters
Expressed as many bits | Digital parameters
This presents a possible 4 categories of objects, which the
Modbus spec has christened (for reasons known only to it)
as:
| Binary | Digital |
--------+----------------+------------------+
Status | Discrete input | Input register |
--------+----------------+------------------+
Control | Coil | Holding register |
--------+----------------+------------------+
(In a few places, coils are called discrete outputs.)
The protocol permits reading all categories of objects and
writing the control objects. Type of access is determined by
a 1-byte 'function code'. Whereas all read requests can
access multiple objects, write requests distinguish between
'write-single' and 'write-multiple' with separate function
codes. The complete³ breakout of data access function codes
(in hex) is:
| Read | Write |
| Mlt | Sgl | Mlt |
--------+----------------------------+------+-----+-----+
| Binary | Discrete input | 02² | -- | -- |
Status |----------------------------+------+-----+-----+
| Digital | Input register | 04² | -- | -- |
--------+----------------------------+------+-----+-----+
| Binary | Coil | 01² | 05 | 0F¹|
Control |----------------------------+------+-----+-----+
| Digital | Holding register | 03² | 06 | 10¹|
--------+----------------------------+------+-----+-----+
Notes
¹ Variable-length request
² Variable-length response
³ I know I have left out lots of other function codes.
This is a first draft.
Therefore all write-multiple requests, and all responses to
read requests are variable length; while write-single
requests (& responses), read-multiple requests and
write-multiple responses are fixed length.
To size my I/O buffers I need to track down the largest
possible request and response the system will face. The MBAP
gives limits for 4 of the 6 variable length packets:
| ~~ Max objects in ~~
| Response | Request
| to read | for write
| Mlt | Mlt
--------+----------------------------+----------+----------
| Binary | Discrete input | 2000 | --
Status |----------------------------+----------+----------
| Digital | Input register | 125 | --
--------+----------------------------+----------+----------
| Binary | Coil | 2000 | ???
Control |----------------------------+----------+----------
| Digital | Holding register | ??? | 123
--------+----------------------------+----------+----------
But the Conformance Test Specification for Modbus TCP
implies values for all 6:
| ~~ Max objects in ~~
| Response | Request
| to read | for write
| mlt | mlt
--------+----------------------------+----------+----------
| Binary | Discrete input | 2000 | --
Status |----------------------------+----------+----------
| Digital | Input register | 125 | --
--------+----------------------------+----------+----------
| Binary | Coil | 2000 | 1968
Control |----------------------------+----------+----------
| Digital | Holding register | 125 | 123
--------+----------------------------+----------+----------
I don't think my system will have 100 of anything, so I may
be able to reduce this further.
If I divide the bit counts by 8, and multiply the register
counts by 2, I have the maximum number of data bytes in each
ADU category:
| Response | Request
| to read | for write
| mlt | mlt
--------+----------------------------+----------+----------
| Binary | Discrete input | 250 | --
Status |----------------------------+----------+----------
| Digital | Input register | 250 | --
--------+----------------------------+----------+----------
| Binary | Coil | 250 | 246
Control |----------------------------+----------+----------
| Digital | Holding register | 250 | 246
--------+----------------------------+----------+----------
To that I must add (for all ADUs):
- 1 byte of node address,
- 1 byte of function code, &
- 1 byte of LRC
for both write-multiple requests:
- 2 bytes of starting address
- 2 bytes of number of objects
- 1 byte of number of data bytes
and for all 4 read responses:
- 1 byte of number of data bytes
This adds up to:
| Response | Request
| to read | for write
| mlt | mlt
--------+----------------------------+----------+----------
| Binary | Discrete input | 254 | --
Status |----------------------------+----------+----------
| Digital | Input register | 254 | --
--------+----------------------------+----------+----------
| Binary | Coil | 254 | 254
Control |----------------------------+----------+----------
| Digital | Holding register | 254 | 254
--------+----------------------------+----------+----------
So I need 254 bytes in both buffers before ASCII encoding,
and 254 x 2 + 3 (adding ':', '\r', and '\n') = 511 for the
I/O buffers.
If this is correct, would somebody just nod?
If not, could you correct my math?
Thanks.
============================================================
Gary Lynch To send mail change my lynchg@no$pam.com
domain name to stacoenergy
============================================================
</pre>
Thanks to Lenore, Curt, & M for the speedy and thorough
replies to my May 12 request for a Modbus overview. Today I
try a technical question.
My company is not a Modbus anything, yet. We have a customer
asking for Modbus functionality and it is my job to
integrate it into an existing product (or prove that
implementing it is so expensive we can't possibly make a
profit).
I have read all 3 Modbus specs and am trying to specify the
maximum size for my Modbus ASCII buffers. I am condensing
what I got from the spec, which confuses me.
An intelligent system can be monitored & controlled by
access to variables I call parameters.
Parameters that can be: | I call:
------------------------+--------------------
Read only | Status parameters
Read and written | Control parameters
Expressed as 1 bit | Binary parameters
Expressed as many bits | Digital parameters
This presents a possible 4 categories of objects, which the
Modbus spec has christened (for reasons known only to it)
as:
| Binary | Digital |
--------+----------------+------------------+
Status | Discrete input | Input register |
--------+----------------+------------------+
Control | Coil | Holding register |
--------+----------------+------------------+
(In a few places, coils are called discrete outputs.)
The protocol permits reading all categories of objects and
writing the control objects. Type of access is determined by
a 1-byte 'function code'. Whereas all read requests can
access multiple objects, write requests distinguish between
'write-single' and 'write-multiple' with separate function
codes. The complete³ breakout of data access function codes
(in hex) is:
| Read | Write |
| Mlt | Sgl | Mlt |
--------+----------------------------+------+-----+-----+
| Binary | Discrete input | 02² | -- | -- |
Status |----------------------------+------+-----+-----+
| Digital | Input register | 04² | -- | -- |
--------+----------------------------+------+-----+-----+
| Binary | Coil | 01² | 05 | 0F¹|
Control |----------------------------+------+-----+-----+
| Digital | Holding register | 03² | 06 | 10¹|
--------+----------------------------+------+-----+-----+
Notes
¹ Variable-length request
² Variable-length response
³ I know I have left out lots of other function codes.
This is a first draft.
Therefore all write-multiple requests, and all responses to
read requests are variable length; while write-single
requests (& responses), read-multiple requests and
write-multiple responses are fixed length.
To size my I/O buffers I need to track down the largest
possible request and response the system will face. The MBAP
gives limits for 4 of the 6 variable length packets:
| ~~ Max objects in ~~
| Response | Request
| to read | for write
| Mlt | Mlt
--------+----------------------------+----------+----------
| Binary | Discrete input | 2000 | --
Status |----------------------------+----------+----------
| Digital | Input register | 125 | --
--------+----------------------------+----------+----------
| Binary | Coil | 2000 | ???
Control |----------------------------+----------+----------
| Digital | Holding register | ??? | 123
--------+----------------------------+----------+----------
But the Conformance Test Specification for Modbus TCP
implies values for all 6:
| ~~ Max objects in ~~
| Response | Request
| to read | for write
| mlt | mlt
--------+----------------------------+----------+----------
| Binary | Discrete input | 2000 | --
Status |----------------------------+----------+----------
| Digital | Input register | 125 | --
--------+----------------------------+----------+----------
| Binary | Coil | 2000 | 1968
Control |----------------------------+----------+----------
| Digital | Holding register | 125 | 123
--------+----------------------------+----------+----------
I don't think my system will have 100 of anything, so I may
be able to reduce this further.
If I divide the bit counts by 8, and multiply the register
counts by 2, I have the maximum number of data bytes in each
ADU category:
| Response | Request
| to read | for write
| mlt | mlt
--------+----------------------------+----------+----------
| Binary | Discrete input | 250 | --
Status |----------------------------+----------+----------
| Digital | Input register | 250 | --
--------+----------------------------+----------+----------
| Binary | Coil | 250 | 246
Control |----------------------------+----------+----------
| Digital | Holding register | 250 | 246
--------+----------------------------+----------+----------
To that I must add (for all ADUs):
- 1 byte of node address,
- 1 byte of function code, &
- 1 byte of LRC
for both write-multiple requests:
- 2 bytes of starting address
- 2 bytes of number of objects
- 1 byte of number of data bytes
and for all 4 read responses:
- 1 byte of number of data bytes
This adds up to:
| Response | Request
| to read | for write
| mlt | mlt
--------+----------------------------+----------+----------
| Binary | Discrete input | 254 | --
Status |----------------------------+----------+----------
| Digital | Input register | 254 | --
--------+----------------------------+----------+----------
| Binary | Coil | 254 | 254
Control |----------------------------+----------+----------
| Digital | Holding register | 254 | 254
--------+----------------------------+----------+----------
So I need 254 bytes in both buffers before ASCII encoding,
and 254 x 2 + 3 (adding ':', '\r', and '\n') = 511 for the
I/O buffers.
If this is correct, would somebody just nod?
If not, could you correct my math?
Thanks.
============================================================
Gary Lynch To send mail change my lynchg@no$pam.com
domain name to stacoenergy
============================================================
</pre>