Connect Device¶
⚠️ Note: This document describes how to use the SDK's API to operate the scanning device and provides sample code in C language. Please note that the API is a synchronous operation and may block the main thread.
⚠️ Note: Before using the API, you need to connect the device and register for message notifications to receive messages from the device. For detailed steps, please refer to Message Notification.
1. Send Configuration Permission¶
You need to use the following Bluetooth service and characteristic UUIDs to perform the write without response
operation:
Bluetooth | UUID |
---|---|
Service | 0x0000ff0000001000800000805f9b34fb |
Characteristic | 0x0000ff0500001000800000805f9b34fb |
After connecting the device, you need to grant configuration permission. If permission is not granted, the scanner will disconnect from Bluetooth.
Use the following command to get the data to write to the characteristic:
const char* result = inateck_scanner_cmd_auth();
The return result is in JSON
format. If the call is successful, result
will return:
{
"status": 0,
"data": [0, 1, 2, 3],
}
If the call fails, result
will return:
{
"status": 1,
"data": [],
}
Return result:
* data
: Configuration permission command, byte array. It needs to be sent to the scanner to obtain configuration permission.
Send the obtained configuration permission command to the scanner and wait for the scanner to respond.
2. Data Parsing¶
Send the obtained configuration permission command to the scanner, and it will return the verification result data
. You can use the following method to parse the data:
int result = inateck_scanner_cmd_check_auth_result(data, data_length);
The return result is of type int
. If the call is successful, result
will return 0
, indicating successful verification. If the call fails, result
will return 1
, indicating verification failure.
3. Sample Code¶
#include <stdio.h>
#include <string.h>
#include "inateck_scanner_cmd.h"
int main() {
const char* result = inateck_scanner_cmd_auth();
if (result) {
// Assuming result is in JSON format, parse the data
const unsigned char* data = (const unsigned char*)result;
int data_length = strlen(result);
// Send data via Bluetooth
// Assuming there is a function send_data_via_bluetooth to send data
send_data_via_bluetooth(data, data_length);
// Wait for the scanner to respond, receive data
// Assuming there is a function receive_data_via_bluetooth to receive data
const char* setting_data = receive_data_via_bluetooth();
int setting_data_length = strlen(setting_data);
int check_result = inateck_scanner_cmd_check_auth_result(setting_data, setting_data_length);
if (check_result == 0) {
printf("Verification successful\n");
} else {
printf("Verification failed\n");
}
} else {
printf("Authentication failed, no result received\n");
}
return 0;
}
// Assumed function to send data
void send_data_via_bluetooth(const unsigned char* data, int data_length) {
// Implement Bluetooth data sending logic
}
// Assumed function to receive data
const char* receive_data_via_bluetooth() {
// Implement Bluetooth data receiving logic
return "example_response_data"; // Return example data
}