Skip to content

Option to strip the TX echo on half-duplex sensors #5

@clausbroch

Description

@clausbroch

IEC 62056-21 optical probes (such as the Smart Gateways USB-C probe) are half-duplex and echo back transmitted bytes on the RX line. PyKMP does not account for this — it reads until the first stop byte (0x0D), which matches the end of the echoed request, and never sees the actual response.

A fix is to read and discard the echo bytes (matching the length of the sent request) before reading the response.

Edit the PyKMP client source (client.py).
Find the send_request method (around line 140) and locate these two lines:

        self.write(request_physical_bytes)
        response_physical_bytes = self.read()

Add a line between them to consume the echo:

        self.write(request_physical_bytes)
        # Strip TX echo from optical probes that echo back sent bytes.
        self.read(num_bytes=len(request_physical_bytes))
        response_physical_bytes = self.read()

Save the file and test:

pykmp-tool -vv get-serial
The "Received bytes" line should now start with 40 (response from meter) instead of 80 (echo of request).

This should of course not be implemented as the default, but instead as an option, e.g. --strip-tx-echo.
I would like to hear opinions about this approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions