# `EtherCAT.Transport`
[🔗](https://github.com/tallakt/yaethercat/blob/v0.1.0/lib/ethercat/transport.ex#L1)

How EtherCAT frames get to the SubDevices and back: the behaviour of a transport, which an
`EtherCAT.MainDevice` opens and owns.

  * `EtherCAT.Transport.Packet`, raw Ethernet on Linux, through OTP's `:socket`
  * `EtherCAT.Transport.BPF`, raw Ethernet on macOS, through a small program of its own
  * `EtherCAT.Transport.UDP`, EtherCAT frames in UDP datagrams to port 0x88A4, as the spec allows

A transport takes and gives EtherCAT frames, from their header of two bytes on; the Ethernet or
UDP around them is its own business. What it receives comes to the process that opened it as
messages, which that process hands to `c:handle/2`.

# `t`

```elixir
@type t() :: term()
```

A transport's own state.

# `close`

```elixir
@callback close(t()) :: :ok
```

Closes the transport.

# `handle`

```elixir
@callback handle(t(), term()) :: {:ok, [binary()], t()} | {:error, term()} | :ignore
```

Takes a message the process received: the EtherCAT frames it brought, none or more, with the
transport's state; an error when the transport is gone; or `:ignore` for a message that isn't the
transport's.

# `open`

```elixir
@callback open(keyword()) :: {:ok, t()} | {:error, term()}
```

Opens the transport, in the process that will receive its frames.

# `send`

```elixir
@callback send(t(), binary()) :: :ok | {:error, term()}
```

Sends an EtherCAT frame.

# `raw`

```elixir
@spec raw() :: module()
```

The transport for an interface on this operating system: `EtherCAT.Transport.Packet` on Linux and
`EtherCAT.Transport.BPF` on macOS.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
