Set HID Output Mode¶
⚠️ Note: This document describes how to operate the scanning device using the SDK's API and provides sample code in C language. Please note that the API is a synchronous operation and may block the main thread when used.
⚠️ 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. Set HID Output Mode¶
Set the output mode of the barcode in HID mode, you need to use the following Bluetooth service and characteristic UUID for write without response
operation:
Bluetooth | UUID |
---|---|
Service | 0x0000ff0000001000800000805f9b34fb |
Characteristic | 0x0000ff0400001000800000805f9b34fb |
Use the following command to get the data to be written to the characteristic:
const char* result = inateck_scanner_cmd_get_hid_output(device_id, output_type);
Input parameters:
output_type
:0
means output barcode content to HID,1
means output to SDK.
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": [],
}
2. Message Parsing¶
After the device responds, you can use the following method to parse the data:
int result = inateck_scanner_cmd_check_result(data, data_length);
The return result is in int
type. If the call is successful, result
will return 0
. If the call fails, result
will return 1
.
3. Sample Code¶
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include "inateck_scanner_ble.h"
int main() {
int output_type = 0;
const char* result = inateck_scanner_ble_set_hid_output(device_id, output_type);
if (result) {
// 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 write without response
// Here we assume there is a function send_data_via_bluetooth to send data
send_data_via_bluetooth(data, data_length);
// Wait for the device to respond and receive data
// Here we assume there is a function receive_data_via_bluetooth to receive data
receive_data_via_bluetooth();
const unsigned char* data = get_received_data();
int data_length = get_received_data_length();
// Parse the data
int result = inateck_scanner_cmd_check_result(data, data_length);
if (result == 0) {
printf("Set HID Output Type success\n");
} else {
printf("Set HID Output Type failed\n");
}
}
return 0;
}