detect if usb is plugged in python

Solutions on MaxInterview for detect if usb is plugged in python by the best coders in the world

showing results for - "detect if usb is plugged in python"
Gianluca
10 Jun 2018
1import pyudev
2context = pyudev.Context()
3monitor = Monitor.from_netlink()
4# For USB devices
5monitor.filter_by(susbsytem='usb')
6# OR specifically for most USB serial devices
7monitor.filter_by(susbystem='tty')
8for action, device in monitor:
9    vendor_id = device.get('ID_VENDOR_ID')
10    # I know the devices I am looking for have a vendor ID of '22fa'
11    if vendor_id in ['22fa']:
12        print 'Detected {} for device with vendor ID {}'.format(action, vendor_id)
13
Alessandro
24 Apr 2017
1import pyudev
2context = pyudev.Context()
3monitor = Monitor.from_netlink()
4# For USB devices
5monitor.filter_by(susbsytem='usb')
6# OR specifically for most USB serial devices
7monitor.filter_by(susbystem='tty')
8for action, device in monitor:
9    vendor_id = device.get('ID_VENDOR_ID')
10    # I know the devices I am looking for have a vendor ID of '22fa'
11    if vendor_id in ['22fa']:
12        print('Detected {} for device with vendor ID {}'.format(action, vendor_id))
13