Updated 2015-01-28 02:42:33 by APN

The following examples require Twapi 4.1a15 or later.

Enumerating devices and their properties edit

We first need to get a device information set containing the devices of interest
(tcl) 66 % set hdevset [devinfoset -pnpenumerator USB -presentonly 1]
54267840 HDEVINFO

Leaving off the -pnpenumerator option will return entries for all device buses (actually enumerators).

The -presentonly option is set to true to indicate that only devices that are actually plugged in should be included.

We then retrieve the device instance identifiers for all devices in the set.
(tcl) 67 % set device_instances [devinfoset_instance_ids $hdevset]
{USB\VID_0781&PID_5571\4C532000030115118234} {USB\VID_04F2&PID_B2E1&MI_00\7&210D64C0&0&0000} {USB\ROOT_HUB30\4&D858888&0&0} {USB\VID_8087&PID_0024\5&1A59D89A&0&1} {USB\VID_0A81&PID_0205\7&304D57C3&0&1} {USB\VID_05E3&PID_0604\6&2CAE7568&0&4} {USB\VID_0A81&PID_0205&MI_00\8&29195F3B&0&0000} {USB\ROOT_HUB20\4&2BE5801C&0} {USB\VID_8087&PID_07DA\6&2E2F5DEF&0&3} {USB\VID_04F2&PID_B2E1\6&2E2F5DEF&0&1} {USB\VID_8087&PID_0024\5&294335C8&0&1} {USB\VID_0A81&PID_0205&MI_01\8&29195F3B&0&0001} {USB\VID_045E&PID_00F6\7&304D57C3&0&3} {USB\ROOT_HUB20\4&14C1C731&0}

We can then retrieve properties for each device instance.
(tcl) 68 % foreach inst $device_instances {
   set develem [devinfoset_element $hdevset $inst]
   puts "$inst -> [devinfoset_element_registry_property $hdevset $develem devicedesc]"
USB\VID_0781&PID_5571\4C532000030115118234 -> USB Mass Storage Device
USB\VID_04F2&PID_B2E1&MI_00\7&210D64C0&0&0000 -> Lenovo EasyCamera
USB\ROOT_HUB30\4&D858888&0&0 -> USB Root Hub (xHCI)
USB\VID_8087&PID_0024\5&1A59D89A&0&1 -> Generic USB Hub
USB\VID_0A81&PID_0205\7&304D57C3&0&1 -> USB Composite Device
USB\VID_05E3&PID_0604\6&2CAE7568&0&4 -> Generic USB Hub
USB\VID_0A81&PID_0205&MI_00\8&29195F3B&0&0000 -> USB Input Device
USB\ROOT_HUB20\4&2BE5801C&0 -> USB Root Hub
USB\VID_8087&PID_07DA\6&2E2F5DEF&0&3 -> Intel(R) Centrino(R) Wireless Bluetooth(R) 4.0 + High Speed Adapter
USB\VID_04F2&PID_B2E1\6&2E2F5DEF&0&1 -> USB Composite Device
USB\VID_8087&PID_0024\5&294335C8&0&1 -> Generic USB Hub
USB\VID_0A81&PID_0205&MI_01\8&29195F3B&0&0001 -> USB Input Device
USB\VID_045E&PID_00F6\7&304D57C3&0&3 -> Microsoft Hardware USB Mouse
USB\ROOT_HUB20\4&14C1C731&0 -> USB Root Hub

We have to release associated resources when done with the device information set.
(tcl) 69 % devinfoset_close $hdevset

Forcing a device rescan edit

The rescan_devices command will force the system to rescan for new hardware. The command takes no arguments.