VT Anywhere supports several different CAN adapters. Currently the following CAN adapters are available:
Peak USB Adapter
UDP Adapter
SocketCAN (Linux Only)
By default, VT Anywhere is configured to use the Peak CAN USB adapter. If you would like to use a different adapter, the command line option will need to be changed if using the server only application or the Adapter setting in the application must be changed.
Windows: Edit the batch file and change the following line:
start vt-anywhere.exe --pcan
to start vt-anywhere.exe --udp
Linux: While calling the the program from the command line, change:
./vt-anywhere --socketcan <your-can-adapter-interface>
to ./vt-anywhere --udp
VT Anywhere comes packaged with the necessary dlls for PCAN on Windows.
Part of the Linux mainline kernel, classic CAN since 3.2 (peak_pci), CAN FD since 4.0 (peak_usb). PCAN devices will work via SocketCAN.
Steps to get PCAN USB device working were taken from the python-can documentation.
sudo modprobe peak_usb
Check that kernal module is loaded: lsmod | grep ^peak
sudo ip link set can0 up type can bitrate 250000 restart-ms 10
Connect to VT Anywhere via --socketcan adapter
Selecting the CAN interface using SocketCAN on Linux can be done via the terminal:
./vt-anywhere --socketcan <your-can-adapter-interface>
e.g. ./vt-anywhere --socketcan can1
The UDP adapter is intended to provide inter-process communication between a client and server on the same PC. To use this adapter, configure VT Anywhere to use it as outlined above and set your client up to communicate over UDP.
The protocol is very simple, so updating a client to use the UDP adapter should not be difficult. The basics here are:
Use UDP Multicast
Use multicast address 239.0.0.222
Use port 25000
The message format is:
Header
DLC
8 byte data array
Here's some sample code for constructing a message to send over UDP:
char msg[32] = { 0x00 };
msg[0] = (uint8_t)((packet->Header.Identifier & 0xFF000000) >> 24);
msg[1] = (uint8_t)((packet->Header.Identifier & 0x00FF0000) >> 16);
msg[2] = (uint8_t)((packet->Header.Identifier & 0x0000FF00) >> 8);
msg[3] = (uint8_t)((packet->Header.Identifier & 0x000000FF));
msg[4] = (uint8_t)packet->DLC;
for (i = 0; i < packet->DLC; i++) {
msg[5 + i] = packet->Data[i];
}
To read incoming messages, just listen to the multicast socket and act accordingly.
If developing an ISOBUS client application, it can be convenient to not require a hardware display on your desk. To enable this, we have put together a simple virtual CAN bus that uses UDP multicast to communicate with applications on the same PC. UDP multicast was chosen since it is a connection-less protocol, the same as CAN.
To connect to the bus, use the following multicast parameters:
Multicast address: 239.0.0.222
Port: 25000
The message format is very simple, and mirrors what would be seen on a physical CAN bus:
--------------------------------------
Byte: 0-3
Field: Header
Byte: 4
Field: DLC
Byte: 5-12
Field: Data
--------------------------------------
There are plenty of examples of communicating over UDP multicast on the internet for different programming languages. This example can serve as a reference.
To "connect":
var socket = new UdpClient();
var multicastAddress = IPAddress.Parse(239.0.0.222);
var localEndPoint = new IPEndPoint(IPAddress.Any, 25000);
socket.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
socket.Client.ExclusiveAddressUse = false;
socket.Client.Bind(localEndPoint);
socket.JoinMulticastGroup(_multicastAddress, 2);
And to send some data over the virtual bus:
var endPoint = new IPEndPoint(multicastAddress, 25000);
// extension method to serialize a CAN message into the byte format described above
byte[] data = message.ToBytes();
await _socket.SendAsync(data, data.Length, endPoint);