Switching between two webcams on the dashboard

The USB0::0x… are the fully-qualified addresses that VISA and some other drivers will call the camera when they enumerate. The OS HID drivers use the same or a similar technique. This includes which USB controller, which hub, and which port on the hub the device is plugged into. It is unrelated to the USB 0 and USB 1 addresses that the WPILib camera stuff uses.

One way to get what you are asking for is for me to describe a bit more about the camera server that is inside of Send2PC. It is written to use only one port and one camera. But with a few small tweaks, you can make ones that will serve two cameras. Then you can decide which is paused and which is streaming.

If you start with the Vision Processing block diagram, there is a string of initialization functions to ensure the camera is in a predictable state, then this refnum forks and goes into the loop and goes to the Background Loop subVI. Open the Background subVI.

As the comment states, this subVI does one thing for IP cameras and another for USB cams. They were combined into one abstract background subVI, but have little interaction. The left-most camera function determines whether this is a USB camera or not. If it is USB, the only thing that executes is the Send2PC Loop. So lets open that one next.

Send2PC listens for a connection on port 1180. That is not a parameter, but a constant. So if you want two cameras, you probably want two ports. Once it has a dashboard connection, it sets up the camera, starts it, and loops acquiring and sending them to the port. This implements both the SW compression and HW compression options and has code for a two-port cRIO that requires the data be forwarded. But the important thing to notice is that this code uses an image named WPILib_SendtoPCImage to get the image from the camera. It wouldn’t be good to use the same image name for different cameras.

So. If you clone the Send2PC VI and make the image name and port be unique, you now have two camera servers. If you are using USB for both, don’t bother with the background loop, you can just drop your Send2PCA and B versions and wire up the parameters.

Some teams want two small simultaneous streams, and the customizations I’ve described should work for them. You wanted a switch. So I’d recommend you then add some pause/run code to the loops to leave both cameras open and on a unique port and control which is working and which is paused.

On the dashboard, you have a few edits to make as well. The vision loop listens on one port, stores to one AVI file, displays to one image display, etc. If you dig down inside the code, the important work happens in Get on PC. It opens and communicates on port 1180 and decodes transmitted data into your image. If you have two of these connected to the appropriate port, hint, make the port be a parameter, then you can leave both running and display the one the driver is interested in.

So, with a few edits, you can make variations of the Send and Get PC camera servers to do what you want. I believe some teams have made these changes in years past, so you may not need to make them yourself, but they aren’t that hard or risky.

I’m happy to answer questions.
Greg McKaskle