Hello NR users,
We currently use the NR to conduct closed-loop neural network training. But we have problems to deliver stimulation in the plugin.
Experiment condition:
A oscilloscope is connected to the Stim.out port of the interface board to capture stimulation.
Successful experiment:
1. Use the Mannual stim. panel to deliver stimulation. We can see correct waveform and timing in the oscilloscope.
2. Deliver stimulation in the Setup() in the plugin to deliver stimulation at several fixed time. We can see correct waveform and timing in the oscilloscope. Code is attached.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using NeuroRighter.Log;
using NeuroRighter.DataTypes;
using NeuroRighter.Network;
using NeuroRighter.NeuroRighterTask;
using NeuroRighter.Server;
using NeuroRighter.SpikeDetection;
namespace StimTest
{
public class Test : NRTask
{
double[] times = { 20, 25, 27 };
int[] channels = { 3, 7, 9 };
protected override void Setup()
{
double[] waveform = PredefinedWaveform;
double fs = NRStimSrv.SampleFrequencyHz;
List<StimulusOutEvent> stimuli = new List<StimulusOutEvent>();
for (int i = 0; i < times.Length; i++)
{
stimuli.Add(new StimulusOutEvent(channels[i], (ulong)(times[i] * fs), waveform));
}
NRStimSrv.StimOut.WriteToBuffer(stimuli);
Thread.Sleep(20000);
}
protected override void Cleanup()
{
Console.WriteLine("terminating protocal");
}
}
}
Failed exp:
When we try to deliver stimulation in a real-time manner in response to the neural spikes. We failed to use the NRStimSrv.StimOut.GetTime() function in the Loop(). Code is attached. And it should deliver stimulation rough every 7 s. However, no signal can been seen.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using NeuroRighter.DataTypes;
using NeuroRighter.NeuroRighterTask;
using NeuroRighter.Server;
namespace ResponsiveElectrodeLocating
{
class ResponsiveElectrodeLocating : NRTask
{
static int ChannelNum = 64;//Total channel number
static double Delay = 2;//Make sure the stimulation is delivered in the future
protected override void Setup()
{
Console.WriteLine("Starting plugin");
}
protected override void Loop(object sender, EventArgs e)
{
//A delay
Console.WriteLine("loop...");
Thread.Sleep(5000);
if (StimChannelNum < ChannelNum)//Run stimulation from channel 0 to ChannelNum (31 or 63), totally 32 or 64 channels
{
//Writing the stimulation buffer for output stimulation in the near future
NRStimSrv.StimOut.EmptyOuterBuffer();
List<StimulusOutEvent> Stimuli = new List<StimulusOutEvent>();
double[] WaveForm = PredefinedWaveform;
double StimFreq = NRStimSrv.SampleFrequencyHz;
double CurrentTime = NRStimSrv.StimOut.GetTime();
ulong StimTime = (ulong) ((CurrentTime / 1000 + Delay) * StimFreq);
Stimuli.Add(new StimulusOutEvent(StimChannelNum, StimTime, WaveForm));
NRStimSrv.StimOut.WriteToBuffer(Stimuli);
Console.WriteLine("Stimulation channel {0} at time {1} using predifined waveform in the UI", StimChannelNum, Time);
}
else
{
Console.WriteLine("All channels are stimulated. Please click STOP to quit the plugins.");
}
//Upadte stimulation channel
StimChannelNum = StimChannelNum + 1;
}
protected override void Cleanup()
{
Console.WriteLine("Quiting the plugins.\n");
}
}
}
Would anyone help me to troubleshoot? Thank you in advance!
Best,
Kai
Dr. Shi Peng's group
City University of Hong Kong, HK