Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Small changes to 'length' and 'Discovery' descriptions.
  • Loading branch information
Rossko57 authored Aug 26, 2020
1 parent 49eea6f commit 68ed85b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bundles/org.openhab.binding.modbus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ You must give each of your bridge Things a reference (thing ID) that is unique f
| Parameter | Type | Required | Default if omitted | Description |
| ------------- | ------- | -------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `start` | integer | | `0` | Address of the first register, coil, or discrete input to poll. Input as zero-based index number. |
| `length` | integer || (-) | Number of registers, coils or discrete inputs to read. |
| `length` | integer || (-) | Number of registers, coils or discrete inputs to read. Note that protocol max is 123 |

This comment has been minimized.

Copy link
@ssalonen

ssalonen Aug 27, 2020

Contributor

Wikipedia says that

Because the number of bytes for register values is 8-bit wide and maximum modbus message size is 256 bytes, only 125 registers for Modbus RTU and 123 registers for Modbus TCP can be read at once

Can you confirm if this is the case? Why rtu limit is different than tcp?

This comment has been minimized.

Copy link
@ssalonen

ssalonen Aug 27, 2020

Contributor

Hmm and furthermore modbus spec https://modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf says that when reading coils or discrete inputs the max count is 2000 (!), while with registers it is 125. The spec also says that when writing multiple registers, the max count is 123.

I guess this weird math makes sense, the count is connected to the maximum size (in bytes) of response. I guess that could explain the Wikipedia difference with rtu and tcp as well since the protocol format is slightly different.

Should we validate the count on pollers, and set thing offline if it exceeds above limits?

EDIT: Tested against diagslave and it seems the limits are

  • on read 125 (registers) and 2000 (coils, discrete inputs).
  • on write: 123 (registers) and 1968 (coils, discrete inputs).

Introduced #8370

Same limits for tcp and RTU serial.

READS:

#
# tcp tests against ./diagslave -p 5555
# 
# failing queries: coils, discrete inputs, input registers, holding registers
./modpoll -1 -t 0 -c 2001 127.0.0.1 -p 5555 > /dev/null || echo err
./modpoll -1 -t 1 -c 2001 127.0.0.1 -p 5555 > /dev/null || echo err
./modpoll -1 -t 3 -c 126 127.0.0.1 -p 5555 > /dev/null || echo err
./modpoll -1 -t 4 -c 126 127.0.0.1 -p 5555 > /dev/null || echo err
# all fail with "modpoll: Invalid count parameter! Try -h for help."

# ok queries: coils, discrete inputs, input registers, holding registers
./modpoll -1 -t 0 -c 2000 127.0.0.1 -p 5555 > /dev/null || echo err
./modpoll -1 -t 1 -c 2000 127.0.0.1 -p 5555 > /dev/null || echo err
./modpoll -1 -t 3 -c 125 127.0.0.1 -p 5555 > /dev/null || echo err
./modpoll -1 -t 4 -c 125 127.0.0.1 -p 5555 > /dev/null || echo err

#
# serial tests against /diagslave -m rtu -a 1 -b 38400 -d 8 -s 1 -p none -4 10 /dev/pts/10
# 
# failing queries: coils, discrete inputs, input registers, holding registers
./modpoll -1 -t 0 -c 2001 /dev/pts/11 > /dev/null || echo err
./modpoll -1 -t 1 -c 2001 /dev/pts/11 > /dev/null || echo err
./modpoll -1 -t 3 -c 126 /dev/pts/11 > /dev/null || echo err
./modpoll -1 -t 4 -c 126 /dev/pts/11 > /dev/null || echo err
# all fail with "modpoll: Invalid count parameter! Try -h for help."

# ok queries: coils, discrete inputs, input registers, holding registers
./modpoll -1 -t 0 -c 2000 /dev/pts/11 > /dev/null || echo err
./modpoll -1 -t 1 -c 2000 /dev/pts/11 > /dev/null || echo err
./modpoll -1 -t 3 -c 125 /dev/pts/11 > /dev/null || echo err
./modpoll -1 -t 4 -c 125 /dev/pts/11 > /dev/null || echo err

Further notes: While tcp query works with 125 registers against diagslave it is out-of-spec -- the message size is larger than 256 bytes.

WRITES:

#
# tcp tests against ./diagslave -p 5555
# 
# failing writes: coils, holding registers
./modpoll -1 -t 0 127.0.0.1 -p 5555 $(printf ' 1%.0s' {1..1969})
./modpoll -1 -t 4 127.0.0.1 -p 5555  $(printf ' 1%.0s' {1..124})
# all fail with "Illegal argument error!"

# ok writes: coils, holding registers
./modpoll -1 -t 0 127.0.0.1 -p 5555 $(printf ' 1%.0s' {1..1968})
./modpoll -1 -t 4 127.0.0.1 -p 5555 $(printf ' 1%.0s' {1..123})

#
# serial tests against /diagslave -m rtu -a 1 -b 38400 -d 8 -s 1 -p none -4 10 /dev/pts/10
# 
# failing writes: coils, holding registers
./modpoll -1 -t 0  /dev/pts/11 $(printf ' 1%.0s' {1..1969})
./modpoll -1 -t 4  /dev/pts/11 $(printf ' 1%.0s' {1..124})
# all fail with "modpoll: Invalid count parameter! Try -h for help."

# ok writes: coils, holding registers
./modpoll -1 -t 0  /dev/pts/11 $(printf ' 1%.0s' {1..1968})
./modpoll -1 -t 4  /dev/pts/11 $(printf ' 1%.0s' {1..123})
| `type` | text || (-) | Type of modbus items to poll. This matches directly to Modbus request type or function code (FC). Valid values are: `"coil"` (FC01), `"discrete"` (FC02), `"holding"`(FC03), `"input"` (FC04). |
| `refresh` | integer | | `500` | Poll interval in milliseconds. Use zero to disable automatic polling. |
| `maxTries` | integer | | `3` | Maximum tries when reading. <br /><br />Number of tries when reading data, if some of the reading fail. For single try, enter 1. |
Expand Down Expand Up @@ -310,7 +310,7 @@ Main documentation on `autoupdate` in [Items section of openHAB docs](https://ww
Device specific modbus bindings can take part in the discovery of things, and detect devices automatically. The discovery is initiated by the `tcp` and `serial` bridges when they have `enableDiscovery` setting enabled.
Note that the main binding does not recognize any device, so it is pointless to turn this on unless you have the correct binding installed.
Note that the main binding does not recognize any devices, so it is pointless to turn this on unless you have a suitable add-on binding installed.
## Details
Expand Down

0 comments on commit 68ed85b

Please sign in to comment.