internal IISZapper(int phaseWidth, double amplitude, int channel, int numPulses, double rate,
            Task stimDigitalTask, Task stimAnalogTask, DigitalSingleChannelWriter stimDigitalWriter,
            AnalogMultiChannelWriter stimAnalogWriter, double deviceRefreshRate, NeuroRighter sender)
        {
            const int prePadding = 100;
            const int postPadding = 100;

            const double offsetVoltage = 0.0;
            const int interPhaseLength = 0;

            this.stimDigitalTask = stimDigitalTask;
            this.stimDigitalWriter = stimDigitalWriter;
            this.stimAnalogTask = stimAnalogTask;
            this.stimAnalogWriter = stimAnalogWriter;
            this.channel = channel - 1;

            sp = new StimPulse(phaseWidth, phaseWidth, amplitude, -amplitude, channel,
                numPulses, rate, offsetVoltage, interPhaseLength, prePadding, postPadding, true);

            stimAnalogTask.Timing.SamplesPerChannel = numPulses * sp.analogPulse.GetLength(1);
            stimDigitalTask.Timing.SamplesPerChannel = numPulses * sp.digitalData.GetLength(0);

            totalNumReadsTraining = (int)(numSecondsTraining / deviceRefreshRate);
            totalNumReadsRefractory = (int)(refractory / deviceRefreshRate);
            numReadsRefractory = totalNumReadsRefractory;
        }
Beispiel #2
0
 internal void Grab(DataSrv DatSrv, StimSrv StimSrv, Logger Debugger, string NRFilePath, bool NRRecording, NeuroRighter NR)
 {
     this.NRDataSrv   = DatSrv;
     this.NRStimSrv   = StimSrv;
     this.debugger    = Debugger;
     this.nrFilePath  = NRFilePath;
     this.nrRecording = NRRecording;
     this.NR          = NR;//we need a reference back to NR to initiate the stop sequence
 }
Beispiel #3
0
 internal ClosedLoopOut(NRTask CLE, int fs, DataSrv DatSrv, StimSrv StimSrv, Task buffLoadTask, Logger Debugger, string NRFilePath, bool NRRecording, NeuroRighter NR)
 {
     this.CLE            = CLE;
     this.outputSampFreq = fs;
     this.DatSrv         = DatSrv;
     this.StimSrv        = StimSrv;
     this.useManStimWave = false;
     this.buffLoadTask   = buffLoadTask;
     this.Debugger       = Debugger;
     this.NRFilePath     = NRFilePath;
     this.NRRecording    = NRRecording;
     this.NR             = NR;
 }
Beispiel #4
0
        private void IISDetector(object sender, double[][] lfpData, int numReads)
        {
            if (!isTraining)
            {
                if (numReadsRefractory >= totalNumReadsRefractory)
                {
                    for (int i = 0; i < lfpData[channel].Length; ++i)
                    {
                        if (lfpData[channel][i] > threshold)
                        {
                            zap();
                            numReadsRefractory = 1;

#if (USE_LOG_FILE)
                            NeuroRighter nr = (NeuroRighter)sender;
                            //nr.logFile.WriteLine("Zap trigger at index, buffer read (buffer length): " + i + " " + numReads + " (" + lfpData[channel].Length + ")");
                            nr.logFile.Write(((i / 2000.0) + numReads * 0.003).ToString() + " ");
#endif

                            break; //automatically stop checking, supposing we're in refractory
                            //this will break down if the device refresh rate is long
                        }
                    }
                }
                else
                {
                    ++numReadsRefractory;
                }
            }
            else
            {
                threshold += NeuroRighter.rootMeanSquared(lfpData[channel]);
                if (++numReadsTraining >= totalNumReadsTraining)
                {
                    isTraining = false;
                    threshold /= totalNumReadsTraining;
                    threshold *= thresholdMult;
                }
            }
        }
Beispiel #5
0
        private const double refractory         = 1; // in seconds

        internal IISZapper(int phaseWidth, double amplitude, int channel, int numPulses, double rate,
                           Task stimDigitalTask, Task stimAnalogTask, DigitalSingleChannelWriter stimDigitalWriter,
                           AnalogMultiChannelWriter stimAnalogWriter, double deviceRefreshRate, NeuroRighter sender)
        {
            const int prePadding  = 100;
            const int postPadding = 100;

            const double offsetVoltage    = 0.0;
            const int    interPhaseLength = 0;

            this.stimDigitalTask   = stimDigitalTask;
            this.stimDigitalWriter = stimDigitalWriter;
            this.stimAnalogTask    = stimAnalogTask;
            this.stimAnalogWriter  = stimAnalogWriter;
            this.channel           = channel - 1;

            sp = new StimPulse(phaseWidth, phaseWidth, amplitude, -amplitude, channel,
                               numPulses, rate, offsetVoltage, interPhaseLength, prePadding, postPadding, true);

            stimAnalogTask.Timing.SamplesPerChannel  = numPulses * sp.analogPulse.GetLength(1);
            stimDigitalTask.Timing.SamplesPerChannel = numPulses * sp.digitalData.GetLength(0);

            totalNumReadsTraining   = (int)(numSecondsTraining / deviceRefreshRate);
            totalNumReadsRefractory = (int)(refractory / deviceRefreshRate);
            numReadsRefractory      = totalNumReadsRefractory;
        }
Beispiel #6
0
 internal void stop(NeuroRighter sender)
 {
     sender.IISDetected -= new NeuroRighter.IISDetectedHandler(IISDetector);
 }
 internal void stop(NeuroRighter sender)
 {
     sender.IISDetected -= new NeuroRighter.IISDetectedHandler(IISDetector);
 }
Beispiel #8
0
 internal ClosedLoopOut(NRTask CLE, int fs, DataSrv DatSrv, StimSrv StimSrv, Task buffLoadTask, Logger Debugger, string NRFilePath, bool NRRecording, NeuroRighter NR, double[] standardWave)
     : this(CLE, fs, DatSrv, StimSrv, buffLoadTask, Debugger, NRFilePath, NRRecording, NR)
 {
     this.guiWave        = standardWave;
     this.useManStimWave = true;
 }