@flux-control/effect-modbus-rs
    Preparing search index...

    Function planReads

    • Merges register addresses into the fewest read transactions that cover them.

      The planner sorts and deduplicates the addresses, then extends a span while the next address is within maxGap unrequested registers of the last one and the span stays within maxRegistersPerRead.

      ReadPlan.locate maps each address back to its position, so a caller issues the spans, keeps the responses in order, and reads each value out without tracking the grouping itself.

      Parameters

      • addresses: readonly number[]

        Requested addresses, in any order, duplicates allowed.

      • options: PlanReadsOptions = {}

        Device limits and the gap tolerance.

      Returns ReadPlan

      The spans to read and the index back into their responses.

      RangeError - An address or an option is out of range.

      const plan = planReads([0x0000, 0x0001, 0x0002, 0x0020, 0x0021]);
      plan.spans; // [{ address: 0, quantity: 3 }, { address: 32, quantity: 2 }]
      plan.locate(0x0021); // { span: 1, offset: 1 }
      plan.locate(0x0010); // undefined