My first comment is a reiteration of something I previously stated. "Sample rate" and "Sampling rate" are terms used when dealing with analog INPUT. You are doing analog OUTPUT. When dealing with analog output, we use the term "update rate". This could be viewed as a triviality, but it has already caused one point of confusion, please let's try to be consistant.
While I did not mention it for simplicity sake, the buffer size does play a role as to how fast you can go. In fact, there is sort of an optimal range of buffer size, probably around 1000. If your buffer size is too small, too many small DMA transfers will be required. Your PC will fall behind and you will not be able to achieve even 500,000 S/s update rate.
The
[S/C] I spoke of corresponds to the waveform length in the Function Generator.vi you mentioned.
You will not be able to use the Function Generator.vi example as it was not designed to generate signals at the rates you are trying to achieve. It takes your waveform length (for a simple high-frequency square wave, let's say a waveform length of 2) and uses it for the buffer size, as well as the waveform data generated. What you need to use the optimal buffer size but still generate the proper data is to duplicate your data. So if you have two data points for your square wave, create an array of 1000 elements that are these two points repeated 500 times. Just remember that with buffered analog output, the first AO Write.vi should get an entire buffer worth of data, and each subsequent iteration should get a half a buffer's worth, in general, the first half followed by the second half.
I will not have time to look at your code or continue to follow up with this, but if you are st
ill having issues with this I would suggest contacting either the RT or DAQ support group at NI for further assistance if others on the message board do not answer your questions.