# Communication Link (`commLink`)

> Carries up to four values from one controller to another with the timing of a bus: a rate, a latency, a seeded jitter and a seeded loss.

![commLink](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/img/commLink.svg)

[Component reference](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/) · [繁體中文](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/control/commLink/)

**Group:** Control · **Kind:** `{"block":"commLink","kind":"control"}`

## When to use it

Use it where a supervisor talks to a converter over PMBus, CAN or a UART: a set point that arrives late, a status report that takes some milliseconds, a message that is lost. It models only the timing, not a protocol stack: no addressing, arbitration, checksums or retries.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `in1` | signal | First value of the message |
| `in2` | signal | Second value (sent when width is 2 or more) |
| `in3` | signal | Third value (sent when width is 3 or more) |
| `in4` | signal | Fourth value (sent when width is 4) |
| `out1` | signal | First value of the last message delivered, held |
| `out2` | signal | Second value delivered |
| `out3` | signal | Third value delivered |
| `out4` | signal | Fourth value delivered |
| `fresh` | signal | 1 for pulse seconds after each arrival, else 0 |
| `lost` | signal | Messages lost so far |

## Common parameters

- `rate`: Messages per second, sent at t = k/rate; 0 sends a message whenever an input moves past deadband (Default: 1k)
- `latency`: Fixed delay from sending to arrival (Default: 1m)
- `jitter`: Most extra delay per message, drawn from 0 to jitter with the seed; every message arrives within latency + jitter (Default: 0)
- `loss`: Probability that a message is lost, 0 to 1, drawn with the seed; the lost output counts them (Default: 0)
- `width`: Values per message, 1 to 4: inputs in1 … in<width>, outputs out1 … out<width> (Default: 1)

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `rate` | Hz | 1k |  | Messages per second, sent at t = k/rate; 0 sends a message whenever an input moves past deadband |
| `latency` | s | 1m |  | Fixed delay from sending to arrival |
| `jitter` | s | 0 |  | Most extra delay per message, drawn from 0 to jitter with the seed; every message arrives within latency + jitter |
| `loss` | — | 0 |  | Probability that a message is lost, 0 to 1, drawn with the seed; the lost output counts them |
| `width` | — | 1 |  | Values per message, 1 to 4: inputs in1 … in<width>, outputs out1 … out<width> |
| `seed` | — | 1 |  | Number that picks the jitter and loss pattern; the same seed gives the same run |
| `deadband` | — | 0 |  | Send on change only: how far an input must move from the last message before a new one is sent |
| `y0` | — | 0 |  | Outputs until the first message arrives |
| `pulse` | s | 100u |  | How long fresh stays 1 after each arrival; keep it above maxStep to see it in a fixed-step recording |

_Parameter descriptions are in English in both languages._

## Model

With rate above 0 the sender reads in1 … in<width> at t = k/rate from t = 0; with rate 0 it sends whenever an input moves more than deadband from the last message sent. Each message is lost with the probability loss and counted on lost when it is sent. Otherwise it arrives latency + jitter·u after it was sent, u uniform from 0 to 1, and never before the message ahead of it, so the bus keeps the order and every message arrives within latency + jitter. The outputs hold the last message delivered, y0 before the first, and fresh is 1 for pulse seconds from each arrival. The draws depend only on seed and the message number, so the same seed gives the same jitter and losses in every run and in both solvers. Send instants, arrivals and the ends of the pulses are events, so the solver lands on them. A message sent while 4096 are on the way is dropped and counted as lost.

## Common mistakes

- With rate 0 and a continuous input, every solver step sends a message. Give deadband a value, or use a rate, so the bus carries what a real one would.
- A fixed-step recording keeps only the grid points, so a pulse shorter than maxStep can fall between them. Keep pulse above maxStep, and below the time between messages, or fresh stays at 1.
- Code generation leaves this block out as simulation-only. On the target the bus driver carries the message, so generate each side on its own.

## Datasheet and sources

There is no datasheet. Typical numbers, worked out from the bit rates and not taken from a standard: PMBus at 100 kHz needs about 0.5 ms for a word read or write and a host polls at 10 to 100 Hz (rate 10 to 100, latency 0.5m, jitter up to 1m). CAN at 500 kbit/s sends an 8-byte frame in about 0.27 ms and a lower-priority frame waits for the ones ahead (latency 0.3m, jitter 0.3m to 1m). A UART at 115200 baud takes 87 µs per byte, about 0.7 ms for 8 bytes (latency 0.7m). loss stands for a message the application never gets, after any retries the bus makes.

## Example

Open the example with the command `file.openExample` and the name `demo:commLink`.

---
Generated by `cargo xtask reference` from the usage texts and parameter specs. Do not edit by hand.
