protected void InitializeData()
    {
        nirsdata[0].stimulus = new List <nirs.Stimulus>();
        int cnt = 0;

        for (int i = 0; i < MainClass.devices.Length; i++)
        {
            cnt += nirsdata[i].probe.numChannels / nirsdata[i].probe.numWavelengths;
            nirsdata[i].data = new List <double> [nirsdata[i].probe.ChannelMap.Length];
            for (int ii = 0; ii < nirsdata[i].probe.ChannelMap.Length; ii++)
            {
                nirsdata[i].data[ii] = new List <double>();
            }
            nirsdata[i].time     = new List <double>();
            nirsdata[i].stimulus = nirsdata[0].stimulus;

            NIRSDAQ.info _info = MainClass.devices[i].GetInfo();
            nirsdata[i].auxillaries = new nirs.auxillary[_info.numAux];
            for (int ii = 0; ii < _info.numAux; ii++)
            {
                nirsdata[i].auxillaries[ii]            = new nirs.auxillary();
                nirsdata[i].auxillaries[ii].data       = new List <double>();
                nirsdata[i].auxillaries[ii].time       = new List <double>();
                nirsdata[i].auxillaries[ii].timeOffset = 0;
                nirsdata[i].auxillaries[ii].name       = string.Format("Aux-{0}", ii + 1);
            }
        }



        realtimeEngine = new RealtimeEngine();

        // Reset the stimulus information
        _handles.stimListStore.Clear();
    }
Esempio n. 2
0
            public info GetInfo()
            {
                info _info = new info();

                _info.DeviceName = devicename;
                switch (devicetype)
                {
                case 0:
                    _info.numDet         = ((NIRSDAQ.Instrument.Devices.Simulator)device).ndets();
                    _info.numSrc         = ((NIRSDAQ.Instrument.Devices.Simulator)device).nsrcs();
                    _info.numMeas        = ((NIRSDAQ.Instrument.Devices.Simulator)device).nmeas();
                    _info.numAux         = ((NIRSDAQ.Instrument.Devices.Simulator)device).naux();
                    _info.PortName       = ((NIRSDAQ.Instrument.Devices.Simulator)device).portname();
                    _info.Manufacturer   = ((NIRSDAQ.Instrument.Devices.Simulator)device).Manufacturer;
                    _info.wavelengths    = ((NIRSDAQ.Instrument.Devices.Simulator)device).wavelengths;
                    _info.numwavelengths = _info.wavelengths.Length;
                    _info.sample_rate    = ((NIRSDAQ.Instrument.Devices.Simulator)device).sample_rate;
                    break;

                case 1:
                    _info.numDet         = ((NIRSDAQ.Instrument.Devices.TechEn.BTnirs)device).ndets();
                    _info.numSrc         = ((NIRSDAQ.Instrument.Devices.TechEn.BTnirs)device).nsrcs();
                    _info.numMeas        = ((NIRSDAQ.Instrument.Devices.TechEn.BTnirs)device).nmeas();
                    _info.numAux         = ((NIRSDAQ.Instrument.Devices.TechEn.BTnirs)device).naux();
                    _info.PortName       = ((NIRSDAQ.Instrument.Devices.TechEn.BTnirs)device).portname();
                    _info.Manufacturer   = ((NIRSDAQ.Instrument.Devices.TechEn.BTnirs)device).Manufacturer;
                    _info.wavelengths    = ((NIRSDAQ.Instrument.Devices.TechEn.BTnirs)device).wavelengths;
                    _info.numwavelengths = _info.wavelengths.Length;
                    _info.sample_rate    = ((NIRSDAQ.Instrument.Devices.TechEn.BTnirs)device).sample_rate;
                    break;
                }

                return(_info);
            }
Esempio n. 3
0
 public instrument(string type)
 {
     if (type.ToLower().Equals("simulator"))
     {
         devicename = "Simulator";
         devicetype = 0;
         device     = new NIRSDAQ.Instrument.Devices.Simulator();
     }
     else if (type.ToLower().Equals("btnirs"))
     {
         devicename = "BTNIRS";
         devicetype = 1;
         device     = new NIRSDAQ.Instrument.Devices.TechEn.BTnirs();
     }
     _info = this.GetInfo();
 }
Esempio n. 4
0
            public instrument(string type)
            {
                XmlDocument doc = new XmlDocument();


                if (type.ToLower().Equals("simulator"))
                {
                    devicename = "Simulator";
                    devicetype = 0;
                    doc.Load(@"Simulator_Config.xml");
                    device = new NIRSDAQ.Instrument.Devices.Simulator(doc);
                }
                else if (type.ToLower().Equals("btnirs"))
                {
                    devicename = "BTNIRS";
                    devicetype = 1;
                    doc.Load(@"BTNIRS_Config.xml");
                    device = new NIRSDAQ.Instrument.Devices.TechEn.BTnirs(doc);
                }
                _info = this.GetInfo();
            }
    protected void CheckBattery()
    {
        if (MainClass.devices == null)
        {
            return;
        }
        int id = combobox_statusBattery.Active;

        if (id < 0)
        {
            id = 0;
        }

        try
        {
            NIRSDAQ.info[] info    = new NIRSDAQ.info[MainClass.devices.Length];
            string[]       battery = new string[MainClass.devices.Length];


            for (int i = 0; i < MainClass.devices.Length; i++)
            {
                info[i]    = MainClass.devices[i].GetInfo();
                battery[i] = MainClass.devices[i].GetBatteryInfo();
            }

            Gtk.ListStore ClearList = new Gtk.ListStore(typeof(string));
            combobox_statusBattery.Model = ClearList;
            for (int i = 0; i < MainClass.devices.Length; i++)
            {
                combobox_statusBattery.AppendText(string.Format("{0} {1}", info[i].PortName, battery[i]));
            }
            combobox_statusBattery.Active = id;
        }
        catch
        {
            Console.WriteLine("Check Battery Failed");
        }
    }
Esempio n. 6
0
    public void SetupGUI(List <string> ports)
    {
        MainClass.win.settings.LoadSettingsSystem();

        // remove all pages
        int n = notebook_detectors.NPages;

        for (int i = n - 1; i > -1; i--)
        {
            notebook_detectors.RemovePage(i);
        }
        n = notebook_sources.NPages;
        for (int i = n - 1; i > -1; i--)
        {
            notebook_sources.RemovePage(i);
        }

        if (ports.Count > 0)
        {
            // TODO DeviceOptionsAction.Sensitive = true;
        }

        List <string> ports2 = new List <string>();

        for (int i = 0; i < ports.Count; i++)
        {
            ports2.Add(ports[i]);
        }


        // If the device already has some connected
        if (MainClass.devices != null)
        {
            for (int j = 0; j < MainClass.devices.Length; j++)
            {
                MainClass.devices[j].Disconnect();
            }
        }

        MainClass.devices = new NIRSDAQ.Instrument.instrument[ports2.Count];
        for (int i = 0; i < ports2.Count; i++)
        {
            MainClass.devices[i] = new NIRSDAQ.Instrument.instrument(settings.SYSTEM);
            MainClass.devices[i].Connect(ports2[i]);
            colorbutton3.Color = new Gdk.Color(128, 255, 128);
            DebugMessage(string.Format("Connected to device {0}", i + 1));
        }


        if (nirsdata != null)
        {
            if (nirsdata.Count > ports2.Count)
            {
                nirsdata.RemoveRange(ports2.Count, nirsdata.Count - ports2.Count);
            }
            if (nirsdata.Count < ports2.Count)
            {
                if (nirsdata.Count > 0)
                {
                    for (int i = nirsdata.Count - 1; i < ports2.Count; i++)
                    {
                        nirsdata.Add(nirsdata[0]);
                    }
                }
            }
        }

        for (int i = 0; i < ports.Count; i++)
        {
            MainClass.devices[i].devicename = string.Format("{0}-{1}", MainClass.devices[i].devicename, i + 1);
            NIRSDAQ.info _info = MainClass.devices[i].GetInfo();

            _info.numDet = settings.system_Info.numdet;
            _info.numSrc = settings.system_Info.numsrc;



            HBox  hBox  = new HBox(true, 0);
            Label label = new Label();
            for (int j = 0; j < _info.numDet; j++)
            {
                if (j % 8 == 0)
                {
                    hBox  = new HBox(true, 0);
                    label = new Label(string.Format("{0}\n{1}-{2}", _info.DeviceName, j + 1, j + 8))
                    {
                        LineWrap = true
                    };
                    notebook_detectors.InsertPage(hBox, label, notebook_detectors.NPages);
                }
                Detector det = new Detector
                {
                    detectorIdx = j,
                    deviceIdx   = i,
                    gain        = 0,
                    name        = string.Format("Det-{0}", j + 1)
                };

                det.frame = new Frame(det.name);
                VBox _box = new VBox(false, 0);
                _box.PackStart(new Gtk.Fixed());
                det.led = new ColorButton(new Gdk.Color(0, 255, 0))
                {
                    HeightRequest = 25,
                    Sensitive     = false
                };

                det.vScale = new VScale(0, settings.system_Info.maxgain, 1)
                {
                    Value         = det.gain,
                    ValuePos      = PositionType.Bottom,
                    Inverted      = true,
                    HeightRequest = 175,
                    Name          = string.Format("{0}", _handles.detectors.Count)
                };
                det.vScale.ValueChanged += DetChanged;

                _box.PackStart(det.led);
                _box.PackStart(det.vScale);
                det.frame.Add(_box);
                hBox.PackStart(det.frame);

                _handles.detectors.Add(det);
            }

            VBox _vbx = new VBox();
            // Now add the source controls
            for (int j = 0; j < _info.numSrc; j += _info.numwavelengths)
            {
                if (j % 8 == 0)
                {
                    _vbx  = new VBox(true, 0);
                    label = new Label(string.Format("{0}\n{1}-{2}", _info.DeviceName, j + 1, j + 8))
                    {
                        LineWrap = true
                    };
                    notebook_sources.InsertPage(_vbx, label, notebook_sources.NPages);
                }
                int    sIdx  = j / _info.numwavelengths + 1;
                Frame  frame = new Frame(string.Format("Source-{0}", sIdx));
                HBox   _hbx  = new HBox(true, 0);
                Lasers src   = new Lasers
                {
                    laserIdx    = new int[_info.numwavelengths],
                    wavelength  = new int[_info.numwavelengths],
                    gain        = new int[_info.numwavelengths],
                    state       = new bool[_info.numwavelengths],
                    buttons     = new Button[_info.numwavelengths],
                    led         = new ColorButton[_info.numwavelengths],
                    spinButtons = new SpinButton[_info.numwavelengths],
                    deviceIdx   = i,
                    frame       = frame
                };
                for (int k = 0; k < _info.numwavelengths; k++)
                {
                    src.laserIdx[k]   = j + k;
                    src.wavelength[k] = _info.wavelengths[k];
                    src.gain[k]       = 0;
                    src.state[k]      = false;
                    src.name          = string.Format("{0}nm", src.wavelength[k]);
                    HBox _hbx2 = new HBox(true, 0);
                    src.buttons[k] = new Button
                    {
                        Label = src.name
                    };

                    VBox _vbx3 = new VBox(true, 0);
                    _vbx3.PackStart(src.buttons[k]);
                    _vbx3.PackStart(new Gtk.Fixed());
                    _hbx2.PackStart(_vbx3);

                    VBox _vbx2 = new VBox(true, 0);


                    src.led[k] = new ColorButton(new Gdk.Color(128, 128, 128))
                    {
                        HeightRequest = 25,
                        Sensitive     = false
                    };
                    _vbx2.PackStart(src.led[k]);

                    src.spinButtons[k] = new SpinButton(0, settings.system_Info.maxpower, 1)
                    {
                        Value = 0
                    };
                    src.buttons[k].Name     = string.Format("{0}", _handles.lasers.Count);
                    src.spinButtons[k].Name = string.Format("{0} {1}", _handles.lasers.Count, k);
                    if (!settings.system_Info.laseradjustable)
                    {
                        src.spinButtons[k].Visible = false;
                    }

                    src.buttons[k].Clicked += SrcClicked;
                    src.buttons[k].ModifyBg(StateType.Normal, new Gdk.Color(128, 128, 128));
                    src.buttons[k].ModifyBg(StateType.Selected, new Gdk.Color(128, 128, 128));
                    src.buttons[k].ModifyBg(StateType.Active, new Gdk.Color(128, 128, 128));
                    src.spinButtons[k].ValueChanged += SrcValueChanged;

                    _vbx2.PackStart(src.spinButtons[k]);
                    _hbx2.PackStart(_vbx2);
                    _hbx.PackStart(_hbx2);

                    if (k < _info.numwavelengths - 1)
                    {
                        _hbx.PackStart(new Gtk.VSeparator());
                    }
                }
                src.frame.Add(_hbx);
                _vbx.PackStart(src.frame);
                _handles.lasers.Add(src);
            }
        }

        string path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

        path = System.IO.Path.Combine(path, "LastSettings.xml");
        if (System.IO.File.Exists(path))
        {
            // Read the Config.xml file
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            XmlNodeList elemList;
            elemList = doc.GetElementsByTagName("probefile");
            string probefile = elemList[0].InnerXml.Trim();
            if (System.IO.File.Exists(probefile))
            {
                QuickStartAction.Sensitive = true;
                // Read the Config.xml file
                elemList = doc.GetElementsByTagName("Investigator");
                string investigator = elemList[0].InnerXml.Trim();
                elemList = doc.GetElementsByTagName("Study");
                string study = elemList[0].InnerXml.Trim();
                QuickStartAction.Label = "Quick Start: " + investigator + ":" + study;

                DebugMessage("Last Settings Avaliable  " + investigator + " : " + study);
            }
            else
            {
                QuickStartAction.Sensitive = false;
            }
        }
        else
        {
            QuickStartAction.Sensitive = false;
        }


        combobox_device1.Model   = new ListStore(typeof(string));
        combobox_device2.Model   = new ListStore(typeof(string));
        comboboxdeviceDemo.Model = new ListStore(typeof(string));
        for (int i = 0; i < MainClass.devices.Length; i++)
        {
            combobox_device1.AppendText(MainClass.devices[i].devicename);
            combobox_device2.AppendText(MainClass.devices[i].devicename);
            comboboxdeviceDemo.AppendText(MainClass.devices[i].devicename);
        }

        combobox_device1.Active = 0;
        if (MainClass.devices.Length > 1)
        {
            combobox_device2.Active = 1;
        }


        ShowAll();

        if (MainClass.devices.Length == 1)
        {
            fixed_device1.Visible     = false;
            fixed_device2.Visible     = false;
            combobox_device1.Visible  = false;
            combobox_device2.Visible  = false;
            drawingarea_Data2.Visible = false;
            drawingarea_SDG2.Visible  = false;

            fixed_device1.Hide();
            fixed_device2.Hide();
            combobox_device1.Hide();
            combobox_device2.Hide();
            MultipleDevicesAction.Sensitive = false;
            drawingarea_Data2.Hide();
            drawingarea_SDG2.Hide();
            combobox_device1.Active    = 0;
            DualViewAction.Sensitive   = false;
            SingleViewAction.Sensitive = false;
        }
        else
        {
            //   fixed_device1.Hide();
            fixed_device2.Hide();

            combobox_device1.Active = 0;
            combobox_device2.Active = 1;

            //   combobox_device1.Hide();
            combobox_device2.Hide();
            MultipleDevicesAction.Sensitive = true;
            SingleViewAction.Active         = false;

            DualViewAction.Sensitive   = true;
            SingleViewAction.Sensitive = true;
            drawingarea_Data2.Hide();
            drawingarea_SDG2.Hide();
        }
        if (MainClass.devices.Length > 0)
        {
            NewSubjectAction.Sensitive = true;
        }
    }
    protected void ChangeBPF(object sender, EventArgs e)
    {
        double[] fs = new double[MainClass.devices.Length];
        for (int i = 0; i < MainClass.devices.Length; i++)
        {
            NIRSDAQ.info info = MainClass.devices[i].GetInfo();
            fs[i] = info.sample_rate;
        }

        double hpf = 0.016;
        double lpf = 0.5;

        try
        {
            lpf = Convert.ToDouble(MainClass.win._handles.editLPF.Text);
            if (lpf > fs[0] / 2)
            {
                lpf = fs[0] * 5 / 11;
                MainClass.win._handles.editLPF.Text = string.Format("{0}", lpf);
            }
        }
        catch
        {
            MainClass.win._handles.editLPF.Text = string.Format("{0}", 0.5);
            lpf = 0.5;
        }

        try
        {
            hpf = Convert.ToDouble(MainClass.win._handles.editHPF.Text);
            if (hpf < 0)
            {
                hpf = 0;
                MainClass.win._handles.editHPF.Text = string.Format("{0}", 0);
            }
            if (hpf > lpf)
            {
                hpf = lpf / 2;
                MainClass.win._handles.editHPF.Text = string.Format("{0}", hpf);
            }
        }
        catch
        {
            MainClass.win._handles.editHPF.Text = string.Format("{0}", 0.016);
            hpf = 0.016;
        }



        if (maindisplaythread.IsAlive)
        {
            for (int i = 0; i < MainClass.devices.Length; i++)
            {
                for (int j = 0; j < MainClass.win.nirsdata[i].probe.numChannels; j++)
                {
                    realtimeEngine.OnlineFIRFiltersLPF[i][j] = OnlineFilter.CreateLowpass(ImpulseResponse.Finite, fs[i], lpf);
                    realtimeEngine.OnlineFIRFiltersHPF[i][j] = OnlineFilter.CreateHighpass(ImpulseResponse.Finite, fs[i], hpf);
                }
            }
        }
    }
    protected void SaveDataNow(int startIdx, int endIdx, int dataIdx = 0, bool keeptime = false)
    {
        DateTime now;

        if (keeptime)
        {
            now = lastscantime;
        }
        else
        {
            now          = DateTime.Now;
            lastscantime = now;
        }

        string comments = textview_comments.Buffer.Text;


        for (int i = 0; i < nirsdata.Count; i++)
        {
            NIRSDAQ.info info = MainClass.devices[i].GetInfo();

            nirsdata[i].demographics.set("comments", comments);
            nirsdata[i].demographics.set("scan_date", now.ToString("MM-dd-yyyy_HH:mm:ss"));
            nirsdata[i].demographics.set("device", info.DeviceName);
            nirsdata[i].demographics.set("manufacturer", info.Manufacturer);
            nirsdata[i].demographics.set("port", info.PortName);

            string test = (string)nirsdata[i].demographics.get("SubjID");
            if (test.Equals(""))
            {
                nirsdata[i].demographics.set("SubjID", "unknown");
            }


            string file = string.Format("{0}_scan{1}_{2}", (string)nirsdata[i].demographics.get("SubjID"),
                                        scancount, now.ToString("MMMMddyyyy_HHmm"));

            if (nirsdata.Count > 1)
            {
                file = string.Format("{0}_device{1}_scan{2}_{3}", (string)nirsdata[i].demographics.get("SubjID"),
                                     i + 1, scancount, now.ToString("MMMMddyyyy_HHmm"));
            }


            string[] paths = new string[] { MainClass.win.settings.DATADIR,
                                            (string)nirsdata[i].demographics.get("Investigator"),
                                            (string)nirsdata[i].demographics.get("Study"),
                                            now.ToString("MMMMddyyyy") };

            string pathname = System.IO.Path.Combine(paths);

            if (!Directory.Exists(pathname))
            {
                Directory.CreateDirectory(pathname);
            }

            if (SaveNirsFormatAction.Active)
            {
                string filename = System.IO.Path.Combine(pathname, string.Format("{0}.nirs", file));
                nirs.io.writeDOTnirs(nirsdata[i], filename, startIdx, endIdx);
                _handles.dataListStore.AppendValues(string.Format("{0}.nirs", file), "  ");
                DebugMessage(string.Format("Saving file {0}", filename));
            }

#if AllowHDF5
            if (SaveSnirfFormatAction.Active & !CombineSnirfFilesAction.Active)
            {
                string filename = System.IO.Path.Combine(pathname, string.Format("{0}.snirf", file));
                nirs.io.writeSNIRF(nirsdata[i], filename, -1, dataIdx);
                _handles.dataListStore.AppendValues(string.Format("{0}.snirf", file), "  ");
                DebugMessage(string.Format("Saving file {0}", filename));
            }
#endif
        }

#if AllowHDF5
        if (SaveSnirfFormatAction.Active & CombineSnirfFilesAction.Active)
        {
            string file = string.Format("{0}_scan{1}_{2}", "Hyperscan",
                                        scancount, now.ToString("MMMMddyyyy_HHmm"));

            string[] paths = new string[] { MainClass.win.settings.DATADIR,
                                            (string)nirsdata[0].demographics.get("Investigator"),
                                            (string)nirsdata[0].demographics.get("Study"),
                                            now.ToString("MM_dd_yyyy") };

            string pathname = System.IO.Path.Combine(paths);

            if (!Directory.Exists(pathname))
            {
                Directory.CreateDirectory(pathname);
            }



            string filename = System.IO.Path.Combine(pathname, string.Format("{0}.snirf", file));
            nirs.io.writeSNIRF(nirsdata, filename, -1, dataIdx);
            _handles.dataListStore.AppendValues(string.Format("{0}.snirf", file), "  ");
            DebugMessage(string.Format("Saving file {0}", filename));
        }
#endif
    }