在国产系统麒麟V10系统上面上使用的 USB HID POS 的 SDK 包.
特别说明涉及到永久参数的函数接口,请勿频繁使用.如果是出厂或者偶尔设置推荐使用永久参数,如果是每次读码都进行参数修改,请使用临时参数.频繁进行永久参数操作会减小扫码设备的使用寿命.
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include "tx_scanner.h"
/*************************************************************************
内部宏定义
*************************************************************************/
/*************************************************************************
内部结构、枚举、公用体等结构声明
*************************************************************************/
/*************************************************************************
内部静态变量定义
全局变量定义
extern 外部变量声明
*************************************************************************/
/*************************************************************************
静态函数声明
extern 外部函数声明
*************************************************************************/
/**解码数据回调函数**/
static int32 tx_scanner_sdk_decode_data_cb(uint8 ucCodeType, uint8 *pBuf, uint32 uiBufLen);
/**连接状态回调函数**/
static void tx_scanner_sdk_comm_state_cb_fun(uint8 ucState);
static void tx_scanner_sdk_show_menu(void);
/*************************************************************************
函数定义
*************************************************************************/
int32 main(void)
{
int32 iRet;
uint8 ucVer[64] = "";
uint8 ucTemp1;
uint8 ucTemp2;
uint8 ucTemp3[50];
int length = 0;
tx_scanner_get_version(ucVer, sizeof(ucVer));
printf("linux c/c++ usb hidpos demo ver:%s\r\n", ucVer);
/**注册解码数据回调函数**/
iRet = tx_scanner_decode_data_fun_register(tx_scanner_sdk_decode_data_cb);
if(iRet < 0)
{
printf("tx_scanner_decode_data_fun_register fail!!!\r\n");
return 1;
}
/**注册设备连接状态回调函数**/
iRet = tx_scanner_comm_state_fun_register(tx_scanner_sdk_comm_state_cb_fun);
if(iRet < 0)
{
printf("tx_scanner_comm_state_fun_register fail!!!\r\n");
return 1;
}
/**初始化**/
iRet = tx_scanner_init();
if(iRet < 0)
{
printf("tx_scanner_init fail!!!\r\n");
return 1;
}
printf("******************************************************\r\n");
printf("a:start decode\r\n");
printf("b:stop decode\r\n");
printf("c:no time decode start\r\n");
printf("d:get version info\r\n");
printf("e:get product info\r\n");
printf("f:set trigger mode; 0:LEVEL,1:PULSE,2:CONTINUOUS,3:AUTOSENS; save:0:no,1:yes.(eg:f01)\r\n");
printf("g:get trigger mode\r\n");
printf("h:set light LED; 0:working light,1:always off,2:always on; save:0:no,1:yes.(eg:h01)\r\n");
printf("i:get light LED\r\n");
printf("?/m:more menu\r\n");
printf("q:quit\r\n");
printf("******************************************************\r\n");
while(1)
{
switch(getchar())
{
case 'a':
case 'A':
iRet = tx_scanner_decode_start();
if(iRet < 0)
printf("tx_scanner_decode_start fail!!!\r\n");
else
printf("start\r\n");
break;
case 'b':
case 'B':
iRet = tx_scanner_decode_stop();
if(iRet < 0)
printf("tx_scanner_decode_stop fail!!!\r\n");
else
printf("stop\r\n");
break;
case 'c':
case 'C':
iRet = tx_scanner_no_time_decode_start();
if(iRet < 0)
printf("tx_scanner_no_time_decode_start fail!!!\r\n");
else
printf("no time start\r\n");
break;
case 'd':
case 'D':
{
uint8 ucVerInfo[128] = "";
iRet = tx_scanner_get_version_info(ucVerInfo, sizeof(ucVerInfo));
if(iRet < 0)
printf("tx_scanner_get_version_info fail!!!\r\n");
else
printf("%s\r\n", ucVerInfo);
}
break;
case 'e':
case 'E':
{
uint8 ucProInfo[128] = "";
iRet = tx_scanner_get_all_product_info(ucProInfo, sizeof(ucProInfo));
if(iRet < 0)
printf("tx_scanner_get_all_product_info fail!!!\r\n");
else
printf("%s\r\n", ucProInfo);
}
break;
case 'f':
case 'F':
ucTemp1 = getchar();
ucTemp2 = getchar();
ucTemp1 -= '0';
ucTemp2 -= '0';
printf("%d,%d\r\n", ucTemp1, ucTemp2);
iRet = tx_scanner_set_trigger_mode((DB_TRIGGER_MODE_E)ucTemp1, ucTemp2);
if(iRet < 0)
printf("tx_scanner_set_trigger_mode fail!!!\r\n");
break;
case 'g':
case 'G':
iRet = tx_scanner_get_trigger_mode();
printf("tx_scanner_get_trigger_mode:%d\r\n", iRet);
break;
case 'h':
case 'H':
ucTemp1 = getchar();
ucTemp2 = getchar();
ucTemp1 -= '0';
ucTemp2 -= '0';
printf("%d,%d\r\n", ucTemp1, ucTemp2);
iRet = tx_scanner_set_light_state((DB_LED_STATE_E)ucTemp1, ucTemp2);
if(iRet < 0)
printf("tx_scanner_set_light_state fail!!!\r\n");
break;
case 'i':
case 'I':
iRet = tx_scanner_get_light_state();
printf("tx_scanner_get_light_state:%d\r\n", iRet);
break;
case 'j':
case 'J':
ucTemp1 = getchar();
ucTemp2 = getchar();
ucTemp1 -= '0';
ucTemp2 -= '0';
printf("%d,%d\r\n", ucTemp1, ucTemp2);
iRet = tx_scanner_set_focus_state((DB_LED_STATE_E)ucTemp1, ucTemp2);
if (iRet < 0)
printf("tx_scanner_set_focus_state fail!!!\r\n");
break;
case 'k':
case 'K':
iRet = tx_scanner_get_focus_state();
printf("tx_scanner_set_focus_state:%d\r\n", iRet);
break;
case 'l':
case 'L':
ucTemp1 = getchar();
ucTemp2 = getchar();
ucTemp1 -= '0';
ucTemp2 -= '0';
printf("%d,%d\r\n", ucTemp1, ucTemp2);
iRet = tx_scanner_set_en_prefix(ucTemp1, ucTemp2);
if (iRet < 0)
printf("tx_scanner_set_prefix_function fail!!!\r\n");
break;
case 'n':
case 'N':
iRet = tx_scanner_get_en_prefix();
printf("tx_scanner_get_prefix_function_state:%d\r\n", iRet);
break;
case 'o':
case 'O':
{
uint8 ucPrefix[] = "ABC";
ucTemp1 = getchar();
ucTemp1 -= '0';
length = strlen((char*)ucPrefix);
iRet = tx_scanner_set_prefix(ucPrefix, length, ucTemp1);
if(iRet < 0)
{
printf("tx_scanner_set_prefix fail!!!\r\n");
}
break;
}
case 'p':
case 'P':
memset(ucTemp3,0,sizeof(ucTemp3));
iRet = tx_scanner_get_prefix(ucTemp3, length);
printf("tx_scanner_get_prefix_length:%d\r\n",iRet);
break;
case 'r':
case 'R':
ucTemp1 = getchar();
ucTemp2 = getchar();
ucTemp1 -= '0';
ucTemp2 -= '0';
printf("%d,%d\r\n", ucTemp1, ucTemp2);
iRet = tx_scanner_set_en_suffix(ucTemp1, ucTemp2);
if (iRet < 0)
printf("tx_scanner_set_suffix_function fail!!!\r\n");
break;
case 's':
case 'S':
iRet = tx_scanner_get_en_suffix();
printf("tx_scanner_get_suffix_function_state:%d\r\n", iRet);
break;
case 't':
case 'T':
{
uint8 ucSuffix[] = "CBA";
ucTemp1 = getchar();
ucTemp1 -= '0';
length = strlen((char*)ucSuffix);
iRet = tx_scanner_set_suffix(ucSuffix, length, ucTemp1);
if(iRet < 0)
{
printf("tx_scanner_set_suffix fail!!!\r\n");
}
break;
}
case 'u':
case 'U':
memset(ucTemp3,0,sizeof(ucTemp3));
iRet = tx_scanner_get_suffix(ucTemp3,length);
printf("tx_scanner_get_suffix_length:%d\r\n",iRet);
break;
case 'v':
case 'V':
{
uint16 ucTime;
printf("Please enter the duration of a single scan(0-65536)\r\n");
scanf("%hd\r\n",&ucTime);
ucTemp2 = getchar();
ucTemp2 -= '0';
printf("%d,%d\r\n",ucTime,ucTemp2);
iRet = tx_scanner_set_once_scan_time(ucTime,ucTemp2);
if(iRet < 0)
{
printf("tx_scanner_set_once_scan_time fail!!!\r\n");
}
break;
}
case 'w':
case 'W':
iRet = tx_scanner_get_once_scan_time();
printf("tx_scanner_get_once_scan_time:%d\r\n", iRet);
break;
case 'x':
case 'X':
printf("Please enter the volume level of the prompt tone(0-100):\r\n");
scanf("%hhd\r\n",&ucTemp1);
ucTemp2 = getchar();
ucTemp2 -= '0';
printf("%d,%d\r\n",ucTemp1,ucTemp2);
iRet = tx_scanner_set_beep_volume(ucTemp1,ucTemp2);
if(iRet < 0)
{
printf("tx_scanner_set_beep_volume fail!!!\r\n");
}
break;
case 'y':
case 'Y':
iRet = tx_scanner_get_beep_volume();
printf("tx_scanner_get_beep_volume:%d\r\n",iRet);
break;
case 'z':
case 'Z':
ucTemp1 = getchar();
ucTemp2 = getchar();
ucTemp1 -= '0';
ucTemp2 -= '0';
printf("%d,%d\r\n", ucTemp1, ucTemp2);
iRet = tx_scanner_set_heartbeat_type((DB_HEARTBEAT_TYPE_E)ucTemp1, ucTemp2);
if (iRet < 0)
printf("tx_scanner_set_heartbeat_type fail!!!\r\n");
break;
case '0':
iRet = tx_scanner_get_heartbeat_type();
printf("tx_scanner_get_heartbreat_type:%d\r\n",iRet);
break;
case '1':
{
uint32 uiGapTime;
printf("Please enter the time between heartbeat intervals(0-2147483648):\r\n");
scanf("%d\r\n",&uiGapTime);
ucTemp2 = getchar();
ucTemp2 -= '0';
printf("%d,%d\r\n",uiGapTime,ucTemp2);
iRet = tx_scanner_set_heartbeat_gap_time(uiGapTime,ucTemp2);
if(iRet < 0)
{
printf("tx_scanner_set_heartbeat_gap_time faill!!!\r\n");
}
break;
}
case '2':
iRet = tx_scanner_get_heartbeat_gap_time();
printf("tx_scanner_get_heartbeat_gap_time:%d\r\n",iRet);
break;
case '3':
{
uint32 uiAckTime;
printf("Please enter the time for the heartbeat to wait for a response(0-2147483648):\r\n");
scanf("%d\r\n",&uiAckTime);
ucTemp2 = getchar();
ucTemp2 -= '0';
printf("%d,%d\r\n",uiAckTime,ucTemp2);
iRet = tx_scanner_set_heartbeat_wait_ack_time(uiAckTime,ucTemp2);
if(iRet < 0)
{
printf("tx_scanner_set_heartbeat_wait_ack_time faill!!!\r\n");
}
break;
}
case '4':
iRet = tx_scanner_get_heartbeat_wait_ack_time();
printf("tx_scanner_get_heartbeat_wait_ack_time:%d\r\n",iRet);
break;
case '5':
iRet = tx_scanner_reset();
printf("tx_scanner_reset:%d\r\n",iRet);
break;
case '6':
ucTemp1 = getchar();
ucTemp1 -= '0';
printf("%d\r\n",ucTemp1);
iRet = tx_scanner_scan_sw(ucTemp1);
if(iRet > 0)
{
printf("tx_scanner_scan_sw fail!!!\r\n");
}
break;
case '7':
ucTemp1 = getchar();
ucTemp2 = getchar();
ucTemp1 -= '0';
ucTemp2 -= '0';
printf("%d,%d\r\n",ucTemp1,ucTemp2);
iRet = tx_scanner_cmd_setcode_sw(ucTemp1,ucTemp2);
if(iRet > 0)
{
printf("tx_scanner_cmd_setcode_sw fail!!!\r\n");
}
break;
case '8':
{
uint32 uiBeepType;
printf("Please enter the beep type(0-20):\r\n");
scanf("%d",&uiBeepType);
tx_scanner_play_beep((MP_BEEP_TYPE_E)uiBeepType);
}
break;
case 'm':
case 'M':
case '?':
tx_scanner_sdk_show_menu();
break;
case 'q':
case 'Q':
printf("quit\r\n");
return 0;
break;
default:
break;
}
}
return 0;
}
static uint32 s_uiDecodeCnt = 0;
static int32 tx_scanner_sdk_decode_data_cb(uint8 ucCodeType, uint8 *pBuf, uint32 uiBufLen)
{
printf("[%03d][%02d]len:%d,data:%s\r\n", ++s_uiDecodeCnt, ucCodeType, uiBufLen, pBuf);
}
static void tx_scanner_sdk_comm_state_cb_fun(uint8 ucState)
{
/**0:断开连接,1:连接**/
printf("scanner comm state:%d\r\n", ucState);
}
static void tx_scanner_sdk_show_menu(void)
{
printf("***************************MENU***************************\r\n");
printf("a:start decode\r\n");
printf("b:stop decode\r\n");
printf("c:no time decode start\r\n");
printf("d:get version info\r\n");
printf("e:get product info\r\n");
printf("f:set trigger mode; 0:LEVEL,1:PULSE,2:CONTINUOUS,3:AUTOSENS; save:0:no,1:yes.(eg:f01)\r\n");
printf("g:get trigger mode\r\n");
printf("h:set light LED; 0:working light,1:always off,2:always on; save:0:no,1:yes.(eg:h01)\r\n");
printf("i:get light LED\r\n");
printf("j:set focus state; 0:working light,1:always off,2:always on; save:0:no,1:yes.(eg:j01)\r\n");
printf("k:get fucus state\r\n");
printf("l:set en prefix; 0:OFF,1:ON; save:0:no,1:yes.(eg:l01)\r\n");
printf("n:get en prefix\r\n");
printf("o:set prefix; save:0:no,1:yes.(eg:o0)\r\n");
printf("p:get prefix length\r\n");
printf("r:set en suffix; 0:OFF,1:ON; save:0:no,1:yes.(eg:r01)\r\n");
printf("s:get en suffix\r\n");
printf("t:set suffix; save:0:no,1:yes.(eg:t0)\r\n");
printf("u:get suffix length\r\n");
printf("v:set once scan time(0-65536); save:0:no,1:yes.(eg:v01)\r\n");
printf("w:get once scan time\r\n");
printf("x:set beep volume(0-100); save:0:no,1:yes.(eg:x01)\r\n");
printf("y:get beep volume\r\n");
printf("z:set heartbeat type; 0:BAN,1:NO ACK,2:ACK; save:0:no,1:yes.(eg:z01)\r\n");
printf("0:get heartbeat type\r\n");
printf("1:set heartbeat gap time(0-2147483648); save:0:no,1:yes.(eg:101)\r\n");
printf("2:get heartbeat gap time\r\n");
printf("3:set heartbeat wait ack time(0-2147483648); save:0:no,1:yes.(eg:301)\r\n");
printf("4:get heartbeat wait ack time\r\n");
printf("5:reset\r\n");
printf("6:set scan sw; 0:unable,1:able\r\n");
printf("7:set setcode sw; 0:unable,1:able; save:0:no,1:yes.(eg:71)\r\n");
printf("8:set beep type(0-20)\r\n");
printf("?/m:more menu\r\n");
printf("q:quit\r\n");
printf("******************************************************\r\n");
}