DONSEE东信智能 - 身份证社保卡读卡智能终端应用服务商

eastcoms@qq.com
400-6722-705
首页 > 服务支持专区 > 产品支持 > 常见问题

Python调用东信QR-M20二维码扫码模组示例

来源:www.eastcoms.com   标签:Python 扫码 二维码 模组   发布时间: 2024-9-18 8:59:20

Python语言开发采用东信QR-M20二维码模块,USB接口进行开发,调用了libdonseeQR.so 这个扫码的接口库。


import ctypes

from ctypes import *

import sys


# Define callback function types

tx_scanner_decode_data_cb_fun = CFUNCTYPE(c_int, c_ubyte, POINTER(c_ubyte), c_int)

tx_scanner_comm_state_cb_fun = CFUNCTYPE(None, c_ubyte)


# Load the DLL

tx_windows_hidpos = ctypes.CDLL("./tx_windows_hidpos.dll")


# Define function prototypes

tx_scanner_init = tx_windows_hidpos.tx_scanner_init

tx_scanner_init.restype = c_int


tx_scanner_get_version = tx_windows_hidpos.tx_scanner_get_version

tx_scanner_get_version.argtypes = [POINTER(c_ubyte), c_ubyte]

tx_scanner_get_version.restype = c_int


tx_scanner_decode_data_fun_register = tx_windows_hidpos.tx_scanner_decode_data_fun_register

tx_scanner_decode_data_fun_register.argtypes = [tx_scanner_decode_data_cb_fun]

tx_scanner_decode_data_fun_register.restype = c_int


tx_scanner_comm_state_fun_register = tx_windows_hidpos.tx_scanner_comm_state_fun_register

tx_scanner_comm_state_fun_register.argtypes = [tx_scanner_comm_state_cb_fun]

tx_scanner_comm_state_fun_register.restype = c_int


s_uiDecodeCnt = 0


@tx_scanner_decode_data_cb_fun

def tx_scanner_sdk_decode_data_cb(ucCodeType, pBuf, uiBufLen):

    global s_uiDecodeCnt

    return 0


@tx_scanner_comm_state_cb_fun

def tx_scanner_sdk_comm_state_cb_fun(ucState):

    print(f"scanner usb hidpos state:{ucState}")


def tx_scanner_sdk_show_menu():

    print("***************************东信QR-M20二维模组Test***************************")

    print("q:quit")

    print("******************************************************")


def main():

    ucVer = (c_ubyte * 128)()

    iRet = tx_scanner_get_version(ucVer, len(ucVer))

    if iRet > 0:

        strTemp = bytes(ucVer[:iRet]).decode('utf-8')

    print(f"DONSEE QR-M20 Linux python usb hidpos demo ver:{strTemp}")


    # Register decode data callback function

    tx_scanner_decode_data_fun_register(tx_scanner_sdk_decode_data_cb)


    # Register device connection state callback function

    tx_scanner_comm_state_fun_register(tx_scanner_sdk_comm_state_cb_fun)


    # Initialize

    iRet = tx_scanner_init()

    print(f"tx_scanner_init:{iRet}")

    print("q:quit")

    print("***********************东信QR-M20二维模组Test******************************")


    while True:

        cInput = input().lower()

        if cInput == 'q':

            print("quit")

            return


if __name__ == "__main__":

    main()


 

 
QQ在线咨询