Your loop is too slow to get the samples before the buffer on the DAQ is overwritten. Do not wire the number of samples to read to the DAQ Timing function. You are limiting the buffer size with that. Other suspects include the writing the TDMS and the digital output with the DAQ Assistant. I would try to get rid of the DAQ Assistant and use the normal DAQmx VIs instead (setup before the loop, write inside of the loop, and close after the loop). If you are still too slow, then you should set up a Producer/Consumer to write to the TDMS file.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions Unofficial Forum Rules and Guidelines "Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5