private void SaveButtonClick(object sender, EventArgs e)
        //Hitting the save button saves the session info to SessionInfo_{rat#} as well as a screen shot of the GUI
        {
            if (ratWasChosen)
            {
                Show();
                saveButton.ForeColor = Color.DarkGray;
                saveButton.Enabled   = false;
                //notesReformatted =  notesBox.Text.Replace("," , ";");
                notes_behaviourReformatted = notesBox_behaviour.Text.Replace(",", ";");
                experimenterReformatted    = experimenterBox.Text.Replace(",", ";");


                CsvFiles.SessionCsv.Write(
                    $"{sessionLabel.Text},{experimenterReformatted},{DateTime.Now},{run_time},{correctNum.Text},{initialNum.Text},{outboundNum.Text},{inboundNum.Text},{repeatNum.Text},{totalErrNum.Text},{totalNum.Text},{notes_behaviourReformatted}\n");
                CsvFiles.Close();
                if (
                    !Directory.Exists(
                        $@"C:\Users\sahanasrivathsa\Documents\Barnes Lab\Wmaze\RatData\{ratName[RatSelection.SelectedIndex]}\ScreenShots"))
                {
                    Directory.CreateDirectory(
                        $@"C:\Users\sahanasrivathsa\Documents\Barnes Lab\Wmaze\RatData\{ratName[RatSelection.SelectedIndex]}\ScreenShots");
                }
                var bmpScreenCapture = new Bitmap(Width, Height);
                DrawToBitmap(bmpScreenCapture, new Rectangle(0, 0, bmpScreenCapture.Width, bmpScreenCapture.Height));
                bmpScreenCapture.Save(
                    $@"C:\Users\sahanasrivathsa\Documents\Barnes Lab\Wmaze\RatData\{ratName[RatSelection.SelectedIndex]}\ScreenShots\GUIscreenshot_{ratName
                        [RatSelection.SelectedIndex]}_Session{sessionNumber}.gif",
                    ImageFormat.Gif);


                saved = true;
            }
        }
Beispiel #2
0
        private void SaveButtonClick(object sender, EventArgs e)
        //Hitting the save button saves the session info to SessionInfo_{rat#} as well as a screen shot of the GUI
        {
            if (ratWasChosen)
            {
                Show();
                saveButton.ForeColor       = Color.DarkGray;
                saveButton.Enabled         = false;
                notesReformatted           = notesBox.Text.Replace(",", ";");
                notes_behaviourReformatted = notesBox_behaviour.Text.Replace(",", ";");
                experimenterReformatted    = experimenterBox.Text.Replace(",", ";");
                if (train)
                {
                    CsvFiles.trainingCsv.Write($"{DateTime.Now},{experimenterReformatted},{display_time.Text},{correctNum.Text},{notesReformatted},{notes_behaviourReformatted}\n");
                    CsvFiles.trainingCsv.Close();
                }
                else
                {
                    CsvFiles.SessionCsv.Write(
                        $"{sessionLabel.Text},{experimenterReformatted},{DateTime.Now},{run_time},{correctNum.Text},{initialNum.Text},{outboundNum.Text},{inboundNum.Text},{repeatNum.Text},{totalErrNum.Text},{totalNum.Text},{notesReformatted},{notes_behaviourReformatted}\n");
                    CsvFiles.Close();
                    if (
                        !Directory.Exists(
                            $@"C:\Users\akoutia\Documents\Barnes Lab\Wmaze\RatData\{ratName[RatSelection.SelectedIndex]}\ScreenShots"))
                    {
                        Directory.CreateDirectory(
                            $@"C:\Users\akoutia\Documents\Barnes Lab\Wmaze\RatData\{ratName[RatSelection.SelectedIndex]}\ScreenShots");
                    }
                    var bmpScreenCapture = new Bitmap(Width, Height);
                    DrawToBitmap(bmpScreenCapture, new Rectangle(0, 0, bmpScreenCapture.Width, bmpScreenCapture.Height));
                    bmpScreenCapture.Save(
                        $@"C:\Users\akoutia\Documents\Barnes Lab\Wmaze\RatData\{ratName[RatSelection.SelectedIndex]}\ScreenShots\GUIscreenshot_{ratName
                            [RatSelection.SelectedIndex]}_Session{sessionNumber}.gif",
                        ImageFormat.Gif);
                }
                saved = true;


                if (
                    File.Exists(
                        $@"C:\Users\akoutia\Documents\Barnes Lab\Wmaze\Videos\Composite_{year}{month}{day}_{hour}{minute}"))
                {
                    if (
                        !Directory.Exists(
                            $@"C:\Users\akoutia\Documents\Barnes Lab\Wmaze\Videos\{RatSelection.SelectedIndex}"))
                    {
                        Directory.CreateDirectory(
                            $@"C:\Users\akoutia\Documents\Barnes Lab\Wmaze\Videos\{RatSelection.SelectedIndex}");
                    }

                    File.Move(
                        $@"C:\Users\akoutia\Documents\Barnes Lab\Wmaze\RatData\Current Cohort Videos\Composite_(NTSC){year}{month}{day}_{hour}{minute}.ts",
                        $@"C:\Users\akoutia\Documents\Barnes Lab\Wmaze\RatData\Current Cohort Videos\{RatSelection.SelectedIndex}\{RatSelection.SelectedIndex}_{sessionLabel}.mpeg");
                }
            }
        }
        // private Window NeuraLynxWindow { get; }

        public W_Maze_Gui()
        {
            //Arduino Basic commands set and connected to port
            CsvFiles.OpenRatDataCsv(); //open RatData.csv so we can read from it and access Rat info
            serialPort.BaudRate        = 9600;
            serialPort.PortName        = "COM3";
            serialPort.ReadTimeout     = 10000;
            serialPort.Encoding        = Encoding.UTF8;
            serialPort.DiscardNull     = true;
            serialPort.WriteBufferSize = 10000;
            serialPort.Open();

            serialPort.DiscardInBuffer();
            serialPort.DiscardOutBuffer();



            while (!CsvFiles.RatdataReader.EndOfStream)
            //this reads the RatData.csv file and makes a dictionary for the ages and for the session number
            {
                var line = CsvFiles.RatdataReader.ReadLine();
                var vals = line.Split(',');
                name_to_age.Add(vals[0], vals[1]);
                name_to_session.Add(vals[0], int.Parse(vals[2]));
                ratName.Add(vals[0]);
            }
            CsvFiles.CloseRatDataCsv();

            //Initializes MNetcom to connect to NETCOM for ONLINE connection with CHEETAH
            mNetComClient = new MNetCom.MNetComClient();



            InitializeComponent();
            foreach (var rat in ratName)
            {
                this.RatSelection.Items.Add(rat);
            }
            this.RatSelection.Items.Add("New Rat");  //option to create new rat

            //Displays time and date on GUI window
            dateString         = DateTime.Now.ToShortDateString();
            dateLString        = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
            rat_datelabel.Text = DateTime.Now.ToShortDateString();
            rat_timelabel.Text = DateTime.Now.ToShortTimeString();



            //reminderWindow = new NLXReminder(this);
            //modeWindow = new appMode(this);
            //confirm();
            //if (recordingStatus == false) { ephys.Hide(); }
        }
Beispiel #4
0
        private void W_Maze_Gui_FormClosing(object sender, FormClosingEventArgs e)
        //Opens the exitConfirm form to ensure that you are purposefully exiting the GUI
        {
            if (!_exiting)
            {
                if (!saved)
                {
                    _exiting = true;
                    exitConfirm.StartPosition = FormStartPosition.CenterParent;
                    exitConfirm.ShowDialog();
                    e.Cancel = true;
                    _exiting = false;

                    if (train)
                    {
                        CsvFiles.trainingCsv.Close();
                    }

                    if (ratWasChosen && !train)
                    {
                        CsvFiles.OpenWriteToRatData();

                        foreach (var ratname in name_to_age.Keys)
                        {
                            if (ratname == ratbeingtested)
                            {
                                name_to_session[ratname]--;
                            }
                            CsvFiles.RatdataWriter.Write(
                                $"{ratname},{name_to_age[ratname]},{name_to_session[ratname]}\n");
                        }
                        CsvFiles.RatdataClose();
                        CsvFiles.Close();
                    }
                }
                else
                {
                    if (!train)
                    {
                        CsvFiles.RatdataClose();
                        CsvFiles.Close();
                    }
                    Environment.Exit(0);
                }
            }
        }
Beispiel #5
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];
            }
        }
Beispiel #6
0
        public W_Maze_Gui()
        {
            CsvFiles.OpenRatDataCsv(); //open RatData.csv so we can read from it and access Rat info
            serialPort.BaudRate        = 9600;
            serialPort.PortName        = "COM3";
            serialPort.ReadTimeout     = 10000;
            serialPort.Encoding        = Encoding.UTF8;
            serialPort.DiscardNull     = true;
            serialPort.WriteBufferSize = 10000;
            serialPort.Open();

            serialPort.DiscardInBuffer();
            serialPort.DiscardOutBuffer();

            while (!CsvFiles.RatdataReader.EndOfStream)
            //this reads the RatData.csv file and makes a dictionary for the ages and for the session number
            {
                var line = CsvFiles.RatdataReader.ReadLine();
                var vals = line.Split(',');
                name_to_age.Add(vals[0], vals[1]);
                name_to_session.Add(vals[0], int.Parse(vals[2]));
                ratName.Add(vals[0]);
            }
            CsvFiles.CloseRatDataCsv();

            mNetComClient = new MNetCom.MNetComClient();



            InitializeComponent();
            foreach (var rat in ratName)
            {
                RatSelection.Items.Add(rat);
            }
            reminderWindow = new NLXReminder(this);
            //modeWindow = new appMode(this);
            confirm();
            NeuraLynxWindow = Desktop.Instance.Windows().FirstOrDefault(w => w.Name.Contains("Neuralynx"));
        }
        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];
            }
        }