Skip to content

[BUG] Modbus Connector (Modbus TCP) - Extracting a specific bit from a Holding Register (FC3) #2101

@BARRINYs

Description

@BARRINYs

Connector name (If bug in some connector):
Modbus Connector (Modbus TCP)


Describe the bug
We are using ThingsBoard Gateway (Modbus TCP) and believe there is a bug or limitation when extracting a specific bit from a Holding Register (FC3) using the Bytes Modbus uplink converter.

Scenario:

  • FC3 (Holding Registers), address: 228 (40229)
  • We want to read a specific bit N from that register

Example JSON configuration:

{
  "tag": "Daylight",
  "type": "bits",
  "address": 228,
  "objectsCount": 1,
  "functionCode": 3,
  "bit": 8,
  "bitTargetType": "bool"
}

Issue:
When objectsCount is set to 1, specifying bit values 0–15 does not select the expected bit.

In our tests (creating b0..b15), multiple bits return the same value (sometimes all 1 or all 0), even though the raw register value changes (e.g., 25729 / 9345).

Observation:
If we set objectsCount to 16, the returned bits appear correct and variable, but the gateway reads 16 registers (Reading 16 registers...), which is not desired — we only want the 16 bits of a single register.

Suspected cause:
In bytes_modbus_uplink.py (decode_from_registers()), for type: bits with objectsCount == 1, only 1 bit is kept in the decoded list, so any bit ≥ 1 ends up selecting the same index.

Request:
Is there a supported way to extract a specific bit (bit N) of a single holding register via configuration (FC3/FC4) without reading 16 registers?

If not, could this be fixed so that objectsCount: 1 + bit: N works as expected, for example by extracting the bit from the 16-bit register value?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions