python读取usb数据显示_如何使用python检测多个USB端口并从USB读取数据

我已经能够检测到任何时候插入闪存驱动器。但是,(听起来很傻)很难检测到是否插入了多个USB。

另外,我在编写从中读取数据的代码时遇到了困难。

有人能帮忙吗?

谢谢,提前

:)

P、 我的系统是windows 8 64位

整个过程是关于检测信号,我将从传感器中提取。在

这是检测USB的代码import string

from ctypes import windll

import time

import os

def get_drives():

drives = []

bitmask = windll.kernel32.GetLogicalDrives()

for letter in string.uppercase:

if bitmask & 1:

drives.append(letter)

bitmask >>= 1

return drives

if __name__ == '__main__':

before = set(get_drives())

pause = raw_input("Please insert the USB device, then press ENTER")

print ('Please wait...')

time.sleep(5)

after = set(get_drives())

drives = after - before

delta = len(drives)

if (delta):

for drive in drives:

if os.system("cd " + drive + ":") == 0:

newly_mounted = drive

print "There were %d drives added: %s. Newly mounted drive letter is %s" % (delta, drives, newly_mounted)

else:

print "Sorry, I couldn't find any newly mounted drives."

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值