diff --git a/README.md b/README.md
index 00251ee..600a9ce 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
### Wrapper Library for Kvaser CAN Interfaces (Windows®)
-_Copyright © 2017-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.de)_
+_Copyright © 2017-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.de)_
# CAN API V3 for Kvaser CAN Interfaces
@@ -152,4 +152,4 @@ _If you connect your CAN device to a real CAN network when using this library, y
### Contact
E-Mail: mailto://info@uv-software.com \
-Internet: https://www.uv-software.com
\ No newline at end of file
+Internet: https://www.uv-software.com
diff --git a/Sources/CANAPI/README.md b/Sources/CANAPI/README.md
index baf5e96..d766f9b 100644
--- a/Sources/CANAPI/README.md
+++ b/Sources/CANAPI/README.md
@@ -3,7 +3,7 @@
_Copyright © 2004-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com)_ \
_All rights reserved._
-Version $Rev: 1019 $
+Version $Rev: 1020 $
# A CAN Interface Wrapper Specification
@@ -54,7 +54,7 @@ extern int can_bitrate(int handle, can_bitrate_t *bitrate, can_speed_t *speed);
extern int can_property(int handle, uint16_t param, void *value, uint32_t nbyte);
extern char *can_hardware(int handle);
-extern char *can_software(int handle);
+extern char *can_firmware(int handle);
#if (OPTION_CANAPI_LIBRARY != 0)
extern char *can_library(int handle);
diff --git a/Sources/CANAPI/can_api.h b/Sources/CANAPI/can_api.h
index 7bb81c0..dc47ac3 100644
--- a/Sources/CANAPI/can_api.h
+++ b/Sources/CANAPI/can_api.h
@@ -2,7 +2,7 @@
/*
* CAN Interface API, Version 3 (generic)
*
- * Copyright (c) 2004-2021 Uwe Vogt, UV Software, Berlin (info@uv-software.com)
+ * Copyright (c) 2004-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com)
* All rights reserved.
*
* This file is part of CAN API V3.
@@ -51,7 +51,7 @@
*
* @author $Author: eris $
*
- * @version $Rev: 993 $
+ * @version $Rev: 1020 $
*
* @defgroup can_api CAN Interface API, Version 3
* @{
@@ -120,6 +120,7 @@ typedef int can_handle_t;
* @{ */
#define can_transmit(hnd, msg) can_write(hnd, msg, 0U)
#define can_receive(hnd, msg) can_read(hnd, msg, 0U)
+#define can_software(hnd) can_firmware(hnd)
#define can_msg_t can_message_t
/** @} */
@@ -445,7 +446,7 @@ CANAPI char *can_hardware(int handle);
*
* @returns pointer to a zero-terminated string, or NULL on error.
*/
-CANAPI char *can_software(int handle);
+CANAPI char *can_firmware(int handle);
#if (OPTION_CANAPI_LIBRARY != 0)
diff --git a/Sources/KvaserCAN.cpp b/Sources/KvaserCAN.cpp
index b01b997..5b42244 100644
--- a/Sources/KvaserCAN.cpp
+++ b/Sources/KvaserCAN.cpp
@@ -49,10 +49,10 @@
#ifdef _MSC_VER
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
-#define VERSION_PATCH 99
+#define VERSION_PATCH 1
#else
#define VERSION_MAJOR 0
-#define VERSION_MINOR 0
+#define VERSION_MINOR 2
#define VERSION_PATCH 0
#endif
#define VERSION_BUILD BUILD_NO
@@ -133,6 +133,7 @@ CKvaserCAN::CKvaserCAN() {
EXPORT
CKvaserCAN::~CKvaserCAN() {
+ // set CAN contoller into INIT mode and close USB device
(void)TeardownChannel();
}
@@ -288,7 +289,7 @@ char *CKvaserCAN::GetHardwareVersion() {
EXPORT
char *CKvaserCAN::GetFirmwareVersion() {
// retrieve the firmware version of the CAN controller
- return can_software(m_Handle);
+ return can_firmware(m_Handle);
}
EXPORT
diff --git a/Sources/Wrapper/can_api.c b/Sources/Wrapper/can_api.c
index 2d8e8d4..d91cb5a 100644
--- a/Sources/Wrapper/can_api.c
+++ b/Sources/Wrapper/can_api.c
@@ -52,10 +52,10 @@
#ifdef _MSC_VER
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
-#define VERSION_PATCH 99
+#define VERSION_PATCH 1
#else
#define VERSION_MAJOR 0
-#define VERSION_MINOR 0
+#define VERSION_MINOR 2
#define VERSION_PATCH 0
#endif
#define VERSION_BUILD BUILD_NO
@@ -98,6 +98,9 @@ static const char version[] = "CAN API V3 for Kvaser CAN Interfaces, Version " V
/* ----------- options ------------------------------------------------
*/
+#if (OPTION_CAN_2_0_ONLY != 0)
+#error Compilation with legacy CAN 2.0 frame format!
+#endif
/* ----------- defines ------------------------------------------------
*/
@@ -685,11 +688,7 @@ int can_read(int handle, can_msg_t *msg, uint16_t timeout)
msg->brs = (flags & canFDMSG_BRS)? 1 : 0;
msg->esi = (flags & canFDMSG_ESI)? 1 : 0;
msg->dlc = (uint8_t)LEN2DLC(len); // unclear: is it a length or a DLC?
-#ifndef CAN_20_ONLY
memcpy(msg->data, data, CANFD_MAX_LEN);
-#else
- memcpy(msg->data, data, CAN_MAX_LEN);
-#endif
msg->timestamp.tv_sec = (time_t)(timestamp / 1000ul);
msg->timestamp.tv_nsec = (long)(timestamp % 1000ul) * 1000000l;
can[handle].status.receiver_empty = 0; // message read
@@ -810,6 +809,8 @@ int can_property(int handle, uint16_t param, void *value, uint32_t nbyte)
char *can_hardware(int handle)
{
static char hardware[256] = ""; // hardware version
+ char str[256]; // channel name
+ uint64_t rev; // revision
if (!init) // must be initialized
return NULL;
@@ -818,25 +819,40 @@ char *can_hardware(int handle)
if (can[handle].handle == canINVALID_HANDLE) // must be an opened handle
return NULL;
- if (canGetChannelData(can[handle].channel, canCHANNELDATA_CHANNEL_NAME, hardware, 255) != canOK)
+ if (canGetChannelData(can[handle].channel, canCHANNELDATA_CHANNEL_NAME, (void*)str, 256) != canOK)
+ return NULL;
+ if (canGetChannelData(can[handle].channel, canCHANNELDATA_CARD_HARDWARE_REV, (void*)&rev, sizeof(uint64_t)) != canOK)
return NULL;
+ snprintf(hardware, 256, "%s, hardware revision %u.%u", str,
+ (uint16_t)((rev & 0x00000000FFFF0000UL) >> 16),
+ (uint16_t)((rev & 0x000000000000FFFFUL) >> 0));
return (char*)hardware; // hardware version
}
-char *can_software(int handle)
+char *can_firmware(int handle)
{
- static char software[256] = ""; // software version
- unsigned short version; // version number
+ static char firmware[256] = ""; // firmware version
+ char str[256]; // channel name
+ uint64_t rev; // revision
if (!init) // must be initialized
return NULL;
- (void)handle; // handle not needed here
+ if (!IS_HANDLE_VALID(handle)) // must be a valid handle
+ return NULL;
+ if (can[handle].handle == canINVALID_HANDLE) // must be an opened handle
+ return NULL;
- version = canGetVersion(); // FIXME: check encoding
- snprintf(software, 256, "Kvaser CANlib SDK V%d.%d (canlib32.dll)", (version >> 8), (version & 0xFF));
+ if (canGetChannelData(can[handle].channel, canCHANNELDATA_CHANNEL_NAME, (void*)str, 256) != canOK)
+ return NULL;
+ if (canGetChannelData(can[handle].channel, canCHANNELDATA_CARD_FIRMWARE_REV, (void*)&rev, sizeof(uint64_t)) != canOK)
+ return NULL;
+ snprintf(firmware, 256, "%s, firmware version %u.%u.%u", str,
+ (uint16_t)((rev & 0xFFFF000000000000UL) >> 48),
+ (uint16_t)((rev & 0x0000FFFF00000000UL) >> 32),
+ (uint16_t)((rev & 0x00000000FFFF0000UL) >> 16));
- return (char*)software; // software version
+ return (char*)firmware; // firmware version
}
/* ----------- local functions ----------------------------------------
@@ -997,8 +1013,6 @@ static int map_paramsFd2bitrate(const btr_data_t *busParams, long frequency, can
static int lib_parameter(uint16_t param, void *value, size_t nbyte)
{
int rc = CANERR_ILLPARA; // suppose an invalid parameter
-// int i = 0; // one always needs an i
-
static int idx_board = EOF; // actual index in the interface list
if (value == NULL) { // check for null-pointer
diff --git a/Trial/Sources/main.cpp b/Trial/Sources/main.cpp
index e7ce788..28e787c 100644
--- a/Trial/Sources/main.cpp
+++ b/Trial/Sources/main.cpp
@@ -219,7 +219,7 @@ int main(int argc, const char * argv[]) {
retVal = myDriver.GetProperty(CANPROP_GET_CHANNEL_NO, (void *)&i32Val, sizeof(int32_t));
if (retVal == CCanApi::NoError) {
retVal = CKvaserCAN::ProbeChannel(i32Val, opMode, state);
- fprintf(stdout, ">>> CCanApi.ProbeChannel(%i): state = %s", i32Val,
+ fprintf(stdout, ">>> CCanApi::ProbeChannel(%i): state = %s", i32Val,
(state == CCanApi::ChannelOccupied) ? "occupied" :
(state == CCanApi::ChannelAvailable) ? "available" :
(state == CCanApi::ChannelNotAvailable) ? "not available" : "not testable");
diff --git a/Utilities/can_moni/Sources/main.cpp b/Utilities/can_moni/Sources/main.cpp
index 40eda5a..3d18d61 100644
--- a/Utilities/can_moni/Sources/main.cpp
+++ b/Utilities/can_moni/Sources/main.cpp
@@ -985,5 +985,5 @@ static void version(FILE *stream, const char *program)
{
fprintf(stdout, "%s\n%s\n\n%s\n\n", APPLICATION, COPYRIGHT, LICENSE);
(void)program;
- fprintf(stream, "Written by Uwe Vogt, UV Software, Berlin \n");
+ fprintf(stream, "Written by Uwe Vogt, UV Software, Berlin \n");
}
diff --git a/Utilities/can_test/Sources/main.cpp b/Utilities/can_test/Sources/main.cpp
index 6a90d32..af5643b 100644
--- a/Utilities/can_test/Sources/main.cpp
+++ b/Utilities/can_test/Sources/main.cpp
@@ -1198,5 +1198,5 @@ static void version(FILE *stream, const char *program)
{
fprintf(stdout, "%s\n%s\n\n%s\n\n", APPLICATION, COPYRIGHT, LICENSE);
(void)program;
- fprintf(stream, "Written by Uwe Vogt, UV Software, Berlin \n");
+ fprintf(stream, "Written by Uwe Vogt, UV Software, Berlin \n");
}