Exemple #1
0
        public async void RunTrial()
        {
            TrialStart?.Invoke(this, _TrialLoop.CurrentIteration);
            _Status = StatusType.TrialDelay;
            try
            {
                await TrialDelay.RunAsync(CancelToken);

                if (!CancelToken.IsCancellationRequested)
                {
                    CurrentState = StartState;
                    ScriptMachineEventArgs e = new ScriptMachineEventArgs(StartState);
                    ScriptStart?.Invoke(this, e);
                    _MazeDataPoint         = new MazeDataPoint(CurrentState.Name);
                    _MazeDataPoint.Session = _SessionLoop.CurrentIteration;
                    _MazeDataPoint.Trial   = _TrialLoop.CurrentIteration;
                    DataPointReady?.Invoke(this, _MazeDataPoint);
                    CurrentState.Activate();
                    _Status    = StatusType.Running;
                    _StartTime = DateTime.Now;
                }
                else
                {
                    TrialAborted?.Invoke(this, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                TrialAborted?.Invoke(this, new EventArgs());
            }
        }
Exemple #2
0
        private void State_StateCompleted(object sender, ScriptStateEventArgs e)
        {
            CurrentState = null;
            States.TryGetValue(e.NextState, out _CurrentState);
            if (CurrentState.Type == ScriptState.StateType.Complete)
            {
                Status   = StatusType.Completed;
                _EndTime = DateTime.Now;
                //_MazeDataPoint.Stop();
                //DataPointReady?.Invoke(this, _MazeDataPoint);
                //ScriptEnd?.Invoke(this, new ScriptEndEventArgs(true, RunTime));
                //CurrentState = StartState;
            }
            StateChanged?.Invoke(this, new ScriptMachineEventArgs(CurrentState));
            _MazeDataPoint.Stop();
            _MazeDataPoint.ExitAction = e.Condition.Label;
            //DataPointReady?.Invoke(this, _MazeDataPoint);
            _MazeDataPoint         = new MazeDataPoint(CurrentState.Name);
            _MazeDataPoint.Session = _SessionLoop.CurrentIteration;
            _MazeDataPoint.Trial   = _TrialLoop.CurrentIteration;
            DataPointReady?.Invoke(this, _MazeDataPoint);

            if (CurrentState.Type == ScriptState.StateType.Complete)
            {
                ScriptEnd?.Invoke(this, new ScriptEndEventArgs(true, RunTime));
                //CurrentState = StartState;

                if (_TrialLoop.Next() > 0)
                {
                    RunTrial();
                }
                else
                {
                    _TrialLoop.Reset();
                    if (_SessionLoop.Next() > 0)
                    {
                        RunSession();
                    }
                    else
                    {
                        SessionSetComplete?.Invoke(this, new EventArgs());
                    }
                }
            }
        }
Exemple #3
0
        private void SaveResults()
        {
            string Folder = Path.Combine(ResultsFolder, controlPanel1.CurrentScript);

            Directory.CreateDirectory(Folder);
            string Filename = $@"{Folder}\{controlPanel1.ResultsName}.csv";

            using (StreamWriter fs = new StreamWriter(Filename))
            {
                //var Str = JsonConvert.SerializeObject(mazeRunner1.MazeDataPoints, Formatting.Indented);
                //fs.Write(Str);
                fs.WriteLine(String.Join(",", MazeDataPoint.GetFields()));
                foreach (MazeDataPoint dp in mazeRunner1.MazeDataPoints)
                {
                    fs.WriteLine(dp.ToString());
                }
            }
        }
Exemple #4
0
 public MazeDataPoint AddDataPoint(MazeDataPoint dp)
 {
     MazeDataPoints.Add(dp);
     _CurrentDataPoint = dp;
     return(dp);
 }
Exemple #5
0
 private void ScriptFSM_DataPointReady(object sender, MazeDataPoint e)
 {
     e.Trial = CurrentTrial;
     DataPointReady?.Invoke(this, e);
 }
Exemple #6
0
 private void ScriptFSM_DataPointReady(object sender, MazeDataPoint e)
 {
     e.Session = CurrentSession;
     DataPointReady?.Invoke(this, e);
 }
Exemple #7
0
 private void AddMazeDataPoint(MazeDataPoint dp)
 {
     mazeRunner1.AddDataPoint(dp);
 }
Exemple #8
0
 private void ScriptFSM_DataPointReady(object sender, MazeDataPoint e)
 {
     mazeRunner1.BeginInvoke(new InvokeAddDataPoint(AddMazeDataPoint), new object[] { e });
 }