Switching to mode 'Offboard' is currently not possible. Check for a valid position estimate

I have not tried arming it via my code but I will try to see if I can replicate your issue. Are you also using two telemetry cables to a Linux based offboard computer?

Have you tried the settings listed at this link?
Problems connecting a Pixhawk 6c to a Raspberry Pi - #4 by JulianOes

I made those changes for both Telem2 and Telem3. Doing this and then running the code on my offboard computer let me see messages had gone through( by doing cout << message_id) and I could see position messages (LOCAL_POSITION_NED and ODOMETRY) being received by Mavlink Inspector in QGroundControl.

My next thought is to plot the test ratios as mentioned here: Using the ECL EKF | PX4 User Guide

and see if some of my data is coming through with too much noise or something.