Skip to content

2.6 Protocol Presentation Layer Utility

OpenClaw edited this page May 25, 2026 · 4 revisions

Protocol Presentation Layer is the first API that Modbus.Net could use, it can directly communicate to addresses of devices thinking with protocol, and it can be second encapsulated to specific APIs.

Implementation

Utility has two parts, property named IUtilityProperty and method groups named IUtilityMethod.

IUtilityProperty has an AddressTranslator, translate string address into AddressDef, which include several number and string definitions of an address.
AddressTranslator can be replaced in any time.

IutilityProperty also has an Endian system, included little endian, big endian and big endian with most significant bit, which defines the storaging patterns. IUtilityProperty.

IUtilityMethod is the interface of utility method group, which defines a group of low level API methods.These methods need to inherit from IUtilityMethod interface and defines its interface, then be implemented Utility class(BaseUtility is an example in Modbus.Net, which implement IUtiltiyData).

User will only be shown IUtilityProperty in interface, but they can call method in IUtilityMethod by invoke GetUtilityMethods in IUtilityProperty.

classDiagram
    class IUtilityProperty {
        <<interface>>
        +AddressTranslator: AddressTranslator
        +Endian: Endian
    }
    class IUtilityMethod {
        <<interface>>
    }
    class IUtilityMethodData {
        <<interface>>
        +GetDatasAsync(startAddress, count, originalCount)
        +SetDatasAsync(startAddress, contents, originalCount)
    }
    class BaseUtility~TParamIn,TParamOut,TProtocolUnit,TPipeUnit~ {
        +AddressTranslator
        +Endian
        +Wrapper: IProtocol
        +GetDatasAsync()
        +SetDatasAsync()
    }
    IUtilityProperty <|.. BaseUtility
    IUtilityMethod <|.. IUtilityMethodData
    IUtilityMethodData <|.. BaseUtility
    BaseUtility --> IProtocol : Wraps
Loading

Interface

BaseUtility implement IUtilityProperty and IUtilityMethodData. IUtilityMethodData included a group of GetDatas(Async) and SetDatas(Async). If you write a class inherit from BaseUtility, just implement two abstract methods, others are already implemented.

public abstract Task<byte[]> GetDatasAsync(string startAddress, int getByteCount);

public abstract Task<bool> SetDatasAsync(string startAddress, object[] setContents);

IUtilityProperty will explore the address or address range when IMachineMethod send message to it, then send correct message or some messages to IProtocol.

sequenceDiagram
    participant M as IMachineMethod
    participant UP as IUtilityProperty
    participant UM as IUtilityMethodData
    participant P as IProtocol
    M->>UP: Resolve address
    UP-->>M: AddressDef
    M->>UM: GetDatasAsync/SetDatasAsync
    UM->>P: SendReceiveAsync
    P-->>UM: response
    UM-->>M: ReturnStruct
Loading

Home

中文

English

Clone this wiki locally