HandshakeOne round-trip

  1. Open the port at 6,000,000 baud (Transport); framed binary from the first byte.
  2. Catch the unsolicited hello (below) or send QUERY(VERSION); both produce the same RESP(VERSION) frame.
  3. Check that reply's proto_ver is 9.
ReplyMeaning
proto_ver == 9Speaks the protocol these pages describe.
proto_ver != 9Speaks a protocol these pages don't cover; commands may behave otherwise.
No replyNot a Medius box, or wrong port or baud.

The check is mandatory. Firmware 3.1.x and earlier report 4. In proto 4, LOCK's last byte is a state (1 = lock, 0 = unlock), not a scale.

a proto-9 host talking to a proto-4 box

  scale = 100  (unlock)  ->  state = 100, non-zero  ->  LOCKS it
  scale =   0  (block)   ->  state = 0              ->  UNLOCKS it
RESP(VERSION)
OffsetFieldTypeNotes
0whatu8selector, echoed; 0x00 = VERSION
1proto_veru8protocol version, expected 9
2fw_majoru8firmware major
3fw_minoru8firmware minor
4fw_patchu8firmware patch
5macu8[6]box MAC, a stable per-box id
11..nameasciihuman-readable box name (may be empty), delimited by the frame LEN

Ready helloUnsolicited RESP(VERSION), twice per boot

Treat either hello as ready and skip the QUERY(VERSION).

TriggerWhen
Power-onOnce, as the device chip boots, before any other frame.
First contactOnce, on the first valid frame after boot, before that frame's reply. If another program has already sent a frame, a program opening the port gets neither hello and sends QUERY(VERSION).
  device chip boots         -->  hello, SEQ 0
  first valid frame         -->  hello, SEQ 0, then that frame's reply
  every later frame         -->  no hello
  device chip restarts      -->  hello at boot, and again on the next frame

The hello carries SEQ=0 and the same payload as a queried reply. A hello mid-session means the device chip restarted and lost its session state, such as locks and rewrite rules.

The medius library's open and find do all of this: send QUERY(VERSION) up to 5 times, waiting 250 ms for each reply, and check proto_ver == 9 before returning a connection.