I work at ERDI TECH LTD and answer integration questions about our laser rangefinder modules. One failure mode is easy to miss: the distance is real, the checksum is fine, and it still belongs to the wrong moment. The note we keep for integrators describes it like this: a host sends a measure request to sensor A, the reply arrives late, the host sends the next request to sensor B, and the late frame is attributed to B. Nothing in the log looks broken, because nothing is broken at the frame level. The mistake is in deciding which request a frame answers.
This post walks through the three association rules from our request/response note, shows which of them the 55 AA protocol family can use, and then breaks the simplest rule with a simulation, because the break is the interesting part. All numbers in the simulation are made up to illustrate the mechanism. I have not measured a radio link or an RS-485 converter.
What the 55 AA frame can and cannot tell you
The family-A frame is 8 bytes in both directions:
55 AA FN D1 D2 D3 D4 SUM
The manuals for the LR series and the LRF1200A1 / LRF3000A1 document the header, a function byte, four data bytes and a checksum. They do not document an address field or a sequence number. A single-shot request is 55 AA 88 FF FF FF FF 84, and the reply carries 88 in the function position, so the function byte is echoed. That is the only identifier in the frame.
The checksums differ by direction, which matters when you write the parser. Host to module is (FN + D1 + D2 + D3 + D4) & 0xFF. Module to host is (0x55 + 0xAA + FN + D1 + D2 + D3 + D4) & 0xFF. Distance is big-endian in D3 and D4, in units of 0.1 m, and STA = 1 means success.
So of the three rules:
-
Address in the frame, keyed by
(address, command, sequence). Not available. The function echo gives you the command part only. - Explicit sequence number. Not available.
- One request in flight, and the next valid frame inside the timeout belongs to it. This is the one that applies, and it is also the one that fails quietly.
If you put several modules behind one host, give each its own UART. The documented frame has no way to say which module answered, and our field notes say plainly that a UART is point-to-point.
The timing budget, and what it leaves out
Our note defines the deadline as t_send + 2 × frame_time + margin, with frame time bytes × 10 / baud. For 8 bytes that is 0.694 ms at 115200 baud and 8.33 ms at 9600 baud. That is wire time only. It leaves out how long the module takes to measure, and the documents I have do not give a single-shot latency: the LR1000E2 record lists response time as "on request", and the LRF3000A1 gives a 3 to 10 Hz measurement rate, not a latency. So the timeout is a number you measure. Send a hundred requests on your bench, record t_first_byte - t_send, and set the timeout from the worst case plus margin. The 1.5 times margin I use is my own habit, not a figure from a manual.
Also check the line load before blaming the sensor. At 9600 baud the line carries 960 bytes per second. A round trip is 16 bytes, so the wire alone limits you to 60 round trips per second. A 20 Hz poll uses a third of that: 20 × 16 × 10 = 3,200 bit/s out of 9,600.
Why rule 3 alone is not enough
Rule 3 says anything outside the window is discarded. The trouble is a reply that arrives just after the window closes. The host has timed out on request N and moves on. It sends N+1. Reply N turns up inside the window of N+1, passes every check, and is accepted as the answer to N+1.
On a link that preserves order, that is not a one-off. The real reply to N+1 arrives right behind it, and the next request accepts that one. The host is now one reply behind, and it stays one behind until something forces a timeout.
I built the smallest thing that shows this. A virtual-time serial port delivers replies after a latency that is 40 ms normally and 180 ms for every seventh request, with a 120 ms timeout. Each reply encodes the index of the request that produced it (raw count 1000 + k), so the test can tell whether the host got the right one. Three hosts run 200 requests:
| Host behaviour | Right | Wrong | Timeouts |
|---|---|---|---|
| Naive: keep the buffer, take whatever arrives | 6 | 180 | 14 |
| Rule 3: flush before each send, one in flight | 144 | 28 | 28 |
| Rule 3 plus quarantine after a timeout | 172 | 0 | 28 |
The naive host loses lockstep at the first slow reply and never gets it back: 180 of 200 answers belong to an earlier request. The flush version fixes the cascade but still accepts one stale reply per slow event, 28 in all. Both look healthy in a log, because every frame decodes.
The fix: quarantine after a timeout
After a timeout, do not send the next request yet. Keep reading the line for as long as a late reply could still arrive, count what shows up, discard it, and only then start the next exchange. In the simulation the quarantine is 150 ms, and it catches all 28 late replies. The cost is throughput: every timeout costs you the quarantine time. The benefit is a counter, late, that tells you something your timeout counter cannot: how late the replies actually are. Use that histogram to set the timeout and the quarantine from your own link instead of guessing.
The code
The correlator is the pending-request table from the note, with expiry and counters:
import itertools
class Correlator:
"""Pending requests keyed by (address, command, sequence); None for fields the protocol lacks."""
def __init__(self):
self.pending = {}
self.seq = itertools.count()
self.n = dict(sent=0, matched=0, unmatched=0, expired=0)
def request(self, addr, cmd, now, timeout, use_seq=False):
key = (addr, cmd, next(self.seq) & 0xFF if use_seq else None)
self.pending[key] = now + timeout
self.n["sent"] += 1
return key
def on_frame(self, key):
if key not in self.pending:
self.n["unmatched"] += 1 # late, duplicate or unsolicited
return False
del self.pending[key]
self.n["matched"] += 1
return True
def expire(self, now):
dead = [k for k, t in self.pending.items() if t <= now]
for k in dead:
del self.pending[k]
self.n["expired"] += len(dead)
return dead
For 55 AA the key is (None, 0x88, None), so the table never holds more than one entry. If a protocol with an address or a sequence byte comes your way, the same class works with use_seq=True and a real address. The host class below is what the simulation ran, with its naive and one modes kept so you can compare:
class Host:
"""mode: 'naive' reads whatever arrives; 'one' is rule 3; 'one+q' is rule 3 plus a quarantine after a timeout."""
def __init__(self, port, mode, timeout_s, quarantine_s=0.0):
self.p, self.mode, self.timeout_s, self.q = port, mode, timeout_s, quarantine_s
self.buf = b""
self.c = Correlator()
self.late = 0
self.res = dict(ok=0, wrong=0, timeout=0)
def measure(self, true_k):
p = self.p
if self.mode != "naive":
p.flush(); self.buf = b""
key = self.c.request(None, 0x88, p.t, self.timeout_s)
p.write(single_shot())
end = p.t + self.timeout_s
while p.t < end:
p.t += 0.001
self.buf += p.take()
fr, used = parse(self.buf)
self.buf = self.buf[used:]
if fr and self.c.on_frame((None, fr["fn"], None)):
self.res["ok" if fr["raw"] - 1000 == true_k else "wrong"] += 1
return fr["raw"] - 1000
self.c.expire(p.t); self.res["timeout"] += 1
if self.mode == "one+q": # let the late reply arrive and count it, then start clean
qend = p.t + self.q
while p.t < qend:
p.t += 0.001
self.buf += p.take()
fr, used = parse(self.buf); self.buf = self.buf[used:]
if fr: self.late += 1
self.buf = b""
return None
parse(buf) scans for 55 AA, checks the receive-side checksum, drops bad frames and returns (frame, bytes_consumed); it follows the same idea as the parser in our earlier RS-485 post. p.t is the virtual clock of the simulated port, and p.take() returns the bytes that have arrived by then; on real hardware those are time.monotonic() and a serial read. A return of None means a timeout. In your own code keep the other fault classes separate too: no reply, checksum error and STA not equal to 1 are three different problems. The simulated port (about 25 lines) is not pasted here.
What I ran
All of this runs as a Python script with assertions, against the virtual-time port, with no hardware:
- The single-shot request is
55 aa 88 ff ff ff ff 84. - A reply built with the receive formula parses (raw count 1234); one built with the transmit formula is rejected; two noise bytes in front of a good frame are skipped.
- The correlator accepts a pending key once and reports a second use as unmatched; an entry past its deadline expires and is counted; two sequence-numbered requests get different keys.
- Frame times come out at 0.694 ms (115200 baud) and 8.33 ms (9600 baud).
- With a constant 40 ms latency, all three hosts get 50 of 50 right.
- With the slow-reply schedule above, the table's counts: naive 6 right, 180 wrong, 14 timeouts; flush 144, 28, 28; quarantine 172, 0, 28 with 28 late replies counted.
Not tested: real hardware, a real converter, or a link that reorders bytes. I only modelled in-order delivery. Continuous ranging is left out on purpose: for the LRF1200A1 and LRF3000A1 the manual's request function byte (89) and reply function byte (88) differ, our documents mark it as an open protocol question, and this keying would have to change if it were resolved.
Where to look next
- Our request/response association note: https://erdilrf.com/knowledge/laser-rangefinder-request-response-association/?utm_source=devto&utm_medium=post&utm_campaign=devto-request-response-202611
- UART TTL integration guide: https://erdilrf.com/knowledge/uart-ttl-integration-guide-lrf-modules/?utm_source=devto&utm_medium=post&utm_campaign=devto-request-response-202611
- Protocol notes and MIT-licensed drivers: https://github.com/ErdiTech/erdi-lrf-drivers
If you have a link that misattributes replies, send the model name and a timestamped raw capture of 20 or more frames to tommy@erdimail.com. Timing problems show up in the timestamps, not in a decoded plot.
Disclosure: I am Tommy Yu, an engineer at ERDI TECH LTD (erdilrf.com), the manufacturer of the modules discussed. Data checked against our protocol documents and model records on 2026-11-18.
Top comments (0)