Prefix and Suffix Configuration¶
⚠️ 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 when used.
⚠️ Note: Before using the API, you need to connect the device first. For specific steps, please refer to Connect Device.
1. Set Prefix¶
Set the prefix for the scanning device. Usage is as follows:
const char* result = inateck_scanner_ble_set_prefix(device_id, prefix, prefix_length);
The return result is in JSON
format. If the call is successful, result
will return:
{
"status": 0,
"error": "",
}
If the call fails, result
will return:
{
"status": 1,
"error": "error message",
}
Input parameters are as follows:
prefix
: Prefix string, with a maximum length of 32 bytes, and the last byte must be0xFF
. For character range, please refer to Custom Encoding Table. For example, if the prefix isABC
, thenprefix
should be0x41 0x42 0x43 0xFF
.prefix_length
: Length of the prefix, with a maximum of 32 bytes.
2. Get Prefix¶
Get the prefix of the scanning device. Usage is as follows:
const char* result = inateck_scanner_ble_get_prefix(device_id);
The return result is in JSON
format. If the call is successful, result
will return:
{
"status": 0,
"error": "",
"prefix": [0x41, 0x42, 0x43, 0xFF],
}
If the call fails, result
will return:
{
"status": 1,
"error": "error message",
"prefix": [],
}
Return parameters are as follows:
prefix
: Prefix byte array. For byte parsing, please refer to Custom Encoding Table.
3. Set Suffix¶
Set the suffix for the scanning device. Usage is as follows:
const char* result = inateck_scanner_ble_set_suffix(device_id, suffix, suffix_length);
The return result is in JSON
format. If the call is successful, result
will return:
{
"status": 0,
"error": "",
}
If the call fails, result
will return:
{
"status": 1,
"error": "error message",
}
Input parameters are as follows:
suffix
: Suffix string, with a maximum length of 32 bytes, and the last byte must be0xFF
. For character range, please refer to Custom Encoding Table. For example, if the suffix isXYZ
, thensuffix
should be0x58 0x59 0x5A 0xFF
.suffix_length
: Length of the suffix, with a maximum of 32 bytes.
4. Get Suffix¶
Get the suffix of the scanning device. Usage is as follows:
const char* result = inateck_scanner_ble_get_suffix(device_id);
The return result is in JSON
format. If the call is successful, result
will return:
{
"status": 0,
"error": "",
"suffix": [0x58, 0x59, 0x5A, 0xFF],
}
If the call fails, result
will return:
{
"status": 1,
"error": "error message",
"suffix": [],
}
Return parameters are as follows:
suffix
: Suffix byte array. For byte parsing, please refer to Custom Encoding Table.
5. Sample Code¶
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include "inateck_scanner_ble.h"
int main() {
const char* device_id = "device id";
const char prefix[] = {0x41, 0x42, 0x43, 0xFF};
const char suffix[] = {0x58, 0x59, 0x5A, 0xFF};
const char* result = inateck_scanner_ble_set_prefix(device_id, prefix, sizeof(prefix));
printf("set prefix result: %s\n", result);
result = inateck_scanner_ble_get_prefix(device_id);
printf("get prefix result: %s\n", result);
result = inateck_scanner_ble_set_suffix(device_id, suffix, sizeof(suffix));
printf("set suffix result: %s\n", result);
result = inateck_scanner_ble_get_suffix(device_id);
printf("get suffix result: %s\n", result);
return 0;
}