1 Star 0 Fork 0

战鹏/python-serial

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 2.62 KB
一键复制 编辑 原始数据 按行查看 历史
战鹏 提交于 2024-07-09 19:24 . sechedule run at clock
import time
import schedule
import usb.util
outEndPoint = None
def findAll():
for dev in usb.core.find(find_all=True):
print(dev)
def findById():
device = usb.core.find(idVendor=0x5131, idProduct=0x2019)
print(str(type(device)) + ":" + str(device))
# ENDPOINT 0x81: Interrupt IN
# ENDPOINT 0x82: Interrupt IN
# ENDPOINT 0x83: Interrupt IN
# ENDPOINT 0x84: Interrupt IN
# ENDPOINT 0x4: Interrupt OUT
return device
def findOutEndpoint():
device = usb.core.find(idVendor=0x5131, idProduct=0x2019)
print(str(type(device)) + ":" + str(device))
# ENDPOINT 0x81: Interrupt IN
# ENDPOINT 0x82: Interrupt IN
# ENDPOINT 0x83: Interrupt IN
# ENDPOINT 0x84: Interrupt IN
# ENDPOINT 0x4: Interrupt OUT
configuration = device.get_active_configuration()
print(str(type(configuration)) + ":" + str(configuration))
# Iterate over all interfaces in this configuration
for interface_number in range(configuration.bNumInterfaces):
# Get the interface by its number
interface = configuration[(interface_number, 0)]
# Print interface details for demonstration
print(f"Interface {interface_number}:")
# print(f"\tNumber of endpoints: {len(interface)}")
print(f"\tInterface class: {interface.bInterfaceClass}")
print(f"\tInterface subclass: {interface.bInterfaceSubClass}")
print(f"\tInterface protocol: {interface.bInterfaceProtocol}")
# You can also iterate over the endpoints in this interface
for endpoint in interface:
print(f"\tEndpoint {endpoint.bEndpointAddress}:")
print(
f"\t\tDirection: {'IN' if usb.util.endpoint_direction(endpoint.bEndpointAddress) == usb.util.ENDPOINT_IN else 'OUT'}")
print(f"\t\tAttributes: {endpoint.wMaxPacketSize} bytes")
if usb.util.endpoint_direction(endpoint.bEndpointAddress) != usb.util.ENDPOINT_IN:
outEndPoint = endpoint
return endpoint
def deviceSendMessage(device, outendpoint,message):
device.write(0x4, message)
# def deviceReciveMessage(device, endpoint):
# devic
def task1():
print("Task1")
if __name__ == '__main__':
device = findById()
outEndPoint = findOutEndpoint()
print(outEndPoint)
# if device.is_kernel_driver_active(0):
# device.detach_kernel_driver(0)
message = b'\x01\x02\x03\x04'
deviceSendMessage(device, outEndPoint, message)
# schedule.every().day.at("10:00").do(task1())
# schedule.every().day.at("11:20").do(task1())
#
# # while True:
# # schedule.run_pending()
# # time.sleep(1)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/haishenshizi/python-serial.git
git@gitee.com:haishenshizi/python-serial.git
haishenshizi
python-serial
python-serial
master

搜索帮助