It is currently April 26th, 2024, 4:00 pm

Detecting a USB device (specifically, a webcam)

Get help with creating, editing & fixing problems with skins
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: Detecting a USB device (specifically, a webcam)

Post by jn_meter »

Thanks everyone for your help. However, I fear I need more help. Here's why.

Code: Select all

wmic path CIM_LogicalDevice where "Description like 'USB%'" get /value
produced (among much other stuff) the following information about my webcam.

Caption=USB2.0 PC CAMERA
ClassGuid={6bdd1fc6-810f-11d0-bec7-08002be2092f}
CompatibleID={"USB\Class_0e&SubClass_03&Prot_00","USB\Class_0e&SubClass_03","USB\Class_0e"}
ConfigManagerErrorCode=0
ConfigManagerUserConfig=FALSE
CreationClassName=Win32_PnPEntity
Description=USB Video Device
DeviceID=USB\VID_18EC&PID_3299&MI_00\6&14F3076D&2&0000
ErrorCleared=
ErrorDescription=
HardwareID={"USB\VID_18EC&PID_3299&REV_0100&MI_00","USB\VID_18EC&PID_3299&MI_00"}
InstallDate=
LastErrorCode=
Manufacturer=Microsoft
Name=USB2.0 PC CAMERA
PNPDeviceID=USB\VID_18EC&PID_3299&MI_00\6&14F3076D&2&0000
PowerManagementCapabilities=
PowerManagementSupported=
Service=usbvideo
Status=OK
StatusInfo=
SystemCreationClassName=Win32_ComputerSystem
SystemName=PC

The challenge I have now is (1) how to find the wmic command that queries the above data, or rather only the 'Caption' value and tells me whether it matches a certain string (viz, 'USB2.0 PC CAMERA'). Or, better: I want (2) a way of searching all my - connected! - USB devices for the string.

Any ideas? The wmic syntax looks forbidding. Also, task 2 might require a Powershell or DOS or Virtual Basic script . .
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Detecting a USB device (specifically, a webcam)

Post by jsmorley »

Try this:

wmic path CIM_LogicalDevice where Caption="USB2.0 PC CAMERA" get status

Hopefully, it will simply return a single "OK".
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: Detecting a USB device (specifically, a webcam)

Post by jn_meter »

Brilliant. It works! Ta greatly. This has been much easier than I thought.

Here's the working stretch of code.

Code: Select all

; ___________________________________
;
; 	Webcam - styles, measures & meter
; ___________________________________


[style_cam_init]
String="cam_undetermined"
ToolTipType=0
ToolTipIcon="Info"
ToolTipText="Webcam - checking status . ."

[style_cam_on]
ToolTipType=0
ToolTipIcon="Warning"
ToolTipText="Webcam ON"

[style_cam_off]
ToolTipType=0
ToolTipIcon="Info"
ToolTipText="Webcam OFF"

[measure_command_camStatus]
Measure=PLUGIN
Plugin=RunCommand
Program=wmic
Parameter=path CIM_LogicalDevice where Caption="USB2.0 PC CAMERA" get status
OutputType=ANSI
State=Hide
Timeout=3500
IfMatch=.*OK
IfMatchAction=[!SetOption measure_camStatus String "cam_on"] [!SetOption meter_camStatus MeterStyle "style_cam_on"] [!Redraw]
IfMatch2=.*No Instance
IfMatchAction2=[!SetOption measure_camStatus String "cam_off"] [!SetOption meter_camStatus MeterStyle "style_cam_off"] [!Redraw]
; Use IfMatch, IfMatch2 because using IfNotMatch produces strange results, on account of IfMatch commands running before there is any output for them to run on.

[measure_camStatus]
Measure=String
String="cam_undetermined"
UpdateDivider=13.5
OnUpdateAction=[!CommandMeasure measure_command_camStatus" "Run"]

[meter_camStatus]
Meter=Image
ImagePath=#@#Images\
MeasureName=measure_camStatus
MeterStyle=style_cam_init
; NB: When a MeasureName is defined within an image meter, the output of that meter determines the image name and path.
AntiAlias=1
SolidColor=#transparentBackgroundCol#
X=59r
Y=2
W=39
H=31
And here is a screenshot in which a blobbly yellow arrow that I've superimposed shows the icon that shows the camera is connected: https://imgur.com/a/OpYcq (sorry for the ugly linking; I don't know how to use the markup this page uses).
jn_meter
Posts: 136
Joined: December 27th, 2016, 12:04 pm

Re: Detecting a USB device (specifically, a webcam)

Post by jn_meter »

The only problem now is that, having done it on windows, I'm going to want to do it on 'Conky' on Linux, too . . ;-)
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Detecting a USB device (specifically, a webcam)

Post by jsmorley »

Good deal!