Virtual CAN bus. Send CAN messages over a virtual can bus.
A virtual can bus can be useful during development of a CAN based system.
To start the virtual CAN server, use the rust implementation:
$ cd rust/server
$ cargo run --release -- --port 18881
To use this from python, install the python-can package, and next the virtualcan module:
$ pip install python-can
$ cd python
$ pip install .
Now, from python, use the virtualcan interface as follows:
import can
bus = can.Bus(interface='virtualcan', channel='localhost:18881')
bus.send(can.Message(arbitration_id=13, data=[1, 2, 3, 4, 5]))
Refer to the C++ demo.
To build the C++ demo, use cmake:
$ cd cpp
$ mkdir build
$ cd build
$ cmake ..
$ make
$ cd demo
$ virtualcan_demo.exe
- C++ implementation of TCP client
- Rust implementation of TCP client/server
- C# implementation of TCP client
The zero-m-can server listens to port 5555 (req-rep) and port 5556 (pub-sub). Messages are encoded as msgpack data.
API:
- get_version() -> int
- get the version of this protocol. Current version: 1
- new_client() -> str
- Create a new client name. Returns the client name.
- send_message(client: str, id: int, extended: bool, data: list[int]) -> int
- Send a message on the bus for the given client. Given are an id, extended marker and data.