Scanners usually send pulses and these are needed to be recorded by the stimulus computer in order to solve this problem. In the specific setup I am using, these pulses are collected in a circuit, called cogent-box, and accumulated. This cumulated count is sent to the serial port of the stimulus computer in the form of 2 bytes. The stimulus program can now correctly time events from different sources e.g. stimulus onsets and the start of volume acquisitions.
The downside is generally that one would need to go to the scanner's console room and run few dummy experiments with the scanner until the presentation code is devoid of any bugs.
Once you have this software you can create a pair of virtual serial port, say COM1 and COM2. You can fire the Matlab, use COM2 and write information in the form of two bytes (to emulate what the cogent-box would be doing in response to pulses received from the scanner at each TR). These two bytes imitates the situation where the cogent-box is counting the number of volumes that have been so far acquired. In another instance of Matlab, running in parallel to the first one, you can set COM1 and read data from it. This will be analogous to the situation you are in the scanner room, without the need of a mobile cogent box or a scanner.
The following psychophysics toolbox function can be used to send pulses.
function SendPulses(N,TR) %function SendPulses(N) % %Sends N pulses to COM2 serial port. TR is the interpulse TR (that is %the "TR"). % %Selim Onat, 24-Jan-2013 10:55:53 IOPort('CloseAll') box.port = IOPort('OpenSerialPort', 'COM2'); counter = 0; % t = GetSecs;%now t = t:TR:t+TR*N;%time of the future pulses for n = 1:N tobesent = [floor(n./255) n];%two byte to be sent WaitSecs('untiltime',t(n));%wait and fire. [~,t_]=IOPort( 'Write' , box.port , [char(tobesent(1))+1,char(tobesent(2))]); counter = counter +1; fprintf('Pulse No: %3d sent at %0.10g was due to at %0.10g\n',counter,t_,t(n)); drawnow%give some time for Control-C end