“Erkennen Sie, ob USB in Python angeschlossen ist” Code-Antworten

Erkennen Sie, ob USB in Python angeschlossen ist

import pyudev
context = pyudev.Context()
monitor = Monitor.from_netlink()
# For USB devices
monitor.filter_by(susbsytem='usb')
# OR specifically for most USB serial devices
monitor.filter_by(susbystem='tty')
for action, device in monitor:
    vendor_id = device.get('ID_VENDOR_ID')
    # I know the devices I am looking for have a vendor ID of '22fa'
    if vendor_id in ['22fa']:
        print('Detected {} for device with vendor ID {}'.format(action, vendor_id))
Jittery Jellyfish

Erkennen Sie, ob USB in Python angeschlossen ist

import pyudev
context = pyudev.Context()
monitor = Monitor.from_netlink()
# For USB devices
monitor.filter_by(susbsytem='usb')
# OR specifically for most USB serial devices
monitor.filter_by(susbystem='tty')
for action, device in monitor:
    vendor_id = device.get('ID_VENDOR_ID')
    # I know the devices I am looking for have a vendor ID of '22fa'
    if vendor_id in ['22fa']:
        print 'Detected {} for device with vendor ID {}'.format(action, vendor_id)
Jittery Jellyfish

Ähnliche Antworten wie “Erkennen Sie, ob USB in Python angeschlossen ist”

Fragen ähnlich wie “Erkennen Sie, ob USB in Python angeschlossen ist”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen