updated example
parent
76afcb410d
commit
fc72d87c76
|
|
@ -2,6 +2,17 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int print_error_code(const char* message, icsneo_error_t error) {
|
||||||
|
char error_str[256] = {0};
|
||||||
|
uint32_t error_length = 256;
|
||||||
|
icsneo_error_t res = icsneo_error_code(error, error_str, &error_length);
|
||||||
|
if (res != icsneo_error_success) {
|
||||||
|
printf("%s: Failed to get string for error code %d with error code %d\n", message, error, res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
printf("%s: %s\n", message, error_str);
|
||||||
|
return (int)error;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
(void)argc;
|
(void)argc;
|
||||||
|
|
@ -10,9 +21,9 @@ int main(int argc, char* argv[]) {
|
||||||
icsneo_device_t* devices[255] = {0};
|
icsneo_device_t* devices[255] = {0};
|
||||||
uint32_t devices_count = 255;
|
uint32_t devices_count = 255;
|
||||||
|
|
||||||
if (icsneo_find(devices, &devices_count, NULL) != icsneo_error_success) {
|
icsneo_error_t res = icsneo_find(devices, &devices_count, NULL);
|
||||||
printf("Failed to find devices\n");
|
if (res != icsneo_error_success) {
|
||||||
return 1;
|
return print_error_code("Failed to find devices", res);
|
||||||
};
|
};
|
||||||
|
|
||||||
printf("Found %u devices\n", devices_count);
|
printf("Found %u devices\n", devices_count);
|
||||||
|
|
@ -22,38 +33,33 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
const char description[255] = {0};
|
const char description[255] = {0};
|
||||||
uint32_t description_length = 255;
|
uint32_t description_length = 255;
|
||||||
icsneo_error_t res = icsneo_device_describe(device, description, &description_length);
|
res = icsneo_device_describe(device, description, &description_length);
|
||||||
if (res != icsneo_error_success) {
|
if (res != icsneo_error_success) {
|
||||||
printf("Failed to get device description %d\n", res);
|
return print_error_code("Failed to get device description", res);
|
||||||
return 1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
icsneo_open_options_t options = icsneo_open_options_none;
|
icsneo_open_options_t options = icsneo_open_options_none;
|
||||||
res = icsneo_get_open_options(device, &options);
|
res = icsneo_get_open_options(device, &options);
|
||||||
if (res != icsneo_error_success) {
|
if (res != icsneo_error_success) {
|
||||||
printf("Failed to get open options %d\n", res);
|
return print_error_code("Failed to get open options", res);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
// Disable Syncing RTC
|
// Disable Syncing RTC
|
||||||
options &= ~icsneo_open_options_sync_rtc;
|
//options &= ~icsneo_open_options_sync_rtc;
|
||||||
res = icsneo_set_open_options(device, options);
|
res = icsneo_set_open_options(device, options);
|
||||||
if (res != icsneo_error_success) {
|
if (res != icsneo_error_success) {
|
||||||
printf("Failed to set open options %d\n", res);
|
return print_error_code("Failed to set open options", res);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Opening device: %s...\n", description);
|
printf("Opening device: %s...\n", description);
|
||||||
res = icsneo_open(device);
|
res = icsneo_open(device);
|
||||||
if (res != icsneo_error_success) {
|
if (res != icsneo_error_success) {
|
||||||
printf("Failed to open device %d\n", res);
|
return print_error_code("Failed to open device", res);
|
||||||
return 1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
printf("Closing device: %s...\n", description);
|
printf("Closing device: %s...\n", description);
|
||||||
res = icsneo_close(device);
|
res = icsneo_close(device);
|
||||||
if (res != icsneo_error_success) {
|
if (res != icsneo_error_success) {
|
||||||
printf("Failed to close device %d\n", res);
|
return print_error_code("Failed to close device", res);
|
||||||
return 1;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue