How to detect missing camera

Is there a way to detect if the UsbCamera is present or not?

If we don’t have the camera plugged in and start a CameraServer, we get the periodic

CS: USB Camera 0: Connecting to USB camera on /dev/video0

Not a biggie, but trying to get the console noise down so we can see the important stuff. If we knew it wasn’t there, we wouldn’t do a


With your camera(s) plugged in, you can run this to discover static device paths (these won’t change between restarts, unlike /dev/video*):

ls -l /dev/v4l/by-path

You can use this in the startAutomaticCapture method:

CameraServer.getInstance().startAutomaticCapture("<name>", "/dev/v4l/by-path/...");

An alternative would be to setup a udev rule to automatically map those long (and ugly) paths to simple ones like “/dev/drivercamera” or “/dev/visioncamera”. I think these will be device-specific, so replacing a camera might require changing the udev rule; it may also be possible to make it USB-port specific. You’d have to do some research on that, if it’s the route you want to take

I’d guess you were more interested in this…

		  if (new File("/dev/video0").exists())

yepper, that’s where we landed.