| |
|
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
| -> Python知识库 -> python HID设备读写 -> 正文阅读 |
|
|
[Python知识库]python HID设备读写 |
|
? 1.安装HIDAPI的库 pip install hidapi 2.使用方法例子 # 查找USB HID设备 import hid for device_dict in hid.enumerate(): 运行结果: interface_number : -1 interface_number : -1 interface_number : -1 # 打开设备,读写,关闭设备 try:
print("Opening the device")
h = hid.device()
h.open(0x41F, 0x1233) # TREZOR VendorID/ProductID
print("Manufacturer: %s" % h.get_manufacturer_string())
print("Product: %s" % h.get_product_string())
print("Serial No: %s" % h.get_serial_number_string())
# # enable non-blocking mode
# h.set_nonblocking(1)
#
# # write some data to the device
# print("Write the data")
# h.write([0, 63, 35, 35] + [0] * 61)
#
# # wait
# time.sleep(0.05)
#
# # read back the answer
# print("Read the data")
# while True:
# d = h.read(64)
# if d:
# print(d)
# else:
# break
print("Closing the device")
h.close()
except IOError as ex:
print(ex)
print("You probably don't have the hard-coded device.")
print("Update the h.open() line in this script with the one")
print("from the enumeration list output above and try again.")
print("Done")
执行结果: Opening the device |
|
|
|
|
| 上一篇文章 下一篇文章 查看所有文章 |
|
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
| 360图书馆 购物 三丰科技 阅读网 日历 万年历 2025年12日历 | -2025/12/1 22:06:23- |
|
| 网站联系: qq:121756557 email:121756557@qq.com IT数码 |