Ejemplo n.º 1
0
        public void StartButtonClick(object sender, EventArgs e)
        //Clicking "Start" starts the timer and you can only start after you have selected a rat and locked it in
        {
            fillButton.Hide();
            SessionHasBegun = true;
            if (ratWasChosen)
            {
                if (recordButton.BackColor != Color.AliceBlue)
                {
                    MessageBox.Show(this, "Check if Cheetah is Recording Session", "Cheetah Recording", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                }
                string reply = "";
                if (!(mNetComClient.SendCommand("-PostEvent \"StartWM\" 0 0", ref reply)))
                {
                    MessageBox.Show(this, "Send command to server failed", "NetCom Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }
                else
                {
                    String[] parsedReplyString = reply.Split(' ');
                    if (0 < parsedReplyString.GetLength(0))
                    {
                        if (parsedReplyString[0].Equals("-1"))
                        {
                            MessageBox.Show(this, "Cheetah could not process your command.", "NetCom Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        }
                    }
                }
                startButton.ForeColor = Color.AliceBlue;

                _elapsed_time          = 0;
                Recording_Time.Enabled = true;
                updateTime();
                startPreSleep.Visible = false;
                stopPreSleep.Visible  = false;
                startButton.Enabled   = false;

                //Felix(The BackroundWorker)
                felix.DoWork             += listen_to_arduino;
                felix.RunWorkerCompleted += run_worker_completed;
                felix.RunWorkerAsync();
            }

            else
            {
                var ratWindow = new SelectRatWindow();
                ratWindow.StartPosition = FormStartPosition.CenterParent;
                ratWindow.ShowDialog();
            }

            try //sends a message to the UNO to reinitialize variables
            {
                var message = new char[1] {
                    'L'
                };
                serialPort.Write(message, 0, 1);
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        private void SelectButtonClick(object sender, EventArgs e)
        //When you click "Select" you lock in the rat number and info
        {
            cleanButton.Show();
            if (RatSelection.SelectedIndex >= 0)
            {
                selectButton.Hide();
                RatSelection.Hide();

                if (recordingStatus == true)
                {
                    startPreSleep.Show();
                    stopPreSleep.Show();
                }
                ephys.Show();
                startButton.Show();
                stopButton.Show();

                selectedRat        = true;
                saveButton.Enabled = true;

                if (RatSelection.Text == "New Rat")
                {
                    var rat_entry = new NewRat();
                    rat_entry.ShowDialog();
                    ratName.Add(newRatNo);
                    //Console.WriteLine($"The NEW RAT NO IS {newRatNo}");
                    name_to_age.Add(newRatNo, newRatAge);
                    name_to_session.Add(newRatNo, 0);

                    chosenRat = newRatNo;
                    ratSelectionLabel.Text = newRatNo;
                }
                else
                {
                    ratSelectionLabel.Text = $"{ratName[RatSelection.SelectedIndex]}";
                    chosenRat = ratName[RatSelection.SelectedIndex];
                }

                ageLabel.Text = name_to_age[chosenRat];

                sessionLabel.Text = name_to_session[chosenRat].ToString();

                CsvFiles.OpenSessionCsv(chosenRat);
                CsvFiles.OpenWriteToRatData();
                foreach (var ratname in name_to_age.Keys)
                {
                    if (ratname == chosenRat)
                    {
                        name_to_session[ratname]++;
                    }
                    CsvFiles.RatdataWriter.Write(
                        $"{ratname},{name_to_age[ratname]},{name_to_session[ratname]}\n");
                }
                sessionNumber = (name_to_session[chosenRat] - 1).ToString();
                CsvFiles.OpenTimestampCsv(chosenRat, sessionNumber);
                CsvFiles.TimestampCsv.Write("Feeder,Type,Timestamp\n");
                CsvFiles.RatdataClose();


                ratWasChosen = true;
                if (recordingStatus == true)
                {
                    string reply = "";


                    if (!(mNetComClient.SendCommand($"-ProcessConfigurationFile WMAZE_HALO_Ephys_Setup_{chosenRat}.cfg", ref reply)))
                    {
                        MessageBox.Show(this, "Send command to server failed", "NetCom Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                    else
                    {
                        String[] parsedReplyString = reply.Split(' ');
                        if (0 < parsedReplyString.GetLength(0))
                        {
                            if (parsedReplyString[0].Equals("-1"))
                            {
                                MessageBox.Show(this, "Cheetah could not process your command.", "NetCom Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                            }
                        }
                    }
                    if (!(mNetComClient.SendCommand($"-SetDataDirectory \"F:\\CurrentCheetahData\\{chosenRat}\\WM_{chosenRat}\\{dateLString}_Session{sessionNumber}\" ", ref reply)))
                    {
                        MessageBox.Show(this, "Send command to server failed", "NetCom Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                    else
                    {
                        String[] parsedReplyString = reply.Split(' ');
                        if (0 < parsedReplyString.GetLength(0))
                        {
                            if (parsedReplyString[0].Equals("-1"))
                            {
                                MessageBox.Show(this, "Cheetah could not process your command.", "Cannot set Data Directory", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                            }
                        }
                    }

                    string folderPath = $"F:\\CurrentCheetahData\\{chosenRat}\\WM_{chosenRat}\\RawData\\{dateLString}_Session{sessionNumber}\\";
                    if (!Directory.Exists(folderPath))
                    {
                        Directory.CreateDirectory(folderPath);
                    }

                    if (!(mNetComClient.SendCommand($"-SetRawDataFile AcqSystem1 \"F:\\CurrentCheetahData\\{chosenRat}\\WM_{chosenRat}\\RawData\\{dateLString}_Session{sessionNumber}\\RawData.nrd \" ", ref reply)))
                    {
                        MessageBox.Show(this, "Send command to server failed", "NetCom Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                    else
                    {
                        String[] parsedReplyString = reply.Split(' ');
                        if (0 < parsedReplyString.GetLength(0))
                        {
                            if (parsedReplyString[0].Equals("-1"))
                            {
                                MessageBox.Show(this, "Cheetah could not process your command.", "NetCom Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                            }
                        }
                    }
                }

                ratbeingtested = ratName[RatSelection.SelectedIndex];
            }
        }