현재 Ubuntu 10.10에 연결된 USB 장치 목록을 얻으 려하고 UDev 및 D-BUS를 사용하여 장치를 연결하거나 분리하는 것과 같은 변경 사항을 모니터링하려고합니다. D-BUS를 사용하여 프로그래밍을하는 것이 상당히 익숙합니다. 한 예를 보았습니다 : Linux : How to detect is usb keyboard is plugged and unplugged 하나만 HAL을 사용하고 HAL이 사용되지 않음을 알고 있습니다. 일부 작동 코드를 발견하고 조금 수정했으나 USB 스틱, 미디어 플레이어 또는 CD-ROM 장치와 같은 모든 장치 전용 저장 장치에서 작동하지 않습니다. 나는 모든 것을 마우스, 키보드, USB 카메라 충전기로 USB에 연결했으면 좋겠다. 내 프로그램에서 알기를 바란다. 이것은 기본적으로 내가 가지고있는 것입니다 (http://moserei.de/2010/01/08/accessing-devicekit-with-dbus-and-python.html) :USB 장치 UDev 및 D-BUS
import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop
def device_added_callback(device):
print 'Device %s was added' % (device)
def device_changed_callback(device):
print 'Device %s was changed' % (device)
#must be done before connecting to DBus
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
proxy = bus.get_object("org.freedesktop.UDisks",
"/org/freedesktop/UDisks")
iface = dbus.Interface(proxy, "org.freedesktop.UDisks.Device")
devices = iface.get_dbus_method('EnumerateDevices')()
print '%s' % (devices)
#addes two signal listeners
iface.connect_to_signal('DeviceAdded', device_added_callback)
iface.connect_to_signal('DeviceChanged', device_changed_callback)
#start the main loop
mainloop = gobject.MainLoop()
mainloop.run()
도움이 될 것입니다. 미리 감사드립니다. Calota Romeo
: 여기
이 UDisks의 예입니다 (나는이 코드를 정확히 찾고 일반 usb 처리기를 찾지 않았다.) iface = dbus.Interface (프록시, "org.freedesktop.UDisks.Device") to iface = dbus.Interface (proxy, "org.freedesktop.UDisks") 최소한 udisks 1.0.4가 사용됩니다. –