python检查交换机端口状态_使用python检测连接到USB的交换机的状态

好的,我现在有了解决方案,我会发布它,但是我有一个问题…当我运行代码时,有时它会说设备正忙,它会产生一个错误,当它工作时。。。它会等待一个中断,但是如果你移动鼠标,它会在屏幕上保持静止,但会产生一个中断。同样可以说,点击一个按钮,它会产生一个中断,但鼠标将保持静止,要再次使用它,你需要把它从usb中取出,然后再放进去。在import usb.core

import usb.util

#import usb

# find our device

dev = usb.core.find(find_all=True)

#the second device it finds is my mouse

device = dev[2]

#print device

#physical device call: 5

#usb HID call: 3

_name = usb.util.get_string(device, 19, 1)

print _name

#we take the first configuration of the device

device.set_configuration()

print "Config set..."

#we access the configuration we've found

cfg = device.get_active_configuration()

#we access the intherface with number 0 and alternate setting with number 0

interface_number = cfg[(0,0)].bInterfaceNumber

alternate_setting = usb.control.get_interface(device,interface_number)

#we find the alterng settings for interface_number and altering_setting

intf = usb.util.find_descriptor(cfg, bInterfaceNumber = interface_number,\

bAlternateSetting = alternate_setting)

#Finds the first IN endpoint

ep = usb.util.find_descriptor(

intf,

# match the first IN endpoint

custom_match = \

lambda e: \

usb.util.endpoint_direction(e.bEndpointAddress) == \

usb.util.ENDPOINT_IN

)

#inorder for you to detect a state from the device, it has to be(for mouse, moved,

#clicked)

#otherwise it generates error

#make use of the error, if the mouse isn't pushed, do nothing and wait, if pushed...

#print the state

#and exit from the loop

print "Waiting for signal..."

#device.detach_kernel_driver(0)

#click of the scroll button has array('B', [4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

#0, 0]) signal

while True:

try:

print ep.read(16)

print "Received!"

break

except:

continue

#assert ep is not 0

#_name=device.ctrl_transfer(bmRequestType=33, bRequest=11, wValue=0x0300)

#print _name

所以我猜它会先删除鼠标的驱动程序,然后它会和设备对话,然后我点击一个按钮就会产生中断,然后……我怎么能说,再次使用你的驱动程序并结束程序……因为每次重新插入usb鼠标是不公正的。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值