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

    Interface RegisterCache

    A belief about the contents of the registers on a bus.

    The key is the unit and the address together, so one cache serves every device on a transport. That is deliberate: the cache is a belief about a physical device, and there is one physical device. Two caches on one unit disagree, and the one that is wrong suppresses a write that the device needed.

    The cache is not a read cache. It records only what this process wrote, so it never answers a read and never claims to know a register nobody has written.

    interface RegisterCache {
        size: number;
        filter(
            unitId: number,
            writes: readonly RegisterWrite[],
        ): RegisterCacheFilter;
        generationOf(unitId: number): number;
        invalidate(unitId?: number): void;
        observe(
            unitId: number,
            address: number,
            value: number,
            generation?: number,
        ): void;
    }
    Index
    size: number

    Registers the cache currently holds a value for. Intended for tests.

    • Splits proposed writes into the ones that change something and the ones that do not.

      When an address appears more than once, the last write wins, which is the same rule planWrites applies. The earlier proposals are reported as suppressed, so the counts still add up to the number of proposals.

      Parameters

      • unitId: number

        Unit the writes are addressed to.

      • writes: readonly RegisterWrite[]

        Proposed writes.

      Returns RegisterCacheFilter

      The writes to issue, and the ones the cache removed.

      RangeError - An address or a value is out of range.

    • How many times what this cache believes about a unit has been discarded.

      Read it before issuing a write and hand it back to observe. The number changes when the unit is invalidated, so an observation that was already in flight can tell that it is describing a device nobody knows anything about any more.

      Parameters

      • unitId: number

      Returns number

    • Forgets what a unit holds, or what every unit holds when unitId is omitted.

      A failed transaction and a reconnect both mean the state of the device is unknown: it may have power-cycled and reset its outputs. A stale belief then suppresses exactly the write that would restore it.

      Parameters

      • OptionalunitId: number

      Returns void

    • Records that a register now holds a value.

      Call this only after the device acknowledged the write. A value recorded before the acknowledgement suppresses the retry that would have fixed it.

      Pass the generation read before the write was issued. An invalidation that lands while a write is on the wire has to win: the write may be the last one the device took before it power-cycled, and re-recording it afterwards would suppress exactly the write that restores the register. Omitting generation records unconditionally.

      Parameters

      • unitId: number
      • address: number
      • value: number
      • Optionalgeneration: number

      Returns void