Do generate a specific number of pulses, you'll have to use the trigger lines on whichever NI frame grabber you have. From there you can program a pulse train using the IMAQ Generate Pulse.vi. Call the VI, wait for a certain number of milliseconds (corresponding with 40 pulses), then call the IMAQ Generate Pulse.vi again to stop the output.
Please let me know if anyone knows of another way to do it.
Kyle V