Short C++ program to display hardware config of teensy -- version, memory, whatever

I have a number of robots, some have teensy 3.1 and some have teensy 4.1. Can I write a “generic” C++ program that will work on any model and print out the model it is? And can I load and run that with platformio?

Don’t the Teensies have have different USB VID/PIDs that you can identify the connected USB devices with?

Yes but they are inside the robot. I am looking for a way to do it programmatically. When I use platformio to upload a new version of code the output from the loader does print info like:

PLATFORM: Teensy (5.0.0) > Teensy 4.1
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 7.75MB Flash

But I would like to be able to get that info as output from a C++ program that I write.

Well PlatformIO prints this “Blindly” based on what board = ... you have in the currently selected environment. It doesn’t actually enumerate the USB devices and ask them how much RAM and Flash they’re having. You could set board = teensy31 and it’ll still print that when a Teensy 4 is connected, but will later fail at the upload sketch.

If “a” Teensy is connected via USB, a simple Python or C/C++ program to just enumerate the USB devices and match their USB VIDs / PIDs against known one of the specific teensies will probably work fine.