-
-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Copyright © 2020-2022 Uwe Vogt, UV Software, Berlin ([email protected])
All rights reserved.
The Swedish company Kvaser AB supplies advanced CAN solutions to engineers designing and deploying systems for manifold areas of applications. They offer a wide range of CAN hardware and CAN software, mainly for applications under Windows but also under Linux. A macOS user-space driver for CAN Leaf Interfaces from Kvaser is provided by UV Software.
The macOS driver for USB CAN interfaces from Kvaser is based on MacCAN-Core which is an abstraction (or rather a wrapper) of Apple´s IOUsbKit to create USB user-space drivers for CAN interfaces from various vendors under macOS.
The GitHub repository contains the source code for the MacCAN-KvaserCAN driver and several alternatives to build dynamic libraries for macOS, either as a C++ class library (libKvaserCAN), or as a CAN API V3 wrapper library (libUVCANKVL), as well as some example programs and my beloved CAN utilities can_moni
and can_test
.
The MacCAN-KvaserCAN driver comes with an CAN API V3 compatible API.
CAN API V3 is a wrapper specification by UV Software to have a uniform CAN Interface API for various CAN interfaces from different vendors running under multiple operating systems. See header file CANAPI.h
for the CAN API V3 interface.
Note: This project does not aim to implement Kvaser´s CANlib API on macOS.
Feature | Leaf Devices |
Mhydra Devices |
Remarks |
---|---|---|---|
CAN 2.0 | ✔️ | ✔️ | Classical CAN |
CAN FD | ❌ | ✔️ | Flexible Data-rate CAN |
Bit-rate, CAN 2.0 | ✔️ | ✔️ | high speed: up to 1 Mbps |
Bit-rate, CAN FD | ❌ | ✔️ | nominal: up to 1 Mbps data phase: up to 8 Mbps |
11-bit identifier (STD) | ✔️ | ✔️ | CAN 2.0 and CAN FD |
29-bit identifier (XTD) | ✔️ | ✔️ | CAN 2.0 and CAN FD |
Remote frames (RTR) | ✔️ | ✔️ | CAN 2.0 only |
Error frames (ERR) | ✔️* | ✔️* | CAN 2.0 and CAN FD |
Error indicator (ESI) | ❌ | ✔️* | CAN FD only |
Bit-rate switching (BRS) | ❌ | ✔️* | CAN FD only |
Silent operation (MON) | ✔️* | ✔️* | CAN 2.0 and CAN FD |
Identifier filtering | ❌ | ❌ | CAN 2.0 and CAN FD |
Operation modes: | |||
- Monitor mode enable/disable (MON) | ✔️* | ✔️* | disabled by default |
- Error frames enable/disable (ERR) | ✔️* | ✔️* | disabled by default |
- Remote frames disable/enable (NRTR) | ✔️ | ✔️ | enabled by default |
- Extended frames disable/enable (NXTD) | ✔️ | ✔️ | enabled by default |
- Shared access enable/disable (SHRD) | ❌ | ❌ | not supported |
- Non-ISO CAN FD enable/disable (NISO) | ❌ | ❌ | not supported |
- Bit-rate switching enable/disable (BRSE) | ❌ | ✔️* | disabled by default |
- CAN FD operation enable/disable (FDOE) | ❌ | ✔️* | disabled by default |
Bit-rate settings: | |||
- Pre-defined bit-timing indexes | ✔️ | ✔️ | acc. CiA CANopen specification |
- BTR register values | ✔️ | ✔️ | register fields: - freq (clock frequency in [Hz])- brp (bit-rate prescaler)- tseg1 (time segment 1)- tseg2 (time segment 2)- sjw (synchronization jump width)- sam (number of samples) |
Message reception: | |||
- Message queue (FIFO) | ✔️ | ✔️ | up to 64K CAN messages |
- Polling | ✔️ | ✔️ | return immediately |
- Timed out | ✔️ | ✔️ | wait up to 65'534 milliseconds |
- Blocking read | ✔️ | ✔️ | wait infinitely |
Message transmission: | |||
- Acknowledged write | ✔️ | ✔️ | wait up to 65'534 milliseconds |
- Buffered write | ✔️ | ✔️ | buffer size depends on the hardware |
Software Development Kit: | |||
- Kvaser CANlib | ❌ | ❌ | not available |
- CAN API V3 | ✔️ | ✔️ | C API and C++ API by UV Software |
- Dynamic library | ✔️ | ✔️ |
libUVCANKVL.dylib , libKvaserCAN.dylib
|
- Static library | ✔️ | ✔️ |
libUVCANKVL.a , libKvaserCAN.a
|
- Source code | ✔️ | ✔️ | BDS-2-Clause or GPL-3.0-or-later |
- Apple silicon | ✔️ | ✔️ | and Intel architecture |
- Swift wrapper | ✔️ | ✔️ | Swift 5.5 (including SPM) |
- Python wrapper | ✔️ | ✔️ | Python 2.7 and 3.8 |
- Windows wrapper | ✔️ | ✔️ | CAN API V3 Wrapper Library |
- Utilities | ✔️ | ✔️ | CLI utilities can_moni and can_test
|
- Examples | ✔️ | ✔️ | C, C++, Swift, Python |
*) Depends on the device hardware or firmware.
Property | Datatype | since | Description |
---|---|---|---|
CANPROP_GET_SPEC | uint16_t | v0.1 | Version of the wrapper specification |
CANPROP_GET_VERSION | uint16_t | v0.1 | Version number of the library |
CANPROP_GET_PATCH_NO | uint8_t | v0.1 | Patch number of the library |
CANPROP_GET_BUILD_NO | uint32_t | v0.1 | Build number of the library |
CANPROP_GET_LIBRARY_ID | int32_t | v0.1 | Library id of the library |
CANPROP_GET_LIBRARY_VENDOR | char[256] | v0.1 | Vendor name of the library |
CANPROP_GET_LIBRARY_DLLNAME | char[256] | v0.1 | File name of the library DLL |
CANPROP_GET_DEVICE_TYPE | int32_t | v0.2 | Device type of the CAN interface |
CANPROP_GET_DEVICE_NAME | char[256] | v0.1 | Device name of the CAN interface |
CANPROP_GET_DEVICE_VENDOR | char[256] | v0.1 | Vendor name of the CAN interface |
CANPROP_GET_DEVICE_DLLNAME | char[256] | v0.2 | File name of the CAN interface DLL |
CANPROP_GET_DEVICE_PARAM | char[256] | (n/a) | Device parameter of the CAN interface |
CANPROP_GET_OP_CAPABILITY | uint8_t | v0.1 | Supported operation modes of the CAN controller |
CANPROP_GET_OP_MODE | uint8_t | v0.1 | Active operation mode of the CAN controller |
CANPROP_GET_BITRATE | can_bitrate_t | v0.1 | Active bit-rate of the CAN controller |
CANPROP_GET_SPEED | can_speed_t | v0.1 | Active bus speed of the CAN controller |
CANPROP_GET_STATUS | uint8_t | v0.1 | Current status register of the CAN controller |
CANPROP_GET_BUSLOAD | uint8_t | v0.1 | Current bus load of the CAN controller(in [1/100]) |
CANPROP_GET_NUM_CHANNELS | uint8_t | v0.2 | Numbers of CAN channels on the CAN interface |
CANPROP_GET_CAN_CHANNEL | uint8_t | v0.2 | Active CAN channel on the CAN interface |
CANPROP_GET_TX_COUNTER | uint64_t | v0.1 | Total number of sent messages |
CANPROP_GET_RX_COUNTER | uint64_t | v0.1 | Total number of received messages |
CANPROP_GET_ERR_COUNTER | uint64_t | v0.1 | Total number of received error frames |
CANPROP_GET_RCV_QUEUE_SIZE | uint32_t | v0.2 | Maximum number of message the receive queue can hold |
CANPROP_GET_RCV_QUEUE_HIGH | uint32_t | v0.2 | Maximum number of message the receive queue has hold |
CANPROP_GET_RCV_QUEUE_OVFL | uint64_t | v0.2 | Overflow counter of the receive queue |
CANPROP_GET_FLT_11BIT_CODE | int32_t | (n/a) | Acceptance filter code of 11-bit identifier |
CANPROP_GET_FLT_11BIT_MASK | int32_t | (n/a) | Acceptance filter mask of 11-bit identifier |
CANPROP_GET_FLT_29BIT_CODE | int32_t | (n/a) | Acceptance filter code of 29-bit identifier |
CANPROP_GET_FLT_29BIT_MASK | int32_t | (n/a) | Acceptance filter mask of 29-bit identifier |
CANPROP_SET_FLT_11BIT_CODE | int32_t | (n/a) | Set value for acceptance filter code of 11-bit identifier |
CANPROP_SET_FLT_11BIT_MASK | int32_t | (n/a) | Set value for acceptance filter mask of 11-bit identifier |
CANPROP_SET_FLT_29BIT_CODE | int32_t | (n/a) | Set value for acceptance filter code of 29-bit identifier |
CANPROP_SET_FLT_29BIT_MASK | int32_t | (n/a) | Set value for acceptance filter mask of 29-bit identifier |
CANPROP_SET_FIRST_CHANNEL | NULL |
v0.1.1 | Set index to the first entry in the interface list |
CANPROP_SET_NEXT_CHANNEL | NULL |
v0.1.1 | Set index to the next entry in the interface list |
CANPROP_GET_CHANNEL_NO | int32_t | v0.1.1 | Get channel no. at actual index in the interface list |
CANPROP_GET_CHANNEL_NAME | char[256] | v0.1.1 | Get channel name at actual index in the interface list |
CANPROP_GET_CHANNEL_DLLNAME | char[256] | v0.1.1 | Get file name of the DLL at actual index in the interface list |
CANPROP_GET_CHANNEL_VENDOR_ID | int32_t | v0.1.1 | Get library id at actual index in the interface list |
CANPROP_GET_CHANNEL_VENDOR_NAME | char[256] | v0.1.1 | Get vendor name at actual index in the interface list |
CANPROP_GET_VENDOR_PROP | void* | (n/a) | Get a vendor-specific property value |
CANPROP_SET_VENDOR_PROP | void* | (n/a) | Set a vendor-specific property value |
Only the following devices from Kvaser AB are supported:
- Kvaser Leaf Light v2 (EAN: 73-30130-00685-0)
- Kvaser Leaf Pro HS v2 (EAN: 73-30130-00843-4)
- Kvaser U100P (EAN: 73-30130-01174-8)
Since version 0.3 theoretically all (single-channel) CAN interfaces from Kvaser´s device family Leaf Interfaces (CAN 2.0 interfaces, e.g. Leaf Light v2) and from Kvaser´s device family Mhydra Interfaces (CAN FD interfaces, e.g. U100P) are supported. To add a new CAN USB interface from Kvaser, only its USB ProductID and some device specific attributes have to be entered or enabled in the source code.
Note: The CAN devices listed above are the ones that are enabled and have been tested.
For technical specifications, prices and delivery terms see Kvaser´s website.
For a list of known bugs and caveats see tab Issues in the GitHub repo.
This work is dual-licensed under the terms of the BSD 2-Clause "Simplified" License and under the terms of the GNU General Public License v3.0 (or any later version). You can choose between one of them if you use this work in whole or in part.
Mac and macOS are trademarks of Apple Inc., registered in the U.S. and other countries.
Windows is a registered trademark of Microsoft Corporation in the United States and/or other countries.
Linux is a registered trademark of Linus Torvalds.
All other company, product and service names mentioned herein are trademarks, registered trademarks or service marks of their respective owners.
If you connect your CAN device to a real CAN network when using this library, you might damage your application.
E-Mail: mailto://[email protected]
Internet: https://www.mac-can.net