//object sender, EventArgs e /// <summary> /// Starts the OpenLoop Experiment by calling methods to create nessesary tasks and /// create/populate the double buffering system using for loading of continous outputs. /// </summary> /// <returns></returns> internal bool Start() { bool stimSetupFail = false; try { bool stimFileProvided = stimFid.Length > 0; bool digFileProvided = digFid.Length > 0; bool auxFileProvided = auxFid.Length > 0; #region check file paths // Make sure that the user provided a file of some sort if (!stimFileProvided && !digFileProvided && !auxFileProvided) { MessageBox.Show("You need to provide a *.olstim, *.oldig, and/or a *.olaux to use the open-loop stimulator."); stimSetupFail = true; return stimSetupFail; } // Make sure that the user has input a valid file path for the stimulation file if (stimFileProvided && !CheckFilePath(stimFid)) { MessageBox.Show("The *.olstim file provided does not exist"); stimSetupFail = true; return stimSetupFail; } // Make sure that the user has input a valid file path for the digital file if (digFileProvided && !CheckFilePath(digFid)) { MessageBox.Show("The *.oldig file provided does not exist"); stimSetupFail = true; return stimSetupFail; } // Make sure that the user has input a valid file path for the digital file if (auxFileProvided && !CheckFilePath(auxFid)) { MessageBox.Show("The *.olaux file provided does not exist"); stimSetupFail = true; return true; } #endregion // This task will govern the periodicity of DAQ circular-buffer loading so that // all digital and stimulus output from the system is hardware timed ConfigureCounter(); string masterLoad = buffLoadTask.COChannels[0].PulseTerminal;//"/"+Properties.Settings.Default.SigOutDev + "/ctr1"; // Set up stimulus output support if (stimFileProvided) { #region If the user provided a .olstim file if (!Properties.Settings.Default.UseStimulator) { MessageBox.Show("You must use configure your hardware to use NeuroRighter's Stimulator for this feature"); stimSetupFail = true; return stimSetupFail; } // Call configuration method //ConfigureStim(masterTask); // Create a File2Stim object and start to run the protocol via its methods if (useManStimWave) { stimProtocol = new File2Stim(stimFid, outputSampFreq, OUTPUT_BUFFER_SIZE, buffLoadTask, masterTask, masterLoad, debugger, guiWave, Properties.Settings.Default.stimRobust); stimProtocol.AlertAllFinished += new File2Stim.AllFinishedHandler(SetStimDone); stimProtocol.AlertAllFinished += new File2Stim.AllFinishedHandler(StopOpenLoopOut); } else { stimProtocol = new File2Stim(stimFid, outputSampFreq, OUTPUT_BUFFER_SIZE, buffLoadTask, masterTask, masterLoad, debugger, null, Properties.Settings.Default.stimRobust); stimProtocol.AlertAllFinished += new File2Stim.AllFinishedHandler(SetStimDone); stimProtocol.AlertAllFinished += new File2Stim.AllFinishedHandler(StopOpenLoopOut); } stimSetupFail = stimProtocol.Setup(); if (stimSetupFail) { return stimSetupFail; } stimProtocol.Start(); #endregion } else { stimDone = true; } // Set up AO/DO support if (digFileProvided || auxFileProvided) { #region If the user provided a .oldig or .olaux file if (!Properties.Settings.Default.UseSigOut) { MessageBox.Show("You must use configure your hardware to use A0/D0 to use this feature"); stimSetupFail = true; return stimSetupFail; } // If no file was provided, mark dig or aux outputs as completed if (!digFileProvided) { digDone = true; } if (!auxFileProvided) { auxDone = true; } //ConfigureAODO(digFileProvided, masterTask); //AuxBuffer ab = null; //DigitalBuffer db = null; //because both buffers need to know about eachother (for restarts), we need to build the pointers here and pass them down the procotols auxProtocol = new File2Aux(auxFid, outputSampFreq, OUTPUT_BUFFER_SIZE, buffLoadTask, masterTask, masterLoad, EVENTS_PER_BUFFER_LOAD, auxFileProvided, debugger, Properties.Settings.Default.stimRobust); auxProtocol.AlertAllFinished += new File2Aux.AllFinishedHandler(SetAuxDone); auxProtocol.AlertAllFinished += new File2Aux.AllFinishedHandler(SetDigDone); auxProtocol.AlertAllFinished += new File2Aux.AllFinishedHandler(StopOpenLoopOut); if (digFileProvided) { digProtocol = new File2Dig(digFid, outputSampFreq, OUTPUT_BUFFER_SIZE, buffLoadTask, masterTask, masterLoad, EVENTS_PER_BUFFER_LOAD, debugger, Properties.Settings.Default.stimRobust ); digProtocol.connectBuffer(auxProtocol.refBuffer()); auxProtocol.connectBuffer(digProtocol.refBuffer()); digProtocol.Setup(); auxProtocol.Setup(digProtocol.numBuffLoadsRequired); } else auxProtocol.Setup(ulong.MaxValue); auxProtocol.Start(); #endregion } else { digDone = true; auxDone = true; } // Start the master load syncing task which you have attached buffer-refill methods to buffLoadTask.Start(); // Made it through start stimSetupFail = false; return stimSetupFail; } catch(Exception e) { KillTasks(); try { digProtocol.Stop(); } catch (Exception me) { } try { auxProtocol.Stop(); } catch (Exception me) { } try { stimProtocol.Stop(); } catch (Exception me) { } MessageBox.Show("Could not make it through OpenLoopOut.Start(): \n" + e.Message); stimSetupFail = true; return stimSetupFail; } }
/// <summary> /// Starts the OpenLoop Experiment by calling methods to create nessesary tasks and /// create/populate the double buffering system using for loading of continous outputs. /// </summary> /// <returns></returns> internal bool Start() //object sender, EventArgs e { bool stimSetupFail = false; try { bool stimFileProvided = stimFid.Length > 0; bool digFileProvided = digFid.Length > 0; bool auxFileProvided = auxFid.Length > 0; #region check file paths // Make sure that the user provided a file of some sort if (!stimFileProvided && !digFileProvided && !auxFileProvided) { MessageBox.Show("You need to provide a *.olstim, *.oldig, and/or a *.olaux to use the open-loop stimulator."); stimSetupFail = true; return(stimSetupFail); } // Make sure that the user has input a valid file path for the stimulation file if (stimFileProvided && !CheckFilePath(stimFid)) { MessageBox.Show("The *.olstim file provided does not exist"); stimSetupFail = true; return(stimSetupFail); } // Make sure that the user has input a valid file path for the digital file if (digFileProvided && !CheckFilePath(digFid)) { MessageBox.Show("The *.oldig file provided does not exist"); stimSetupFail = true; return(stimSetupFail); } // Make sure that the user has input a valid file path for the digital file if (auxFileProvided && !CheckFilePath(auxFid)) { MessageBox.Show("The *.olaux file provided does not exist"); stimSetupFail = true; return(true); } #endregion // This task will govern the periodicity of DAQ circular-buffer loading so that // all digital and stimulus output from the system is hardware timed ConfigureCounter(); string masterLoad = buffLoadTask.COChannels[0].PulseTerminal;//"/"+Properties.Settings.Default.SigOutDev + "/ctr1"; // Set up stimulus output support if (stimFileProvided) { #region If the user provided a .olstim file if (!Properties.Settings.Default.UseStimulator) { MessageBox.Show("You must use configure your hardware to use NeuroRighter's Stimulator for this feature"); stimSetupFail = true; return(stimSetupFail); } // Call configuration method //ConfigureStim(masterTask); // Create a File2Stim object and start to run the protocol via its methods if (useManStimWave) { stimProtocol = new File2Stim(stimFid, outputSampFreq, OUTPUT_BUFFER_SIZE, buffLoadTask, masterTask, masterLoad, debugger, guiWave, Properties.Settings.Default.stimRobust); stimProtocol.AlertAllFinished += new File2Stim.AllFinishedHandler(SetStimDone); stimProtocol.AlertAllFinished += new File2Stim.AllFinishedHandler(StopOpenLoopOut); } else { stimProtocol = new File2Stim(stimFid, outputSampFreq, OUTPUT_BUFFER_SIZE, buffLoadTask, masterTask, masterLoad, debugger, null, Properties.Settings.Default.stimRobust); stimProtocol.AlertAllFinished += new File2Stim.AllFinishedHandler(SetStimDone); stimProtocol.AlertAllFinished += new File2Stim.AllFinishedHandler(StopOpenLoopOut); } stimSetupFail = stimProtocol.Setup(); if (stimSetupFail) { return(stimSetupFail); } stimProtocol.Start(); #endregion } else { stimDone = true; } // Set up AO/DO support if (digFileProvided || auxFileProvided) { #region If the user provided a .oldig or .olaux file if (!Properties.Settings.Default.UseSigOut) { MessageBox.Show("You must use configure your hardware to use A0/D0 to use this feature"); stimSetupFail = true; return(stimSetupFail); } // If no file was provided, mark dig or aux outputs as completed if (!digFileProvided) { digDone = true; } if (!auxFileProvided) { auxDone = true; } //ConfigureAODO(digFileProvided, masterTask); //AuxBuffer ab = null; //DigitalBuffer db = null; //because both buffers need to know about eachother (for restarts), we need to build the pointers here and pass them down the procotols auxProtocol = new File2Aux(auxFid, outputSampFreq, OUTPUT_BUFFER_SIZE, buffLoadTask, masterTask, masterLoad, EVENTS_PER_BUFFER_LOAD, auxFileProvided, debugger, Properties.Settings.Default.stimRobust); auxProtocol.AlertAllFinished += new File2Aux.AllFinishedHandler(SetAuxDone); auxProtocol.AlertAllFinished += new File2Aux.AllFinishedHandler(SetDigDone); auxProtocol.AlertAllFinished += new File2Aux.AllFinishedHandler(StopOpenLoopOut); if (digFileProvided) { digProtocol = new File2Dig(digFid, outputSampFreq, OUTPUT_BUFFER_SIZE, buffLoadTask, masterTask, masterLoad, EVENTS_PER_BUFFER_LOAD, debugger, Properties.Settings.Default.stimRobust ); digProtocol.connectBuffer(auxProtocol.refBuffer()); auxProtocol.connectBuffer(digProtocol.refBuffer()); digProtocol.Setup(); auxProtocol.Setup(digProtocol.numBuffLoadsRequired); } else { auxProtocol.Setup(ulong.MaxValue); } auxProtocol.Start(); #endregion } else { digDone = true; auxDone = true; } // Start the master load syncing task which you have attached buffer-refill methods to buffLoadTask.Start(); // Made it through start stimSetupFail = false; return(stimSetupFail); } catch (Exception e) { KillTasks(); try { digProtocol.Stop(); } catch (Exception me) { } try { auxProtocol.Stop(); } catch (Exception me) { } try { stimProtocol.Stop(); } catch (Exception me) { } MessageBox.Show("Could not make it through OpenLoopOut.Start(): \n" + e.Message); stimSetupFail = true; return(stimSetupFail); } }