|
| 1 | +# can-waveshare |
| 2 | + |
| 3 | +**python-can** backend for the **Waveshare 2-CH-CAN-TO-ETH** bridge that uses a fixed **13‑byte** TCP wire format. |
| 4 | +Works with `python -m can.viewer/logger/player` and plain `can.Bus(...)`. |
| 5 | + |
| 6 | +> Transport: TCP server on the device (e.g., `:20001` for CAN1, `:20002` for CAN2). |
| 7 | +> Frames: 13 bytes: `[flags/dlc][id:4][data:0..8 padded]` |
| 8 | +
|
| 9 | +## Install |
| 10 | + |
| 11 | +```bash |
| 12 | +pip install can-waveshare |
| 13 | +# or from source (editable): |
| 14 | +pip install -e .[dev] |
| 15 | +``` |
| 16 | + |
| 17 | +## Use with CLI |
| 18 | + |
| 19 | +```bash |
| 20 | +# Most portable: pass channel as host:port |
| 21 | +python -m can.viewer -i waveshare -c 172.31.11.67:20001 |
| 22 | + |
| 23 | +# Or forward kwargs directly to the bus: |
| 24 | +python -m can.viewer -i waveshare --bus-kwargs host=172.31.11.67 port=20001 |
| 25 | +``` |
| 26 | + |
| 27 | +### Config via `~/.canrc` |
| 28 | + |
| 29 | +The stock CLIs read only the **[default]** section. Put this in `~/.canrc`: |
| 30 | + |
| 31 | +```ini |
| 32 | +[default] |
| 33 | +interface = waveshare |
| 34 | +channel = 172.31.11.67:20001 |
| 35 | +``` |
| 36 | + |
| 37 | +Then: |
| 38 | + |
| 39 | +```bash |
| 40 | +python -m can.viewer |
| 41 | +``` |
| 42 | + |
| 43 | +If you want multiple profiles, either (a) swap rc files or (b) write a tiny launcher in code and use `Bus(config_context="waveshare2")` to select other sections. |
| 44 | + |
| 45 | +## Use in code |
| 46 | + |
| 47 | +```python |
| 48 | +import can |
| 49 | + |
| 50 | +# explicit kwargs: |
| 51 | +with can.Bus(interface="waveshare", host="172.31.11.67", port=20001) as bus: |
| 52 | + bus.send(can.Message(arbitration_id=0x123, data=b"\x11\x22\x33", is_extended_id=False)) |
| 53 | + print(bus.recv(1.0)) |
| 54 | + |
| 55 | +# or via channel (parses host:port, tcp://host:port, [ipv6]:port, or aliases can1/can2): |
| 56 | +with can.Bus(interface="waveshare", channel="172.31.11.67:20001") as bus: |
| 57 | + print(bus.recv(1.0)) |
| 58 | +``` |
| 59 | + |
| 60 | +## Features & Notes |
| 61 | + |
| 62 | +- CAN 2.0 (0..8 data bytes). **CAN‑FD not supported** by Waveshare wire format. |
| 63 | +- Software filters (`can_filters`) supported in the backend. |
| 64 | +- Best‑effort own‑echo suppression when `receive_own_messages=False` (default). Set `True` to see echoes. |
| 65 | +- Periodic TX via `bus.send_periodic(...)` works (python-can broadcast manager calls `send()` repeatedly). |
| 66 | + |
| 67 | +## License |
| 68 | + |
| 69 | +MIT |
0 commit comments