Esempio n. 1
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();
                saveButton.Enabled     = true;
                ratSelectionLabel.Text = $"{ratName[RatSelection.SelectedIndex]}";
                var chosenRat = ratName[RatSelection.SelectedIndex];
                ageLabel.Text = name_to_age[chosenRat];
                if (train)
                {
                    sessionLabel.Text = "TRAINING";
                    CsvFiles.OpenTrainingCsv(chosenRat);
                }
                else
                {
                    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;
                ratbeingtested = ratName[RatSelection.SelectedIndex];
            }
        }
        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];
            }
        }