Я пытался получить от него некоторые диагностические данные с помощью C++, но функция всегда завершается возвращает 1, что означает ошибку:
Код: Выделить всё
ret = NurApiDiagGetReport(hApi, flags, &report, sizeof(report));Мой main.cpp< /код>
Код: Выделить всё
#include "NurAPI.h"
#include
#include
void ShowErrorAndExitIfNeeded(HANDLE hApi, int error)
{
if (error != NUR_NO_ERROR && error != NUR_ERROR_NO_TAG)
{
TCHAR errorMsg[128+1];
NurApiGetErrorMessage(error, errorMsg, 128);
_tprintf(_T("\r\nNurApi error %d: [%s]\r\n"), error, errorMsg);
// Free API object
NurApiFree(hApi);
exit(EXIT_FAILURE);
}
}
int main() {
HANDLE hApi;
int ret = 0;
struct NUR_DIAG_REPORT report;
memset(&report, 0, sizeof(report));
DWORD flags = 0;default is intended
// Initialize the API
hApi = NurApiCreate();
if (hApi == NULL) {
printf("Failed to create NUR API handle.\n");
return -1;
}
printf("API handle created successfully.\n");
// Attempt to open a connection to the NUR device
ret = NurApiSetUsbAutoConnect(hApi, 1);
if (ret != NUR_NO_ERROR) {
ShowErrorAndExitIfNeeded(hApi, ret);
}
printf("Attempting to connect to NUR device...\n");
printf("Connected to NUR device successfully.\n");
// Prepare to get the diagnostic report
ret = NurApiDiagGetReport(hApi, flags, &report, sizeof(report));
if (ret == NUR_NO_ERROR) {
printf("Diagnostic report obtained successfully.\n");
printf("Temperature: %d C\n", report.temperature);
printf("Battery voltage: %d mV\n", report.uptime);
} else {
ShowErrorAndExitIfNeeded(hApi, ret);
}
// Close the connection and free API
NurApiFree(hApi);
return 0;
}
Код: Выделить всё
API handle created successfully.
Attempting to connect to NUR device...
Connected to NUR device successfully.
NurApi error 1: [I]
Если кому-то нравится попробуйте вот мой CMakeLists.txt
Код: Выделить всё
cmake_minimum_required(VERSION 3.26)
project(nordic)
set(CMAKE_CXX_STANDARD 14)
# Gather all source (.cpp) and header (.h) files in the current directory
file(GLOB_RECURSE PROJECT_SOURCES "${CMAKE_SOURCE_DIR}/*.cpp" "${CMAKE_SOURCE_DIR}/*.h")
list(FILTER PROJECT_SOURCES EXCLUDE REGEX "CMakeCXXCompilerId\\.cpp$")
# Add an executable based on the gathered source files
add_executable(nordic ${PROJECT_SOURCES})
include_directories(${CMAKE_SOURCE_DIR}/include)
link_directories(${CMAKE_SOURCE_DIR})
find_library(NURAPI_LIBRARY NAMES NURAPI PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH)
if(NOT NURAPI_LIBRARY)
message(FATAL_ERROR "NURAPI.lib not found in ${CMAKE_SOURCE_DIR}")
endif()
target_link_libraries(nordic ${NURAPI_LIBRARY})
Код: Выделить всё
$ ls
CMakeLists.txt NurAPI.h NurAPIErrors.h NurAccessoryExtension.h NurOs_Linux.h NurOs_iOS.h SensorExample.cpp SetupExample.cpp cmake-build-debug cmake-build-minsizerel cmake-build-relwithdebinfo
NURAPI.lib NurAPIConstants.h NurAPIExport.h NurOS.h NurOs_Win32.h NurOs_macOS.h SensorExample.h SetupExample.h cmake-build-default cmake-build-release main.cpp
Подробнее здесь: https://stackoverflow.com/questions/787 ... id-scanner