'''Script for on-line control of DAC outputs '''Declare variables View (App(3)); 'activate script view WindowVisible(0); 'and make it disappear Var var1; VAR var3; Var tick1, tick2, interval:=0.1, duration:=1, tick3, tick4, delaypulse:=1,D2 :=1, datafi%; interval:=interval*166666.67; duration:=duration*10000; 'duration is ok delaypulse:=delaypulse*10000; D2:=D2*10000; Var data%; 'raw data window handle Var pulse%; 'sequencer output file handle 'Var pulseoneduration%:=1; 'duration of pulse on channel 1 'Var pulseoneinterval%:=1; 'inter-pulse interval on ch 1 'Var pulseonerepeats%:=20000; 'number of pulses on ch 1 'Var pulsetwoduration%:=20; 'duration of pulse on channel 2 'Var pulsetwointerval%:=60; 'inter-pulse interval on ch 2 'Var pulsetworepeats%:=3; 'number of pulses on ch 2 Var cu,volt,dura,frequency,zahl; VAR microsex; microsex:=0.5; volt:=1; dura:=1; frequency:=1; zahl:=1000; 'SampleClear(); 'clear existing sampling config. View (App(1)); 'Hide toolbar and status bar to free up space WindowVisible(0); 'for data display View (App(2)); WindowVisible(0); pulse%:=FileOpen ("",2,0,"Please select and open the file threshold_pulse_voltage.pls"); 'open the sequence output file WindowVisible (0); '(which will be invisible) If pulse%<0 then Message ("Could not find threshold_pulse_voltage.pls in the C:\Spike\Sequence directory"); Endif;WindowVisible (0); '(which will be invisible) samplesequencer (FileName$()); 'make this sequence file the 'active one 'SampleTimePerAdc (5); 'increase ADC conversion speed to raise sampling rate 'SampleUsPerTime (5); 'SampleWaveform (1,0,1000); 'set up waveform sampling channels at 1000hz sample rate 'SampleWaveform (2,1,1000); '''Now set up a toolbar to make life easy for the user ToolbarSet (9, "Stop Pulse",stoppulse%); ToolbarSet (8,"Start",start%); 'create start button & link to a procedure ToolbarSet (7,"Write",writeenable%); 'write to disk enable button ToolbarSet (6,"Pause",pause%); 'write to disk disable ToolbarSet (5,"start pulses",dac0pulse%); 'fire DAC chan 0 'ToolbarSet (4,"Fire during Burst",fireduringburst%); 'fire DAC chan 0 'ToolbarSet (3,"Fire during entire Interburst",fireduringinterburst%); 'ToolbarSet (2,"Configure Parameters",pulseparameters%);'pulse configuration menu ToolbarSet (1,"Exit",abort%); 'quit (and close data file) button ToolbarEnable (-1,1); 'dim (disable) Write button to begin with Toolbar("Select option...",1023); 'activate toolbar and pop up message '''Note: the script does not continue beyond the toolbar code unless one of ' the procedures (functions) that are called returns the value 0. All ' functions return a 1 except the abort function. Halt; 'stop script NB. all following code is in procedures/functions 'that are called from the toolbar Func start%(); 'start up a data file recording datafi%:=FileNew(0,1); 'Open a new data file for sampling if datafi%<0 then Message("Unable to open new data file");Halt() endif; DrawMode(-1,2); 'Set event draw mode to lines Window(0,0,100,80); 'Make data window in top bit of screen XRange(0,10); ToolbarEnable(8,0); Return 1 'return to toolbar End; 'end of this function Func pause%(); 'function for disabling write-to-disk data%:=sampleOK%(); 'check that a data file is being sampled 'note that this is done by jumping to a function 'called sampleOK%. The function returns the 'variable data% which will be greater than 'zero if a sampling file exists If data%>0 then View (data%); 'disable writing to disk SampleWrite (0); ToolbarEnable (6,0); 'and disable/enable appropriate buttons ToolbarEnable (5,1); Else Message ("Active window must be a data file being sampled!"); Endif; Return 1; End; Func WriteEnable%(); 'reverse of last function for enabling data%:=sampleOK%(); 'data recording to disk If data%>0 then View (data%); SampleWrite (1); ToolbarEnable (5,0); ToolbarEnable (6,1); Else Message ("Active window must be a data file being sampled!"); Endif; Return 1; End; Func dac0pulse%() 'activate pulse sequence labelled '0 in 'ChanShow(1); 'HCursorDelete(-1); 'HCursorNew(1); 'Interact ("set horizontal Cursor",1023); 'volt:=input("give amplitude in volt",1); 'dura:=input("give duration of single pulse in ms",1); 'frequency:=input("give stimulus frequency in volt",1); 'zahl:=input("how many stimuli?",1000); 'cu:=HCursor(1); 'cu:=cu*(32767/5); DlgCreate ("Parameter menu",14,25,80,7); 'create box position and title DlgReal (1,"amplitude in volt",0,10); DlgReal (2,"duration of single pulse in ms",1,10); DlgReal (3,"stimulus frequency in Hz",1,500); DLGReal (4, "how many stimuli?",1,10000); DlgShow (volt, dura, frequency, zahl); dura:=dura/microsex-1;'adapt dura to the sequencer clock (0.5ms = 1 tick, example: 1ms/0.5 = 2 ticks, -1tick =0.5ticks plus 1 tick verarbeitung zum naechsten schritt = 1ms volt:=volt*429496500; 'adapt to full range of DAC output in sequencer (*65535*6553.6) frequency:=(1/frequency)*1000; 'in ms frequency:=frequency/microsex-1;'adapt frequency (=delay in ms) to the sequencer clock (0.5ms = 1 tick, example: 1ms/0.5 = 2 ticks, -1tick =0.5ticks plus 1 tick verarbeitung zum naechsten schritt = 1ms SampleSeqVar (1,volt); SampleSeqVar (2,dura); SampleSeqVar (3,frequency); SampleSeqVar (4,zahl); SampleKey ("0"); 'the sequence output file dura:=(dura+1)/2;'convert back volt:=volt/429496500; 'convert back frequency:=(frequency+1)/2;'back frequency:=1/(frequency/1000); 'back Return 1; End; Func abort%(); 'end script function data%:=sampleOK%(); If data%>0 then 'check that we have a sampling file View (data%); SampleStop(); 'stop sampling 'FileSave(); 'FileClose(); 'close file Endif; Return 0; End; Func sampleOK%() data%:=SampleHandle (0); 'data% is >0 if there is a sampling file active Return data% End; Func stoppulse%() SampleKey ("3"); Return 1; End;