Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int     i      = 5;
            Two     tw     = new Two();
            MWArray result = tw.twice((MWArray)i);

            this.label1.Text = result.ToString();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Class1  a = new Class1();
            MWArray b = 3, c = 6;
            MWArray result = a.add(b, c);

            Console.WriteLine(result.ToString());
            Console.Read();
        }
Esempio n. 3
0
        public int findFrequencia(double[] sinal, double freqAm)
        {
            int            LED = 0;
            string         aux_LED2;
            MWNumericArray xdt = new MWNumericArray(new double[sinal.Length]);

            xdt = sinal;
            processamento obj     = new processamento();
            MWArray       aux_LED = obj.FindFreq(xdt, freqAm);

            aux_LED2 = aux_LED.ToString();
            LED      = Convert.ToInt32(aux_LED2);
            return(LED);
        }
Esempio n. 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "+();", true);
        //aa = new string[] { "1","3","5","7" };
        //json 早上用用看
        // aa = Request.QueryString["1,2,3,4,5,6,7"];
        //Response.Write("A"+aa);

        POW     p   = new POW();
        MWArray mw  = p.CalcPow((MWArray)2, (MWArray)10);//計算2的10次方
        int     res = int.Parse(mw.ToString());

        Response.Write(res);
    }
Esempio n. 5
0
        public int correlacao(double[] sinal, double freqAm, double tamanhoJanela)
        {
            int            LED = 0;
            string         aux_LED2;
            MWNumericArray xdt = new MWNumericArray(new double[sinal.Length]);

            xdt = sinal;
            xcorr   obj     = new xcorr();
            MWArray aux_LED = obj.correlacao(xdt, freqAm, tamanhoJanela);

            aux_LED2 = aux_LED.ToString();
            LED      = Convert.ToInt32(aux_LED2);
            return(LED);
        }
Esempio n. 6
0
        private void StartGame()
        {
            timer1.Stop();

            TimeBlock.Text      = "开始";
            StartButton.Enabled = true;
            countdown           = 3;

            if (webcamIsInitialized)
            {
                Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();//获取当前帧

                if (bitmap == null)
                {
                    ResultLabel.Text = "无法获取当前帧";
                }
                else
                {
                    PreviewPictBox.Image   = bitmap;
                    PreviewPictBox.Visible = true;
                    var height = bitmap.Height;
                    var width  = bitmap.Width;
                    byte[,,] rgb = new byte[3, height, width];

                    for (int i = 0; i < height; i++)
                    {
                        for (int j = 0; j < width; j++)
                        {
                            rgb[0, i, j] = bitmap.GetPixel(j, i).R;
                            rgb[1, i, j] = bitmap.GetPixel(j, i).G;
                            rgb[2, i, j] = bitmap.GetPixel(j, i).B;
                        }
                    }
                    matrix = rgb;
                    try
                    {
                        MWArray result    = operate.ORG(matrix);
                        string  youresult = result.ToString();

                        if (GameMode)
                        {
                            HumReply(youresult);
                        }
                        else
                        {
                            RobotReply(youresult);//不会赢模式
                        }
                        Judge(You, Robot);
                    }
                    catch (Exception e)
                    {
                        string     currentPath = Directory.GetCurrentDirectory();
                        string     filePath    = currentPath + "\\ExceptionLog.txt";
                        FileStream fs          = null;
                        Encoding   encoder     = Encoding.UTF8;
                        byte[]     bytes       = encoder.GetBytes(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": \n" + e.Message);
                        if (File.Exists("ExceptionLog.txt"))
                        {
                            fs = File.OpenWrite(filePath);
                            //设定书写的开始位置为文件的末尾
                            fs.Position = fs.Length;
                            //将待写入内容追加到文件末尾
                            fs.Write(bytes, 0, bytes.Length);
                            fs.Close();
                            // 注:
                            //直接用记事本打开不显示换行,建议用其他文本编辑器看哈
                        }
                        else
                        {
                            File.Create(filePath);

                            fs = File.OpenWrite(filePath);
                            //设定书写的開始位置为文件的末尾
                            fs.Position = fs.Length;
                            //将待写入内容追加到文件末尾
                            fs.Write(bytes, 0, bytes.Length);
                            fs.Close();
                        }

                        ResultLabel.Text = "请调整手势";
                    }
                }
            }
            else
            {
                ResultLabel.Text = "无摄像头";
            }
        }//启动游戏逻辑
Esempio n. 7
0
        private void calcMATLAB(string benchmark, string algorithm)
        {
            double genum = (Double)numericUpDown2.Value;
            double psize = (Double)numericUpDown1.Value;
            double w     = (Double)numericUpDown3.Value;
            double c1    = (Double)numericUpDown4.Value;
            double c2    = (Double)numericUpDown5.Value;
            double run   = (Double)numericUpDown6.Value;

            MWArray[] results = new MWArray[6];
            MWArray[] inputs  = new MWArray[] { (MWArray)genum, (MWArray)psize, (MWArray)w, (MWArray)c1, (MWArray)c2, (MWArray)run };

            switch (benchmark)
            {
            case "FT06(6×6)":
                this.label22.Text = "55";
                FT06 myFT06 = new FT06();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myFT06.mainPSO_6c6(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myFT06.mainCPSO_6c6(6, ref results, inputs);
                }
                break;

            case "FT10(10×10)":
                this.label22.Text = "930";
                FT10 myFT10 = new FT10();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myFT10.mainPSO_10c10(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myFT10.mainCPSO_10c10(6, ref results, inputs);
                }
                break;

            case "FT20(20×5)":
                this.label22.Text = "1165";
                FT20 myFT20 = new FT20();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myFT20.mainPSO_20c5(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myFT20.mainCPSO_20c5(6, ref results, inputs);
                }
                break;

            case "LA01(10×5)":
                this.label22.Text = "666";
                LA01 myLA01 = new LA01();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myLA01.mainPSO_10c5(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myLA01.mainCPSO_10c5(6, ref results, inputs);
                }
                break;

            case "LA21(15×10)":
                this.label22.Text = "1046";
                LA21 myLA21 = new LA21();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myLA21.mainPSO_15c10(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myLA21.mainCPSO_15c10(6, ref results, inputs);
                }
                break;

            case "LA26(20×10)":
                this.label22.Text = "1218";
                LA26 myLA26 = new LA26();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myLA26.mainPSO_20c10(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myLA26.mainCPSO_20c10(6, ref results, inputs);
                }
                break;

            case "LA31(30×10)":
                this.label22.Text = "1784";
                LA31 myLA31 = new LA31();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myLA31.mainPSO_30c10(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myLA31.mainCPSO_30c10(6, ref results, inputs);
                }
                break;

            case "LA36(15×15)":
                this.label22.Text = "1268";
                LA36 myLA36 = new LA36();
                if (algorithm == "标准离散粒子群(DPSO)算法")
                {
                    myLA36.mainPSO_15c15(6, ref results, inputs);
                }
                else if (algorithm == "协同粒子群(CPSO)算法")
                {
                    myLA36.mainCPSO_15c15(6, ref results, inputs);
                }
                break;

            default:
                MessageBox.Show("请选择有效的调度算例");
                break;
            }

            finishTime = DateTime.Now.ToString();
            MWNumericArray exc      = results[0] as MWNumericArray;
            MWNumericArray min      = results[1] as MWNumericArray;
            MWNumericArray wre      = results[2] as MWNumericArray;
            MWNumericArray are      = results[3] as MWNumericArray;
            MWNumericArray t        = results[4] as MWNumericArray;
            MWArray        filename = results[5] as MWArray;

            ganttAdress       = filename.ToString();
            this.label26.Text = exc.ToString();
            this.label23.Text = min.ToString();
            this.label25.Text = wre.ToString();
            this.label24.Text = are.ToString();
            this.label27.Text = t.ToString();
            this.label28.Text = "计算完成!";
        }
Esempio n. 8
0
        public void startMulti(string comment, ViewRSOM.MSOT.Hardware.ViewModels.Laser.ViewModelLaserInnolas multiLaser, Button cancelAcq_Button)
        {
            // Define file parameters
            // Some parameters are adjusted to the OPO.
            MWArray acqFolder = fileParameters.studyFolder + "\\" + System.DateTime.Now.Year.ToString("0000") + System.DateTime.Now.Month.ToString("00")
                                + System.DateTime.Now.Day.ToString("00") + "\\";
            MWArray acqQuickScanFolder = acqFolder + "QuickScan\\";
            MWArray acqLogFolder       = acqFolder + "Log\\";
            MWArray acqPreviewFolder   = fileParameters.acqPreviewFolder;
            MWArray acqThumbnailFolder = acqFolder + "Thumbnail\\";
            MWArray dataName;

            if (fileParameters.dataName != null)
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00") + "_" + fileParameters.dataName;
            }
            else
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00");
            }


            // create recon folder
            if (!Directory.Exists(acqFolder.ToString()))
            {
                Directory.CreateDirectory(acqFolder.ToString());
            }
            //else
            //{
            //    Console.Write("WARNING: acquisition folder exists already. Proceed with reconstruction. Previous reconstructions may be overwritten.");
            //}
            if (!Directory.Exists(acqQuickScanFolder.ToString()))
            {
                Directory.CreateDirectory(acqQuickScanFolder.ToString());
            }
            if (!Directory.Exists(acqLogFolder.ToString()))
            {
                Directory.CreateDirectory(acqLogFolder.ToString());
            }
            if (!Directory.Exists(acqPreviewFolder.ToString()))
            {
                Directory.CreateDirectory(acqPreviewFolder.ToString());
            }
            if (!Directory.Exists(acqThumbnailFolder.ToString()))
            {
                Directory.CreateDirectory(acqThumbnailFolder.ToString());
            }

            // copy file parameters to structure
            string[]      fieldNames = { "acqFolder", "acqQuickScanFolder", "acqLogFolder", "acqPreviewFolder", "acqThumbnailFolder", "dataName" };
            MWStructArray fP         = new MWStructArray(1, 1, fieldNames);

            fP.SetField("acqFolder", acqFolder);
            fP.SetField("acqQuickScanFolder", acqQuickScanFolder);
            fP.SetField("acqLogFolder", acqLogFolder);
            fP.SetField("acqPreviewFolder", acqPreviewFolder);
            fP.SetField("acqThumbnailFolder", acqThumbnailFolder);
            fP.SetField("dataName", dataName);

            // Define acquisition parameters
            MWNumericArray y_0 = acquisitionParameters.y_0;
            MWNumericArray x_0 = acquisitionParameters.x_0;
            MWNumericArray l_y = acquisitionParameters.l_y;
            MWNumericArray l_x = acquisitionParameters.l_x;
            MWNumericArray ds  = acquisitionParameters.ds;
            MWNumericArray PRR = 500; // PRR of the OPO. Dont Change
            MWNumericArray triggerWidth;

            if (systemState.LASERconnected == 1) // Wedge
            {
                triggerWidth = 130;              // [us]
            }
            else
            {
                triggerWidth = 5;
            }
            MWNumericArray f_s                    = acquisitionParameters.f_s;
            MWNumericArray inputRange             = acquisitionParameters.inputRange_list[acquisitionParameters.inputRange_listIndex];
            MWNumericArray z_low                  = acquisitionParameters.z_low;
            MWNumericArray z_target               = acquisitionParameters.z_target;
            MWNumericArray z_high                 = acquisitionParameters.z_high;
            MWNumericArray v_x                    = 10; // dx/PRR
            MWNumericArray acc                    = 300;
            MWNumericArray acqDelay               = 3;
            MWNumericArray d_acc                  = 0.17;
            MWNumericArray acqRes                 = acquisitionParameters.acqRes;
            MWArray        acqMode                = acquisitionParameters.acqMode;
            MWNumericArray triggerLevel           = acquisitionParameters.triggerLevel;
            MWNumericArray numberOfWavelength     = acquisitionParameters.numberOfWavelength;
            MWNumericArray BscanUpdate            = acquisitionParameters.BscanUpdate;
            MWArray        controllerSerialNumber = acquisitionParameters.controllerSerialNumber;
            MWNumericArray quickScan              = 0;
            MWArray        ArrayOfWavelength      = acquisitionParameters.ArrayOfWavelength;

            // MWNumericArray ArrayOfWavelength = new MWNumericArray(acquisitionParameters.ArrayOfWavelength);
            //MWNumericArray ArrayOfWavelength = new MWNumericArray[acquisitionParameters.numberOfWavelength];

            //get number of wavelength from comment box
            if (!string.IsNullOrEmpty(comment))
            {
                try
                {
                    numberOfWavelength = multiLaser.retrieveWL(comment).Length;
                    int[]  tempArr   = multiLaser.retrieveWL(comment);
                    string stringArr = "";
                    for (int i = 0; i < multiLaser.retrieveWL(comment).Length; i++)
                    {
                        if (i == 0)
                        {
                            stringArr = tempArr[i].ToString();
                        }
                        else
                        {
                            stringArr = stringArr + " " + tempArr[i].ToString();
                        }
                    }
                    ArrayOfWavelength = stringArr;
                }
                catch (Exception)
                {
                    multiLaser.illuminationOFF();
                    Console.WriteLine("Wavelengths - wrong syntaxis");
                    //cancelAcq_Button.Click -= multiLaser.laserHandle;
                    Thread.Sleep(5000);
                    Environment.Exit(1);
                }
            }
            else
            {
                ArrayOfWavelength = LaserParameter.LaserDefaultWavelength.ToString();
            }

            // copy file parameters to structure
            string[]      fieldNames2 = { "y_0",          "x_0",          "l_y",                    "l_x",        "ds",
                                          "PRR",               "triggerWidth", "f_s",                    "inputRange", "z_low", "z_target", "z_high",
                                          "v_x",               "acc",          "acqDelay",               "d_acc",      "acqRes","acqMode",  "triggerLevel","numberOfWavelength",
                                          "ArrayOfWavelength", "BscanUpdate",  "controllerSerialNumber", "quickScan" };
            MWStructArray aP = new MWStructArray(1, 1, fieldNames2);

            aP.SetField("y_0", y_0);
            aP.SetField("x_0", x_0);
            aP.SetField("l_y", l_y);
            aP.SetField("l_x", l_x);
            aP.SetField("ds", ds);
            aP.SetField("PRR", PRR);
            aP.SetField("triggerWidth", triggerWidth);
            aP.SetField("f_s", f_s);
            aP.SetField("inputRange", inputRange);
            aP.SetField("z_low", z_low);
            aP.SetField("z_target", z_target);
            aP.SetField("z_high", z_high);
            aP.SetField("v_x", v_x);
            aP.SetField("acc", acc);
            aP.SetField("acqDelay", acqDelay);
            aP.SetField("d_acc", d_acc);
            aP.SetField("acqRes", acqRes);
            aP.SetField("acqMode", acqMode);
            aP.SetField("triggerLevel", triggerLevel);
            aP.SetField("numberOfWavelength", numberOfWavelength);
            aP.SetField("ArrayOfWavelength", ArrayOfWavelength);
            aP.SetField("BscanUpdate", BscanUpdate);
            aP.SetField("controllerSerialNumber", controllerSerialNumber);
            aP.SetField("quickScan", quickScan);

            // Define reconstruction parameters
            MWNumericArray t_focus = detectorParameters.t_focus;

            // copy file parameters to structure
            string[]      fieldNames3 = { "t_focus" };
            MWStructArray dP          = new MWStructArray(1, 1, fieldNames3);

            dP.SetField("t_focus", t_focus);

            // Define reconstruction parameters
            MWNumericArray v_s = reconstructionParameters.v_s;

            // copy file parameters to structure
            string[]      fieldNames4 = { "v_s" };
            MWStructArray rP          = new MWStructArray(1, 1, fieldNames4);

            rP.SetField("v_s", v_s);

            try
            {
                //if (systemState.LASERconnected == 0 || systemState.DAQconnected == 0 || systemState.STAGESconnected == 0)
                if (systemState.DAQconnected == 0 || systemState.STAGESconnected == 0)
                {
                    iScanClass_mock obj_mock = null;
                    obj_mock = new iScanClass_mock();
                    obj_mock.iScan_mock(fP, aP, dP, rP);
                }
                else
                {
                    // choose right kernel for stages
                    switch (systemState.DAQconnected)
                    {
                    case 1:     // Gage

                        // if (acquisitionParameters.triggerMode == 0)
                    {
                        iScanClass_OPO obj = null;
                        obj = new iScanClass_OPO();
                        obj.iScan_dual(fP, aP, dP, rP);
                    }

                        /*else
                         * {
                         *  iScanClass_trig obj_trig = null;
                         *  obj_trig = new iScanClass_trig();
                         *  obj_trig.iScan_trig(fP, aP, dP, rP);
                         * }*/
                        break;

                    case 2:     // Alazar
                        //if (acquisitionParameters.triggerMode == 0)
                    {
                        iScanClass_OPO obj = null;
                        obj = new iScanClass_OPO();
                        obj.iScan_dual(fP, aP, dP, rP);
                    }
                        //else
                        {
                            Console.WriteLine("ERROR: Alazar external trigger not yet implmented.");
                        }
                        break;

                    default:
                        Console.WriteLine("ERROR: Settings say there is no DAQ connected.");
                        break;
                    }

                    // switch off laser and close connection
                    {
                        multiLaser.illuminationOFF();
                        cancelAcq_Button.Click -= multiLaser.laserHandle;
                    }
                }
            }
            catch (Exception e)
            {
                // check if laser emission can be stopped
                if (multiLaser != null)
                {
                    try
                    {
                        multiLaser.illuminationOFF();
                        string StatusMessage;
                        StatusMessage = multiLaser.CheckShutterState();
                        if (StatusMessage == "OPEN")
                        {
                            Console.WriteLine("WARNING: switch off OPO EMISSION if necessary.");
                        }
                        cancelAcq_Button.Click -= multiLaser.laserHandle;
                    }
                    catch
                    {
                        Console.WriteLine("WARNING: switch off laser EMISSION if necessary.");
                    };
                }

                if (!e.Message.Contains("ERROR:"))
                {
                    Console.WriteLine("ERROR:" + e.Message);
                }
                Console.WriteLine("\n");
                Console.WriteLine("Status-Acq: 1.00");
            }

            // write xml-file
            XDocument acqXML = new XDocument(
                new XElement("acquisitionParameters",
                             new XElement("l_y", l_y.ToString()),
                             new XElement("l_x", l_x.ToString()),
                             new XElement("ds", ds.ToString()),
                             new XElement("PRR", PRR.ToString()),
                             new XElement("laserEnergy", acquisitionParameters.laserPower.ToString()),
                             new XElement("f_s", f_s.ToString()),
                             new XElement("inputRange", inputRange.ToString()),
                             new XElement("z_low", z_low.ToString()),
                             new XElement("z_high", z_high.ToString()),
                             new XElement("numberOfWavelength", numberOfWavelength.ToString()),
                             new XElement("comment", comment)
                             )
                );

            acqXML.Declaration = new XDeclaration("1.0", "utf-8", "true");

            string filename = acqFolder.ToString() + dataName.ToString() + ".xml";

            acqXML.Save(@filename);
        }
Esempio n. 9
0
        public void start(string comment, Hardware.LaserSW.ViewModelBrightSolutions ondaLaser, Button cancelAcq_Button)
        {
            // Define file parameters
            MWArray acqFolder = fileParameters.studyFolder + "\\" + System.DateTime.Now.Year.ToString("0000") + System.DateTime.Now.Month.ToString("00")
                                + System.DateTime.Now.Day.ToString("00") + "\\";
            MWArray acqQuickScanFolder = acqFolder + "QuickScan\\";
            MWArray acqLogFolder       = acqFolder + "Log\\";
            MWArray acqPreviewFolder   = fileParameters.acqPreviewFolder;
            MWArray acqThumbnailFolder = acqFolder + "Thumbnail\\";
            MWArray dataName;

            if (fileParameters.dataName != null)
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00") + "_" + fileParameters.dataName;
            }
            else
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00");
            }


            // create recon folder
            if (!Directory.Exists(acqFolder.ToString()))
            {
                Directory.CreateDirectory(acqFolder.ToString());
            }


            if (!Directory.Exists(acqQuickScanFolder.ToString()))
            {
                Directory.CreateDirectory(acqQuickScanFolder.ToString());
            }
            if (!Directory.Exists(acqLogFolder.ToString()))
            {
                Directory.CreateDirectory(acqLogFolder.ToString());
            }
            if (!Directory.Exists(acqPreviewFolder.ToString()))
            {
                Directory.CreateDirectory(acqPreviewFolder.ToString());
            }
            if (!Directory.Exists(acqThumbnailFolder.ToString()))
            {
                Directory.CreateDirectory(acqThumbnailFolder.ToString());
            }

            // copy file parameters to structure
            string[]      fieldNames = { "acqFolder", "acqQuickScanFolder", "acqLogFolder", "acqPreviewFolder", "acqThumbnailFolder", "dataName" };
            MWStructArray fP         = new MWStructArray(1, 1, fieldNames);

            fP.SetField("acqFolder", acqFolder);
            fP.SetField("acqQuickScanFolder", acqQuickScanFolder);
            fP.SetField("acqLogFolder", acqLogFolder);
            fP.SetField("acqPreviewFolder", acqPreviewFolder);
            fP.SetField("acqThumbnailFolder", acqThumbnailFolder);
            fP.SetField("dataName", dataName);

            // Define acquisition parameters
            MWNumericArray y_0 = acquisitionParameters.y_0;
            MWNumericArray x_0 = acquisitionParameters.x_0;
            MWNumericArray l_y = acquisitionParameters.l_y;
            MWNumericArray l_x = acquisitionParameters.l_x;
            MWNumericArray ds  = acquisitionParameters.ds;
            MWNumericArray PRR = acquisitionParameters.PRR;
            MWNumericArray triggerWidth;

            if (systemState.LASERconnected == 1) // Wedge
            {
                triggerWidth = 130;              // [us]
            }
            else
            {
                triggerWidth = 5;
            }
            MWNumericArray f_s                = acquisitionParameters.f_s;
            MWNumericArray inputRange         = acquisitionParameters.inputRange_list[acquisitionParameters.inputRange_listIndex];
            MWNumericArray z_low              = acquisitionParameters.z_low;
            MWNumericArray z_target           = acquisitionParameters.z_target;
            MWNumericArray z_high             = acquisitionParameters.z_high;
            MWNumericArray v_x                = acquisitionParameters.v_x;
            MWNumericArray acc                = acquisitionParameters.acc;
            MWNumericArray acqDelay           = acquisitionParameters.acqDelay;
            MWNumericArray d_acc              = acquisitionParameters.d_acc;
            MWNumericArray acqRes             = acquisitionParameters.acqRes;
            MWArray        acqMode            = acquisitionParameters.acqMode;
            MWNumericArray triggerLevel       = acquisitionParameters.triggerLevel;
            MWNumericArray numberOfWavelength = acquisitionParameters.numberOfWavelength;


            MWNumericArray BscanUpdate            = acquisitionParameters.BscanUpdate;
            MWArray        controllerSerialNumber = acquisitionParameters.controllerSerialNumber;
            MWNumericArray quickScan = 0;

            // copy file parameters to structure
            string[]      fieldNames2 = { "y_0",    "x_0",                    "l_y",      "l_x",        "ds",
                                          "PRR",         "triggerWidth",           "f_s",      "inputRange", "z_low", "z_target", "z_high",
                                          "v_x",         "acc",                    "acqDelay", "d_acc",      "acqRes","acqMode",  "triggerLevel","numberOfWavelength",
                                          "BscanUpdate", "controllerSerialNumber", "quickScan" };
            MWStructArray aP = new MWStructArray(1, 1, fieldNames2);

            aP.SetField("y_0", y_0);
            aP.SetField("x_0", x_0);
            aP.SetField("l_y", l_y);
            aP.SetField("l_x", l_x);
            aP.SetField("ds", ds);
            aP.SetField("PRR", PRR);
            aP.SetField("triggerWidth", triggerWidth);
            aP.SetField("f_s", f_s);
            aP.SetField("inputRange", inputRange);
            aP.SetField("z_low", z_low);
            aP.SetField("z_target", z_target);
            aP.SetField("z_high", z_high);
            aP.SetField("v_x", v_x);
            aP.SetField("acc", acc);
            aP.SetField("acqDelay", acqDelay);
            aP.SetField("d_acc", d_acc);
            aP.SetField("acqRes", acqRes);
            aP.SetField("acqMode", acqMode);
            aP.SetField("triggerLevel", triggerLevel);
            aP.SetField("numberOfWavelength", numberOfWavelength);
            aP.SetField("BscanUpdate", BscanUpdate);
            aP.SetField("controllerSerialNumber", controllerSerialNumber);
            aP.SetField("quickScan", quickScan);

            // Define reconstruction parameters
            MWNumericArray t_focus = detectorParameters.t_focus;

            // copy file parameters to structure
            string[]      fieldNames3 = { "t_focus" };
            MWStructArray dP          = new MWStructArray(1, 1, fieldNames3);

            dP.SetField("t_focus", t_focus);

            // Define reconstruction parameters
            MWNumericArray v_s = reconstructionParameters.v_s;

            // copy file parameters to structure
            string[]      fieldNames4 = { "v_s" };
            MWStructArray rP          = new MWStructArray(1, 1, fieldNames4);

            rP.SetField("v_s", v_s);

            try
            {
                if (systemState.LASERconnected == 0 || systemState.DAQconnected == 0 || systemState.STAGESconnected == 0)
                {
                    iScanClass_mock obj_mock = null;
                    obj_mock = new iScanClass_mock();
                    obj_mock.iScan_mock(fP, aP, dP, rP);
                }
                else
                {
                    // choose right kernel for stages
                    switch (systemState.DAQconnected)
                    {
                    case 1:     // Gage
                        if (acquisitionParameters.triggerMode == 0)
                        {
                            iScanClass obj = null;
                            obj = new iScanClass();
                            obj.iScan(fP, aP, dP, rP);
                        }
                        else
                        {
                            iScanClass_trig obj_trig = null;
                            obj_trig = new iScanClass_trig();
                            obj_trig.iScan_trig(fP, aP, dP, rP);
                        }
                        break;

                    case 2:     // Alazar
                        if (acquisitionParameters.triggerMode == 0)
                        {
                            iScanClass_Alazar obj_Alazar = null;
                            obj_Alazar = new iScanClass_Alazar();
                            obj_Alazar.iScan_Alazar(fP, aP, dP, rP);
                        }
                        else
                        {
                            Console.WriteLine("ERROR: Alazar external trigger not yet implmented.");
                        }
                        break;

                    default:
                        Console.WriteLine("ERROR: Settings say there is no DAQ connected.");
                        break;
                    }

                    // switch off laser and close connection
                    if (systemState.LASERconnected == 1 || systemState.LASERconnected == 2)
                    {
                        // switch laser off and close connection
                        ondaLaser.EmissionOFF();
                        ondaLaser.closeConnection();
                        cancelAcq_Button.Click -= ondaLaser.laserHandle;
                    }
                }
            }
            catch (Exception e)
            {
                // check if laser emission can be stopped
                if (ondaLaser != null)
                {
                    try
                    {
                        ondaLaser.EmissionOFF();
                        ondaLaser.closeConnection();
                        cancelAcq_Button.Click -= ondaLaser.laserHandle;
                    }
                    catch
                    {
                        Console.WriteLine("WARNING: switch off laser EMISSION if necessary.");
                    };
                }

                if (!e.Message.Contains("ERROR:"))
                {
                    Console.WriteLine("ERROR:" + e.Message);
                }
                Console.WriteLine("\n");
                Console.WriteLine("Status-Acq: 1.00");
            }

            // write xml-file
            XDocument acqXML = new XDocument(
                new XElement("acquisitionParameters",
                             new XElement("l_y", l_y.ToString()),
                             new XElement("l_x", l_x.ToString()),
                             new XElement("ds", ds.ToString()),
                             new XElement("PRR", PRR.ToString()),
                             new XElement("laserEnergy", acquisitionParameters.laserPower.ToString()),
                             new XElement("f_s", f_s.ToString()),
                             new XElement("inputRange", inputRange.ToString()),
                             new XElement("z_low", z_low.ToString()),
                             new XElement("z_high", z_high.ToString()),
                             new XElement("numberOfWavelength", numberOfWavelength.ToString()),
                             new XElement("comment", comment)
                             )
                );

            acqXML.Declaration = new XDeclaration("1.0", "utf-8", "true");

            string filename = acqFolder.ToString() + dataName.ToString() + ".xml";

            acqXML.Save(@filename);

            //// write RSOMpreset xml-file
            //XDocument presetXML = new XDocument(
            //    new XElement("RSOMpreset",
            //        new XElement("laserSettings",
            //            new XElement("energy", acquisitionParameters.laserPower.ToString())
            //            )
            //        )
            //   );

            //presetXML.Declaration = new XDeclaration("1.0", "utf-8", "true");

            //string filenamePreset = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\iThera\\ViewRSOM\\RSOMpreset.xml";
            //presetXML.Save(@filenamePreset);
        }
Esempio n. 10
0
        public void start(List <ReconItem> _myReconItems)
        {
            // create timer to estimate recon time
            DateTime tPart = DateTime.Now;
            TimeSpan duration;

            // define own private dataFolder and list of data names that is not updated/affected from outside
            MWArray       dataFolder = studyParameters.myStudyDates_list[studyParameters.myStudyDates_listIndex].folderPath + "\\";
            List <string> dataNames  = new List <string>();

            // current recon settings
            double zRecon_high_curr        = reconstructionParameters.zRecon_high;
            int    bandpassSeparation_curr = reconstructionParameters.bandpassSeparation;
            int    motionCorrection_curr   = reconstructionParameters.motionCorrection;
            int    movingMAP_curr          = reconstructionParameters.movingMAP;
            int    volume3D_curr           = reconstructionParameters.volume3D;


            // create own private recon list and setup total progress bar
            int N_tot  = 0;
            int N_curr = 0;

            for (int i = 0; i < _myReconItems.Count; i++)
            {
                if (_myReconItems[i].isChecked)
                {
                    dataNames.Add(_myReconItems[i].fileName);
                    N_tot++;
                }
            }
            if (bandpassSeparation_curr == 1)
            {
                N_tot = N_tot * 3;
            }
            reconstructionParameters.reconProgressTot = new int[2] {
                0, N_tot
            };

            int     N_recon  = dataNames.Count;
            MWArray dataName = null;

            for (int i = 0; i < N_recon; i++)
            {
                // define data name
                dataName = dataNames[i];

                // Define file parameters
                //MWArray dataFolder = studyParameters.studyDateList[studyParameters.studyDate_default].folderPath + "\\";
                int     counter     = 1;
                bool    runLoop     = true;
                MWArray reconFolder = null;
                while (runLoop)
                {
                    if (motionCorrection_curr == 1)
                    {
                        reconFolder = dataFolder + "R_" + dataName + "_mc" + counter + "\\";
                    }
                    else
                    {
                        reconFolder = dataFolder + "R_" + dataName + "_" + counter + "\\";
                    }
                    if (!Directory.Exists(reconFolder.ToString()))
                    {
                        runLoop = false;
                    }
                    counter++;
                }
                MWArray reconLogFolder       = reconFolder + "LogFile\\";
                MWArray reconImageFolder     = reconFolder + "Images\\";
                MWArray reconThumbnailFolder = reconFolder + "Thumbnail\\";
                MWArray reconExportFolder    = reconFolder + "Export\\";
                MWArray SFFile        = fileParameters.SFFolder + fileParameters.SFFile;
                MWArray fileExtension = "";

                // create recon folder
                if (!Directory.Exists(reconFolder.ToString()))
                {
                    Directory.CreateDirectory(reconFolder.ToString());
                }
                if (!Directory.Exists(reconLogFolder.ToString()))
                {
                    Directory.CreateDirectory(reconLogFolder.ToString());
                }
                if (!Directory.Exists(reconImageFolder.ToString()))
                {
                    Directory.CreateDirectory(reconImageFolder.ToString());
                }
                if (!Directory.Exists(reconThumbnailFolder.ToString()))
                {
                    Directory.CreateDirectory(reconThumbnailFolder.ToString());
                }

                // copy file parameters to structure
                string[]      fieldNames = { "dataFolder",      "reconFolder",       "reconLogFolder", "reconImageFolder",
                                             "reconThumbnailFolder", "reconExportFolder",
                                             "dataName",             "SFFile",            "fileExtension" };
                MWStructArray fP = new MWStructArray(1, 1, fieldNames);
                fP.SetField("dataFolder", dataFolder);
                fP.SetField("reconFolder", reconFolder);
                fP.SetField("reconLogFolder", reconLogFolder);
                fP.SetField("reconImageFolder", reconImageFolder);
                fP.SetField("reconThumbnailFolder", reconThumbnailFolder);
                fP.SetField("reconExportFolder", reconExportFolder);
                fP.SetField("dataName", dataName);
                fP.SetField("SFFile", SFFile);
                fP.SetField("fileExtension", fileExtension);

                // Define reconstruction parameters
                MWNumericArray reflectionFilter = reconstructionParameters.reflectionFilter;
                MWNumericArray bandpassFilter   = reconstructionParameters.bandpassFilter;
                MWNumericArray f_low            = reconstructionParameters.f_low;
                MWNumericArray f_high           = reconstructionParameters.f_high;
                MWNumericArray coRegistration   = reconstructionParameters.coRegistration;
                MWNumericArray focusModel       = reconstructionParameters.focusModel;
                MWNumericArray bpMode           = reconstructionParameters.bpMode;
                MWNumericArray bpWeight         = reconstructionParameters.bpWeight;
                MWNumericArray v_s              = reconstructionParameters.v_s;
                MWNumericArray zRecon_low       = reconstructionParameters.zRecon_low; // reconstructionParameters.z_lowRel;
                MWNumericArray zRecon_high      = zRecon_high_curr;                    // reconstructionParameters.z_upRel;
                MWNumericArray motionCorrection = motionCorrection_curr;
                MWNumericArray blockSize        = reconstructionParameters.blockSize;
                MWArray        platform         = reconstructionParameters.platform;
                MWArray        deviceType       = reconstructionParameters.deviceType;
                MWNumericArray dz         = reconstructionParameters.dz;
                MWNumericArray ds         = reconstructionParameters.ds;
                MWNumericArray maxOffset  = reconstructionParameters.maxOffset;
                MWNumericArray y_shiftInd = reconstructionParameters.y_shiftInd;

                MWNumericArray movingMAP = movingMAP_curr;
                MWNumericArray movingMAP_slabThickness = reconstructionParameters.movingMAP_slabThickness;
                MWNumericArray volume3D = volume3D_curr;

                // copy file parameters to structure
                string[] fieldNames2 = { "reflectionFilter", "bandpassFilter", "f_low",       "f_high",
                                         "coRegistration",   "focusModel",     "bpMode",      "bpWeight",
                                         "v_s",              "zRecon_low",     "zRecon_high", "motionCorrection",       "blockSize",
                                         "platform",         "deviceType",     "dz",          "ds",
                                         "maxOffset",        "y_shiftInd",     "movingMAP",   "movingMAP_slabThickness","volume3D" };

                MWStructArray rP = new MWStructArray(1, 1, fieldNames2);
                rP.SetField("reflectionFilter", reflectionFilter);
                rP.SetField("bandpassFilter", bandpassFilter);
                rP.SetField("f_low", f_low);
                rP.SetField("f_high", f_high);
                rP.SetField("coRegistration", coRegistration);
                rP.SetField("focusModel", focusModel);
                rP.SetField("bpMode", bpMode);
                rP.SetField("bpWeight", bpWeight);
                rP.SetField("v_s", v_s);
                rP.SetField("zRecon_low", zRecon_low);
                rP.SetField("zRecon_high", zRecon_high);
                rP.SetField("motionCorrection", motionCorrection);
                rP.SetField("blockSize", blockSize);
                rP.SetField("platform", platform);
                rP.SetField("deviceType", deviceType);
                rP.SetField("dz", dz);
                rP.SetField("ds", ds);
                rP.SetField("maxOffset", maxOffset);
                rP.SetField("y_shiftInd", y_shiftInd);
                rP.SetField("movingMAP", movingMAP);
                rP.SetField("movingMAP_slabThickness", movingMAP_slabThickness);
                rP.SetField("volume3D", volume3D);

                // Define reconstruction parameters
                MWNumericArray t_focus          = detectorParameters.t_focus;
                MWNumericArray focalLength      = detectorParameters.focalLength;
                MWNumericArray detectorDiameter = detectorParameters.detectorDiameter;
                MWNumericArray dataSign         = detectorParameters.dataSign;

                // copy file parameters to structure
                string[]      fieldNames3 = { "t_focus", "focalLength", "detectorDiameter", "dataSign" };
                MWStructArray dP          = new MWStructArray(1, 1, fieldNames3);
                dP.SetField("t_focus", t_focus);
                dP.SetField("focalLength", focalLength);
                dP.SetField("detectorDiameter", detectorDiameter);
                dP.SetField("dataSign", dataSign);

                if (bandpassSeparation_curr == 0)
                {
                    iReconOpenClClass obj = null;
                    // iRecon3DClass obj = null;

                    try
                    {
                        // Instantiate your component class.
                        obj = new iReconOpenClClass();
                        obj.iRecon3D_OpenCl(fP, rP, dP);
                        // obj = new iRecon3DClass();
                        // obj.iRecon3D(fP, rP, dP);
                        N_curr++;
                        reconstructionParameters.reconProgressTot = new int[2] {
                            N_curr, N_tot
                        };

                        // Print future time estimate
                        duration = (DateTime.Now - tPart);
                        for (int i_time = N_curr + 1; i_time < N_tot; i_time++)
                        {
                            duration += (DateTime.Now - tPart);
                        }
                        reconstructionParameters.remainingReconTime = new TimeSpan(duration.Hours, duration.Minutes, duration.Seconds);
                        tPart = DateTime.Now;

                        // Trigger messages in message box
                        Console.WriteLine("Recon-finished: " + reconFolder + "R_" + dataName);
                    }
                    catch (Exception e)
                    {
                        N_curr++;
                        reconstructionParameters.reconProgressTot = new int[2] {
                            N_curr, N_tot
                        };
                        Console.WriteLine("Status-Recon: 1.00");
                        if (!e.Message.StartsWith("ERROR:"))
                        {
                            Console.WriteLine("ERROR:" + e.Message + "\n");
                        }
                        if (N_tot == N_curr)
                        {
                            Console.WriteLine("Recon-finished: reconstruction finished with errors.");
                        }
                    }
                }

                if (bandpassSeparation_curr == 1)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        // redefine some parameters
                        if (j == 0)
                        {
                            SFFile        = fileParameters.SFFolder + fileParameters.SFFile;
                            fileExtension = "";
                            fP.SetField("SFFile", SFFile);
                            fP.SetField("fileExtension", fileExtension);

                            f_low  = reconstructionParameters.f_low;
                            f_high = reconstructionParameters.f_high;
                            rP.SetField("f_low", f_low);
                            rP.SetField("f_high", f_high);
                        }
                        if (j == 1)
                        {
                            SFFile        = fileParameters.SFFolder + fileParameters.SFFileLF;
                            fileExtension = "_LF";
                            fP.SetField("SFFile", SFFile);
                            fP.SetField("fileExtension", fileExtension);

                            f_low  = reconstructionParameters.f_low;
                            f_high = reconstructionParameters.f_mid;
                            rP.SetField("f_low", f_low);
                            rP.SetField("f_high", f_high);
                        }
                        if (j == 2)
                        {
                            SFFile        = fileParameters.SFFolder + fileParameters.SFFileHF;
                            fileExtension = "_HF";
                            fP.SetField("SFFile", SFFile);
                            fP.SetField("fileExtension", fileExtension);

                            f_low  = reconstructionParameters.f_mid;
                            f_high = reconstructionParameters.f_high;
                            rP.SetField("f_low", f_low);
                            rP.SetField("f_high", f_high);
                        }

                        iReconOpenClClass obj = null;
                        // iRecon3DClass obj = null;

                        try
                        {
                            // Instantiate your component class.
                            obj = new iReconOpenClClass();
                            obj.iRecon3D_OpenCl(fP, rP, dP);
                            // obj = new iRecon3DClass();
                            // obj.iRecon3D(fP, rP, dP);
                            N_curr++;
                            reconstructionParameters.reconProgressTot = new int[2] {
                                N_curr, N_tot
                            };

                            // Print future time estimate
                            duration = (DateTime.Now - tPart);
                            for (int i_time = N_curr + 1; i_time < N_tot; i_time++)
                            {
                                duration += (DateTime.Now - tPart);
                            }
                            reconstructionParameters.remainingReconTime = new TimeSpan(duration.Hours, duration.Minutes, duration.Seconds);
                            tPart = DateTime.Now;

                            // Trigger messages in message box
                            if (j == 0)
                            {
                                Console.WriteLine("Recon-finished: " + reconFolder + "R_" + dataName);
                            }
                            else
                            {
                                Console.WriteLine("Recon-finished: " + reconFolder + "R_" + dataName + fileExtension);
                            }
                        }
                        catch (Exception e)
                        {
                            N_curr++;
                            reconstructionParameters.reconProgressTot = new int[2] {
                                N_curr, N_tot
                            };
                            Console.WriteLine("Status-Recon: 0.01");
                            if (!e.Message.Contains("ERROR:"))
                            {
                                Console.WriteLine("ERROR:" + e.Message + "\n");
                            }
                            if (N_tot == N_curr)
                            {
                                Console.WriteLine("Recon-finished: reconstruction finished with errors.");
                            }
                        }
                    }
                }
            }

            Console.WriteLine("Recon-finished: All reconstructions finished");
        }
Esempio n. 11
0
        public void startMulti(string comment, ViewRSOM.MSOT.Hardware.ViewModels.Laser.ViewModelLaserInnolas multiLaser, Button cancelAcq_Button)
        {
            // Define file parameters
            MWArray acqFolder = fileParameters.studyFolder + "\\" + System.DateTime.Now.Year.ToString("0000") + System.DateTime.Now.Month.ToString("00")
                                + System.DateTime.Now.Day.ToString("00") + "\\";
            MWArray acqQuickScanFolder = acqFolder + "QuickScan\\";
            MWArray acqLogFolder       = acqFolder + "Log\\";
            MWArray acqPreviewFolder   = fileParameters.acqPreviewFolder;
            MWArray acqThumbnailFolder = acqFolder + "Thumbnail\\";
            MWArray dataName;

            if (fileParameters.dataName != null)
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00") + "_" + fileParameters.dataName;
            }
            else
            {
                dataName = System.DateTime.Now.Hour.ToString("00") + System.DateTime.Now.Minute.ToString("00") + System.DateTime.Now.Second.ToString("00");
            }


            // create recon folder
            if (!Directory.Exists(acqFolder.ToString()))
            {
                Directory.CreateDirectory(acqFolder.ToString());
            }
            //else
            //{
            //    Console.Write("WARNING: acquisition folder exists already. Proceed with reconstruction. Previous reconstructions may be overwritten.");
            //}
            if (!Directory.Exists(acqQuickScanFolder.ToString()))
            {
                Directory.CreateDirectory(acqQuickScanFolder.ToString());
            }
            if (!Directory.Exists(acqLogFolder.ToString()))
            {
                Directory.CreateDirectory(acqLogFolder.ToString());
            }
            if (!Directory.Exists(acqPreviewFolder.ToString()))
            {
                Directory.CreateDirectory(acqPreviewFolder.ToString());
            }
            if (!Directory.Exists(acqThumbnailFolder.ToString()))
            {
                Directory.CreateDirectory(acqThumbnailFolder.ToString());
            }

            // copy file parameters to structure
            string[]      fieldNames = { "acqFolder", "acqQuickScanFolder", "acqLogFolder", "acqPreviewFolder", "acqThumbnailFolder", "dataName" };
            MWStructArray fP         = new MWStructArray(1, 1, fieldNames);

            fP.SetField("acqFolder", acqFolder);
            fP.SetField("acqQuickScanFolder", acqQuickScanFolder);
            fP.SetField("acqLogFolder", acqLogFolder);
            fP.SetField("acqPreviewFolder", acqPreviewFolder);
            fP.SetField("acqThumbnailFolder", acqThumbnailFolder);
            fP.SetField("dataName", dataName);

            // Define acquisition parameters
            MWNumericArray y_0 = acquisitionParameters.y_0;
            MWNumericArray x_0 = acquisitionParameters.x_0;
            MWNumericArray l_y = acquisitionParameters.l_y;
            MWNumericArray l_x = acquisitionParameters.l_x;
            MWNumericArray ds  = acquisitionParameters.ds;
            MWNumericArray PRR = acquisitionParameters.PRR;
            MWNumericArray triggerWidth;

            if (systemState.LASERconnected == 1) // Wedge
            {
                triggerWidth = 130;              // [us]
            }
            else
            {
                triggerWidth = 5;
            }
            MWNumericArray f_s                    = acquisitionParameters.f_s;
            MWNumericArray inputRange             = acquisitionParameters.inputRange_list[acquisitionParameters.inputRange_listIndex];
            MWNumericArray z_low                  = acquisitionParameters.z_low;
            MWNumericArray z_target               = acquisitionParameters.z_target;
            MWNumericArray z_high                 = acquisitionParameters.z_high;
            MWNumericArray v_x                    = acquisitionParameters.v_x;
            MWNumericArray acc                    = acquisitionParameters.acc;
            MWNumericArray acqDelay               = acquisitionParameters.acqDelay;
            MWNumericArray d_acc                  = acquisitionParameters.d_acc;
            MWNumericArray acqRes                 = acquisitionParameters.acqRes;
            MWArray        acqMode                = acquisitionParameters.acqMode;
            MWNumericArray triggerLevel           = acquisitionParameters.triggerLevel;
            MWNumericArray numberOfWavelength     = acquisitionParameters.numberOfWavelength;
            MWNumericArray BscanUpdate            = acquisitionParameters.BscanUpdate;
            MWArray        controllerSerialNumber = acquisitionParameters.controllerSerialNumber;
            MWNumericArray quickScan              = 0;

            //get number of wavelength from comment box
            if (!string.IsNullOrEmpty(comment))
            {
                char[]   delimiterChars = { ' ', ',', '.', ':', ';', '\t' };
                string[] tokens         = comment.Split(delimiterChars);
                int[]    convertedItems = Array.ConvertAll <string, int>(tokens, int.Parse);
                numberOfWavelength = convertedItems.Length;
                //Console.WriteLine(convertedItems);
            }
            // copy file parameters to structure
            string[]      fieldNames2 = { "y_0",    "x_0",                    "l_y",      "l_x",        "ds",
                                          "PRR",         "triggerWidth",           "f_s",      "inputRange", "z_low", "z_target", "z_high",
                                          "v_x",         "acc",                    "acqDelay", "d_acc",      "acqRes","acqMode",  "triggerLevel","numberOfWavelength",
                                          "BscanUpdate", "controllerSerialNumber", "quickScan" };
            MWStructArray aP = new MWStructArray(1, 1, fieldNames2);

            aP.SetField("y_0", y_0);
            aP.SetField("x_0", x_0);
            aP.SetField("l_y", l_y);
            aP.SetField("l_x", l_x);
            aP.SetField("ds", ds);
            aP.SetField("PRR", PRR);
            aP.SetField("triggerWidth", triggerWidth);
            aP.SetField("f_s", f_s);
            aP.SetField("inputRange", inputRange);
            aP.SetField("z_low", z_low);
            aP.SetField("z_target", z_target);
            aP.SetField("z_high", z_high);
            aP.SetField("v_x", v_x);
            aP.SetField("acc", acc);
            aP.SetField("acqDelay", acqDelay);
            aP.SetField("d_acc", d_acc);
            aP.SetField("acqRes", acqRes);
            aP.SetField("acqMode", acqMode);
            aP.SetField("triggerLevel", triggerLevel);
            aP.SetField("numberOfWavelength", numberOfWavelength);
            aP.SetField("BscanUpdate", BscanUpdate);
            aP.SetField("controllerSerialNumber", controllerSerialNumber);
            aP.SetField("quickScan", quickScan);

            // Define reconstruction parameters
            MWNumericArray t_focus = detectorParameters.t_focus;

            // copy file parameters to structure
            string[]      fieldNames3 = { "t_focus" };
            MWStructArray dP          = new MWStructArray(1, 1, fieldNames3);

            dP.SetField("t_focus", t_focus);

            // Define reconstruction parameters
            MWNumericArray v_s = reconstructionParameters.v_s;

            // copy file parameters to structure
            string[]      fieldNames4 = { "v_s" };
            MWStructArray rP          = new MWStructArray(1, 1, fieldNames4);

            rP.SetField("v_s", v_s);

            try
            {
                //if (systemState.LASERconnected == 0 || systemState.DAQconnected == 0 || systemState.STAGESconnected == 0)
                if (systemState.DAQconnected == 0 || systemState.STAGESconnected == 0)
                {
                    iScanClass_mock obj_mock = null;
                    obj_mock = new iScanClass_mock();
                    obj_mock.iScan_mock(fP, aP, dP, rP);
                }
                else
                {
                    // choose right kernel for stages
                    switch (systemState.DAQconnected)
                    {
                    case 1:     // Gage

                        if (acquisitionParameters.triggerMode == 0)
                        {
                            iScanClass_OPO obj = null;
                            obj = new iScanClass_OPO();
                            obj.iScan_dual(fP, aP, dP, rP);
                        }
                        else
                        {
                            iScanClass_trig obj_trig = null;
                            obj_trig = new iScanClass_trig();
                            obj_trig.iScan_trig(fP, aP, dP, rP);
                        }
                        break;

                    case 2:     // Alazar
                        if (acquisitionParameters.triggerMode == 0)
                        {
                            iScanClass_Alazar obj_Alazar = null;
                            obj_Alazar = new iScanClass_Alazar();
                            obj_Alazar.iScan_Alazar(fP, aP, dP, rP);
                        }
                        else
                        {
                            Console.WriteLine("ERROR: Alazar external trigger not yet implmented.");
                        }
                        break;

                    default:
                        Console.WriteLine("ERROR: Settings say there is no DAQ connected.");
                        break;
                    }

                    // switch off laser and close connection
                    //if (systemState.LASERconnected == 1 || systemState.LASERconnected == 2)
                    {
                        // switch laser off and close connection
                        multiLaser.q_switch(false);

                        multiLaser.lamp(false);
                        //cancelAcq_Button.Click -= multiLaser.laserHandle;
                    }
                }
            }
            catch (Exception e)
            {
                // check if laser emission can be stopped
                if (multiLaser != null)
                {
                    try
                    {
                        multiLaser.q_switch(false);
                        multiLaser.lamp(false);
                        //cancelAcq_Button.Click -= multiLaser.laserHandle;
                    }
                    catch
                    {
                        Console.WriteLine("WARNING: switch off laser EMISSION if necessary.");
                    };
                }

                if (!e.Message.Contains("ERROR:"))
                {
                    Console.WriteLine("ERROR:" + e.Message);
                }
                Console.WriteLine("\n");
                Console.WriteLine("Status-Acq: 1.00");
            }

            // write xml-file
            XDocument acqXML = new XDocument(
                new XElement("acquisitionParameters",
                             new XElement("l_y", l_y.ToString()),
                             new XElement("l_x", l_x.ToString()),
                             new XElement("ds", ds.ToString()),
                             new XElement("PRR", PRR.ToString()),
                             new XElement("laserEnergy", acquisitionParameters.laserPower.ToString()),
                             new XElement("f_s", f_s.ToString()),
                             new XElement("inputRange", inputRange.ToString()),
                             new XElement("z_low", z_low.ToString()),
                             new XElement("z_high", z_high.ToString()),
                             new XElement("numberOfWavelength", numberOfWavelength.ToString()),
                             new XElement("comment", comment)
                             )
                );

            acqXML.Declaration = new XDeclaration("1.0", "utf-8", "true");

            string filename = acqFolder.ToString() + dataName.ToString() + ".xml";

            acqXML.Save(@filename);
        }