Coding Motor Connection Check

Default VEX V5 C++ API has, at the very least, motor.installed() function to check if motor is connected. I am not sure if there are any accessible undocumented functions which could give you more information regarding port status.

Then, this may a bit to steep of a climb from the block code, but an alternative to the default V5 development environment is Pros, which provides extended API and has more functionality to test for connected device status (see VEX Generic Device C API (For Advanced Users) module | PROS for V5)

Over the years people have developed a number of V5 Motor Testers based on that API with source code available on GitHub: example 1, example 2, example 3