<!-- Source: https://medius.k4tech.net/native/connection -->
# Connection & handshake

_Open, find, and handshake_

The handshake confirms the device on the serial port is a Medius box and speaks a protocol version you understand: one request, one reply. Open the port and start talking.

-   No baud negotiation.
-   No login.
-   No `115200` startup step or baud-switch command.

## Handshake

_One round-trip to confirm the box_

1.  Open the serial port at `4,000,000` baud ([Transport](/native/transport.md)). The box speaks [framed binary](/native/frame.md) from the first byte.
2.  Catch the unsolicited hello the box sends on its own ([below](/native/connection.md#hello)), or send a [`QUERY(VERSION)`](/native/commands/requests.md#version) yourself. Both produce the same [`RESP(VERSION)`](/native/commands/requests.md#version) frame.
3.  Read `proto_ver` from that reply and check it equals `3`.

| Reply | Meaning |
| --- | --- |
| `proto_ver == 3` | Speaks the protocol these pages describe. |
| `proto_ver != 3` | Speaks a protocol these pages don't cover; don't assume the commands behave as described. |
| No reply | Not a Medius box, or the port or baud is wrong. |

#### THE REPLY: RESP(VERSION)

The first byte echoes the `what` selector you asked for (the byte that chose which thing to query), then the protocol and firmware version, the box MAC, and the box name follow. Full detail on the [Requests](/native/commands/requests.md#version) page.

| Offset | Field | Type | Notes |
| --- | --- | --- | --- |
| 0 | `what` | `u8` | the selector byte, echoed back; `0x00` = `VERSION` |
| 1 | `proto_ver` | `u8` | protocol version, expected `3` |
| 2 | `fw_major` | `u8` | firmware major |
| 3 | `fw_minor` | `u8` | firmware minor |
| 4 | `fw_patch` | `u8` | firmware patch |
| 5 | `mac` | `u8[6]` | the box MAC, a stable per-box id |
| 11.. | `name` | `ascii` | the box's human-readable name (may be empty), delimited by the frame `LEN` |

## The ready hello

_Unsolicited RESP(VERSION) on link-up_

The box sends one [`RESP(VERSION)`](/native/commands/requests.md#version) on its own as soon as its serial link is up. Treat it as "box is here and ready" and skip your own [`QUERY(VERSION)`](/native/commands/requests.md#version).

| Trigger | When it fires |
| --- | --- |
| Power-on | Once, as the box boots. |
| First contact | On the first valid frame after a program opens the port, so a program that connects after the power-on hello still gets one. |

The hello carries [`SEQ=0`](/native/frame.md#seq) since no request prompted it, and its payload is identical to a queried reply.

> **Note**
>
> The [medius library](/library/connection.md) does all of this inside [`open`](/library/connection.md#open) and [`find`](/library/connection.md#open): it sends [`QUERY(VERSION)`](/native/commands/requests.md#version), retries a few times, and checks `proto_ver == 3` before handing you a working connection.
