Пример #1
0
        private Ai.Hong.CommonLibrary.SpecFileFormatDouble ScanningSample(int scanCount, string specPath, string File, string addPara)
        {
            OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            OpusCMD334.UnloadFile  unLoad  = new OpusCMD334.UnloadFile();
            Ai.Hong.CommonLibrary.SpecFileFormatDouble spcData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();

            string commandStr = "MeasureSample ({NSS = " + scanCount + "," + "PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
                                "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + "})";

            if (scanCount == 0)
            {
                commandStr = commandStr.Replace("NSS = " + scanCount + ",", string.Empty);
            }

            if (!command.Command(commandStr, true))
            {
                ErrorString = command.ErrorDesc;
                return(null);
            }
            specPath = specPath.Replace(".spc", string.Empty);
            if (!unLoad.Unload(specPath))
            {
                ErrorString = unLoad.ErrorDesc;
                return(null);
            }
            if (!spcData.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.SingleBeam))
            {
                ErrorString = spcData.ErrorString;
                return(null);
            }
            // System.Windows.MessageBox.Show(spcData.Parameter.)
            return(spcData);
        }
Пример #2
0
        /// <summary>
        /// 写入激光波数到仪器
        /// </summary>
        /// <param name="waveNum"></param>
        /// <returns></returns>
        public override bool?SetLaserWavelength(double curPeak, double targetPeak, ref double curLaser)
        {
            double?curLwn = GetLaserWavelength();

            if (!curLwn.HasValue)
            {
                return(null);
            }
            curLaser = 10000 / (double)curLwn * curPeak / targetPeak;
            double write = 10000 / curLaser;

            OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            if (!command.Command("SendCommand(0, {UNI='xwn=" + write.ToString() + "@\"' })"))
            {
                ErrorString = command.ErrorDesc;
                return(null);
            }
            bool?result = null;

            //重启仪器
            System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                new WebBrowser().Navigate("http://" + IpAddress + "/config/resetpage.htm?Sub=RESET+INSTRUMENT");
                Thread.Sleep(3000);
                //等待仪器重启
                ProcessWaitDialog waitDialog = new ProcessWaitDialog((ProcessWaitDialog.SetProcessAndMsgDeletage callBack) =>
                {
                    int i      = 0;
                    string str = "";
                    while (true)
                    {
                        i++;
                        for (int j = 0; j <= i % 6; j++)
                        {
                            str += ".";
                        }
                        callBack("Please Wait", int.MaxValue, int.MaxValue, "Reset Instrument Now" + str, false);
                        var html = DownloadWebPage("http://" + IpAddress + "/config/report.htm");
                        if (!string.IsNullOrEmpty(html))
                        {
                            break;
                        }
                        System.Threading.Thread.Sleep(500);
                        str = "";
                    }
                    return(true);
                });

                if (Application.Current.Windows.Count > 1)
                {
                    waitDialog.Owner = Application.Current.Windows[Application.Current.Windows.Count - 2];
                }
                else
                {
                    waitDialog.Owner = System.Windows.Application.Current.MainWindow;
                }
                result = waitDialog.ShowDialog() == true;
            }));
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 移动转轮
        /// </summary>
        /// <param name="position">0 = 打开, 1 = NG4滤光玻璃, 2 = 聚苯乙烯, 3 = 过滤网</param>
        /// <returns></returns>
        public override bool?MoveWheel(int position, string iniFilePath)
        {
            //lock (thisLock)
            //{
            if (!System.IO.File.Exists(iniFilePath))
            {
                ErrorString = "file: \r\n" + iniFilePath + "\r\n is not exist!";
                return(null);
            }
            if (!LoadXPM(iniFilePath))
            {
                return(null);
            }
            OpusCMD334.OpusCommand    command   = new OpusCMD334.OpusCommand();
            OpusCMD334.WriteParameter writePara = new OpusCMD334.WriteParameter();

            bool result = false;

            // string para = "apt", value = "3";

            switch (position)
            {
            //APT= 1(BRM2065) 2(Filter NG9) 3(Filter NG4) 4(Filter NG11) 5(Reference Spectralon) 10(Open)
            case 0:
                //result=command.Command("SendCommand (0, {UNI='apt=10'}");
                result = writePara.WriteParm("APT", "Open", iniFilePath, false);
                //result = command.Command("SendCommand (0, {UNI='apt=10'}");
                break;        //OPEN

            case 1:
                //result = command.Command("SendCommand (0, {UNI='apt=3'}");
                result = writePara.WriteParm("APT", "Filter NG4", iniFilePath, false);
                //result = command.Command("SendCommand (0, {UNI='apt=3'}");
                break;        //Filter NG4

            case 2:
                //result = command.Command("SendCommand (0, {UNI='apt=1'}");
                result = writePara.WriteParm("APT", "Filter BRM2065", iniFilePath, false);
                //result = command.Command("SendCommand (0, {UNI='apt=1'}");
                break;        //BRM2065

            default: result = true; break;
            }
            if (!result)
            {
                ErrorString = writePara.ErrorDesc;
            }
            if (!LoadXPM(iniFilePath))
            {
                return(null);
            }
            return(result);
            //}
        }
        private static bool SaveAsSPC(string opusFile, string spcFile)
        {
            //SaveAs ([<$ResultFile 1>:Spec], {DAP='E:\Project\VspecNirCloud\CloudManager\bin\Release\Data\IT_Tango\PQ\2015_11_30\14_39_59\LineNoiseAndDevTest', OEX='1', SAN='LineNoiseAndDevTest_2015-11-30 14-39-59.0.spc', COF=256, DPA=5, DPO=5, SEP=',', YON='0', ADP='1', X64='1'});
            OpusCMD334.OpusCommand cmd = new OpusCMD334.OpusCommand();
            string cmdstr  = string.Format("SaveAs ([{0}:Spec], {{DAP='{1}', OEX='1', SAN='{2}', COF=256, DPA=5, DPO=5, SEP=',', YON='0', ADP='1', X64='1'}});", opusFile, System.IO.Path.GetDirectoryName(spcFile), System.IO.Path.GetFileName(spcFile));
            bool   cmdcode = cmd.Command(cmdstr);

            string[] cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(false);
            }

            return(true);
        }
        private static bool ChangeDataBlockType(string opusFile, string srcType, string dstType)
        {
            //改变数据块类型
            OpusCMD334.OpusCommand cmd = new OpusCMD334.OpusCommand();
            string cmdstr  = string.Format("ChangeDataBlockType ([{0}:{1}], {{CBT='{2}'}});", opusFile, srcType, dstType);
            bool   cmdcode = cmd.Command(cmdstr);

            string[] cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(false);
            }

            return(true);
        }
Пример #6
0
        /// <summary>
        /// 用Command保存OPUS中的文件
        /// </summary>
        /// <param name="opusFile"></param>
        /// <returns></returns>
        private bool SaveFileByCommand(string opusFile)
        {
            OpusCMD334.OpusCommand cmd = new OpusCMD334.OpusCommand();

            string cmdstr  = string.Format("Save ([{0}:Spec], {{}});", opusFile);
            bool   cmdcode = cmd.Command(cmdstr);

            string[] cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 3 || cmdrets[0] != "OK")
            {
                return(false);
            }

            return(true);
        }
Пример #7
0
        /// <summary>
        /// 写入激光波数到仪器
        /// </summary>
        /// <param name="waveNum"></param>
        /// <returns></returns>
        public override bool?SetLaserWavelength(double curPeak, double targetPeak, ref double curLaser)
        {
            double?curLwn = GetLaserWavelength();

            if (!curLwn.HasValue)
            {
                return(null);
            }
            curLaser = 10000 / (double)curLwn * curPeak / targetPeak;
            double write = 10000 / curLaser;

            OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            if (!command.Command("SendCommand(0, {UNI='xwn=" + write.ToString() + "@\"' })"))
            {
                ErrorString = command.ErrorDesc;
                return(null);
            }
            return(true);
        }
Пример #8
0
        /// <summary>
        /// 通过Command加载文件
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <returns>加载到OPUS中的文件名</returns>
        private static string LoadFileByCommand(string filename)
        {
            if (filename == null || !System.IO.File.Exists(filename))
            {
                return(null);
            }

            OpusCMD334.OpusCommand cmd = new OpusCMD334.OpusCommand();
            //加载文件
            string cmdstr  = string.Format(" Load (, {{COF=0, DAP='{0}', DAF='{1}'}});", System.IO.Path.GetDirectoryName(filename), System.IO.Path.GetFileName(filename));
            bool   cmdcode = cmd.Command(cmdstr);

            string[] cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 4 || cmdrets[0] != "OK")
            {
                return(null);
            }

            return(cmdrets[3]);
        }
        public static string ChangeWaterRangeToAB(string spectrumFile, string saveFile)
        {
            try
            {
                OpusCMD334.OpusCommand cmd = new OpusCMD334.OpusCommand();

                //加载文件
                string cmdstr = "Load (, {COF=0, DAP='" + System.IO.Path.GetDirectoryName(spectrumFile) + "', DAF='" + System.IO.Path.GetFileName(spectrumFile) + "'});";
                if (cmd.Command(cmdstr) == false)
                {
                    throw new Exception("Load Error:" + cmd.ErrorDesc);
                }

                string[] rets    = cmd.CommandResult.Split('\n');
                string   retname = rets[3];
                cmdstr = "Calculator ([" + retname + ":Spec], {FOR='[" + retname + ":Spec]'});";
                if (cmd.Command(cmdstr) == false)
                {
                    throw new Exception("Load Error:" + cmd.ErrorDesc);
                }

                cmdstr = "Cut ([" + retname + ":Spec], {{CFX=6900.000000, CLX=7500.000000});";
                if (cmd.Command(cmdstr) == false)
                {
                    throw new Exception("Load Error:" + cmd.ErrorDesc);
                }

                cmdstr = "Baseline ([" + retname + ":Spec], {BME=3});";
                if (cmd.Command(cmdstr) == false)
                {
                    throw new Exception("Load Error:" + cmd.ErrorDesc);
                }

                cmdstr = "ABTR ([" + retname + ":Spec], {CCM=3});";
                if (cmd.Command(cmdstr) == false)
                {
                    throw new Exception("Load Error:" + cmd.ErrorDesc);
                }

                //Normalize ([<$ResultFile 4>:AB], {NME=1, NFX=4000.000000, NLX=400.000000, NWR=1});
                cmdstr = "Normalize ([" + retname + ":Spec], {NME=1, NFX=4000.000000, NLX=400.000000, NWR=1});";
                if (cmd.Command(cmdstr) == false)
                {
                    throw new Exception("Load Error:" + cmd.ErrorDesc);
                }

                //SaveAs ([<$ResultFile 4>], {DAP='D:', OEX='1', SAN='AccurancyResult.0', YON='0'});
                cmdstr = "SaveAs ([" + retname + "], {DAP='" + System.IO.Path.GetDirectoryName(saveFile) + "', OEX='1', SAN='" + System.IO.Path.GetFileName(saveFile) + "', YON='0'});";
                if (cmd.Command(cmdstr) == false)
                {
                    throw new Exception("Load Error:" + cmd.ErrorDesc);
                }

                return(saveFile);
            }
            catch (Exception ex)
            {
                ErrorString = ex.ToString();
                return(null);
            }
        }
        /// <summary>
        /// 获取激光矫正光谱
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="firstX">校正范围</param>
        /// <param name="lastX">校正范围</param>
        /// <returns></returns>
        public static string GetLaserWavelengthDataaaa(string filename, double firstX = 6900, double lastX = 7500)
        {
            if (filename == null || !System.IO.File.Exists(filename))
            {
                return(null);
            }

            OpusCMD334.OpusCommand cmd = new OpusCMD334.OpusCommand();

            //加载文件
            string cmdstr  = string.Format(" Load (, {{COF=0, DAP='{0}', DAF='{1}'}});", System.IO.Path.GetDirectoryName(filename), System.IO.Path.GetFileName(filename));
            bool   cmdcode = cmd.Command(cmdstr);

            string[] cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 3 || cmdrets[0] != "OK")
            {
                return(null);
            }

            //剪切
            string opusfile = cmdrets[3];

            cmdstr  = string.Format("Cut ([{0}:Spec], {{CFX={1}, CLX={2}}});", opusfile, firstX, lastX);
            cmdcode = cmd.Command(cmdstr);
            cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(null);
            }

            //基线校正
            cmdstr  = string.Format("Baseline ([{0}:Spec], {{BME=3}});", opusfile);
            cmdcode = cmd.Command(cmdstr);
            cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(null);
            }

            //最大最小归一化
            cmdstr  = string.Format("Normalize ([{0}:Spec], {{NME=1, NFX=4000.000000, NLX=400.000000, NWR=1}});", opusfile);
            cmdcode = cmd.Command(cmdstr);
            cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(null);
            }

            //改变数据块类型
            cmdstr  = string.Format("ChangeDataBlockType ([{0}:Spec], {{CBT='AB'}});", opusfile);
            cmdcode = cmd.Command(cmdstr);
            cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(null);
            }

            //另存文件
            cmdstr  = string.Format("Save ([{0}:Spec], {{}});", opusfile);
            cmdcode = cmd.Command(cmdstr);
            cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 3 || cmdrets[0] != "OK")
            {
                return(null);
            }

            //卸载文件
            cmdstr  = string.Format("Unload ([{0}:Spec], {{}});", opusfile);
            cmdcode = cmd.Command(cmdstr);
            cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(null);
            }
            return(filename);
        }
Пример #11
0
        private Ai.Hong.CommonLibrary.SpecFileFormatDouble ScanningBack(int scanCount, string specPath, string File, string addPara)
        {
            OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            OpusCMD334.UnloadFile  unLoad  = new OpusCMD334.UnloadFile();
            Ai.Hong.CommonLibrary.SpecFileFormatDouble spcData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();

            string commandStr = "MeasureReference ({NSR = " + scanCount + ",APT='Open' " + addPara + "})";

            if (scanCount == 0)
            {
                commandStr = commandStr.Replace("NSR = " + scanCount + ",", string.Empty);
            }
            if (!command.Command(commandStr, true))
            {
                ErrorString = command.ErrorDesc;
                return(null);
            }
            //System.Windows.MessageBox.Show("Scan Complete! " + specPath);
            OpusCMD334.SaveReference saveBack = new OpusCMD334.SaveReference();
            //System.Windows.MessageBox.Show("begin Save reference " + File);
            if (!saveBack.SaveReference(System.IO.Path.GetFileName(File), System.IO.Path.GetDirectoryName(File)))
            {
                ErrorString = saveBack.ErrorDesc;
                return(null);
            }
            //System.Windows.MessageBox.Show("begin UnLoad " +File );
            if (System.IO.File.Exists(File) && !unLoad.Unload(File))
            {
                ErrorString = unLoad.ErrorDesc;
                return(null);
            }
            //System.Windows.MessageBox.Show("begin UnLoad " + specPath);
            if (System.IO.File.Exists(specPath) && !unLoad.Unload(specPath))
            {
                ErrorString = unLoad.ErrorDesc;
                return(null);
            }
            //System.Windows.MessageBox.Show("UnLoad Complete " + specPath);
            if (System.IO.File.Exists(specPath) && !spcData.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.Background))
            {
                //System.Windows.MessageBox.Show("read error !" + specPath);
                ErrorString = spcData.ErrorString;
                return(null);
            }
            if (System.IO.File.Exists(File) && !spcData.ReadFile(File, Ai.Hong.CommonLibrary.SpecFileFormat.specType.Background))
            {
                //System.Windows.MessageBox.Show("read error !" + File);
                ErrorString = spcData.ErrorString;
                return(null);
            }
            if (addPara != null && addPara.Contains("HFQ") && addPara.Contains("LFQ"))
            {
                try
                {
                    string[] temp     = addPara.Split(',');
                    string   fxString = (from p in temp where p.Contains("HFQ") select p).First().Trim().Replace("HFQ=", string.Empty);
                    string   lxString = (from p in temp where p.Contains("LFQ") select p).First().Trim().Replace("LFQ=", string.Empty);
                    Ai.Hong.CommonLibrary.SpecFileFormatDouble backData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
                    backData.Parameter = spcData.Parameter;
                    int indexX = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, Convert.ToInt32(fxString));
                    int indexY = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, Convert.ToInt32(lxString));

                    if (indexX != -1 && indexY != -1)
                    {
                        float[] tun = new float[Math.Abs(indexX - indexY) + 1];
                        backData.XDatas = new double[tun.Length];
                        backData.YDatas = new double[tun.Length];
                        for (int i = indexX; i < indexY + 1; i++)
                        {
                            tun[i - indexX]             = (float)spcData.XDatas[i];
                            backData.XDatas[i - indexX] = spcData.XDatas[i];
                            backData.YDatas[i - indexX] = spcData.YDatas[i];
                        }
                        backData.Parameter.dataCount = (uint)tun.Length;
                        if (tun.Length > 0)
                        {
                            backData.Parameter.firstX = tun[0];
                            backData.Parameter.lastX  = tun[tun.Length - 1];
                        }
                        backData.Parameter.maxYValue = (from p in tun select p).ToList().Max();
                        backData.Parameter.maxYValue = (from p in tun select p).ToList().Min();
                        spcData = backData;
                    }
                }
                catch { }
            }
            //Ai.Hong.CommonLibrary.SpecFileFormatDouble backData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            //backData.Parameter = spcData.Parameter;
            //int indexX = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, 4000);
            //int indexY = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, 12000);

            //if (indexX != -1 && indexY != -1)
            //{
            //    float[] tun = new float[Math.Abs(indexX - indexY) + 1];
            //    backData.XDatas = new double[tun.Length];
            //    backData.YDatas = new double[tun.Length];
            //    for (int i = indexX; i < indexY + 1; i++)
            //    {
            //        tun[i - indexX] = (float)spcData.XDatas[i];
            //        backData.XDatas[i - indexX] = spcData.XDatas[i];
            //        backData.YDatas[i - indexX] = spcData.YDatas[i];
            //    }
            //    backData.Parameter.dataCount = (uint)tun.Length;
            //    if (tun.Length > 0)
            //    {
            //        backData.Parameter.firstX = tun[0];
            //        backData.Parameter.lastX = tun[tun.Length - 1];
            //    }
            //    backData.Parameter.maxYValue = (from p in tun select p).ToList().Max();
            //    backData.Parameter.maxYValue = (from p in tun select p).ToList().Min();
            //    spcData = backData;
            //}
            return(spcData);
        }
Пример #12
0
        private string ScanSpec(string scanMethodFile, int scanCount, string File, bool IsScanBack, string addPara = "")
        {
            if (!LoadXPM(scanMethodFile) || !System.IO.Path.HasExtension(File))
            {
                return(null);
            }
            if (IsScanBack)
            {
                MoveWheel(0, scanMethodFile);
            }
            string specPath = File + ".0";

            if (System.IO.File.Exists(specPath))
            {
                OpusCMD334.UnloadFile unLoadFile = new OpusCMD334.UnloadFile();
                unLoadFile.Unload(specPath);
                System.IO.File.Delete(specPath);
            }
            if (System.IO.File.Exists(File))
            {
                System.IO.File.Delete(File);
            }

            OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            OpusCMD334.UnloadFile  unLoad  = new OpusCMD334.UnloadFile();
            Ai.Hong.CommonLibrary.SpecFileFormatDouble spcData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (IsScanBack)
            {
                string para = addPara;
                if (addPara == null || (addPara != null && !addPara.Contains("HFQ") && !addPara.Contains("LFQ")))
                {
                    //OpusCMD334.ReadParameter read = new OpusCMD334.ReadParameter();
                    //if (!read.ReadParm("HFQ", scanMethodFile))
                    //{
                    //    ErrorString = "Read HFQ Error! Please Restart System";
                    //    return null;
                    //}
                    //para += ",HFQ=" + read.Value;
                    //if (!read.ReadParm("LFQ", scanMethodFile))
                    //{
                    //    ErrorString = "Read LFQ Error! Please Restart System";
                    //    return null;
                    //}
                    //para += ",LFQ=" + read.Value;
                    para += ",HFQ=4000,LFQ=12000";//默认为4000-12000
                }
                //System.Windows.MessageBox.Show("begin Scan " + specPath);
                spcData = ScanningBack(scanCount, specPath, File, para);
            }
            else
            {
                spcData = ScanningSample(scanCount, specPath, File, addPara);
                //if (spcData == null)
                //{
                //    ScanningBack(scanCount, specPath, File);
                //    spcData = ScanningSample(scanCount, specPath, File, addPara);
                //}
            }
            if (spcData == null)
            {
                ErrorString = "Scan Error";
                return(null);
            }
            float[] tr = new float[spcData.YDatas.Count()];
            for (int i = 0; i < spcData.YDatas.Count(); i++)
            {
                tr[i] = (float)spcData.YDatas[i];
            }
            Ai.Hong.CommonLibrary.SPCFile.SaveFile(File, tr, spcData.Parameter);

            //System.IO.File.Move(specPath, File);
            if (System.IO.File.Exists(specPath) && !string.Equals(specPath, File))
            {
                unLoad.Unload(specPath);
                System.IO.File.Delete(specPath);
            }
            return(File);
            //if (!LoadXPM(scanMethodFile) || !System.IO.Path.HasExtension(File))
            //{
            //    return null;
            //}
            //if (IsScanBack)
            //{
            //    MoveWheel(0, scanMethodFile);
            //}
            //string specPath = File.Replace(".spc", ".0");
            //if (System.IO.File.Exists(specPath))
            //{
            //    OpusCMD334.UnloadFile unLoadFile = new OpusCMD334.UnloadFile();
            //    unLoadFile.Unload(specPath);
            //    System.IO.File.Delete(specPath);
            //}
            //if (System.IO.File.Exists(File))
            //{
            //    System.IO.File.Delete(File);
            //}

            //OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            //OpusCMD334.UnloadFile unLoad = new OpusCMD334.UnloadFile();

            //Ai.Hong.CommonLibrary.SpecFileFormatDouble data = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            //if (IsScanBack)
            //{
            //    string commandString = "MeasureReference ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
            //        "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + " })";
            //    bool retcode = command.Command(commandString, true);
            //    string[] retstrs = command.CommandResult.Split('\n');
            //    if (retcode == false || retstrs.Length < 1 || retstrs[0] != "OK")
            //    {
            //        ErrorString = command.ErrorDesc;
            //        return null;
            //    }
            //    if (addPara != null)
            //        addPara = addPara.Replace("NSR", "NSS");
            //    commandString = "MeasureSample ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
            //        "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + "})";
            //    retcode = command.Command(commandString, true);
            //    retstrs = command.CommandResult.Split('\n');
            //    if (retcode == false || retstrs.Length < 4 || retstrs[0] != "OK")
            //    {
            //        ErrorString = command.ErrorDesc;
            //        return null;
            //    }
            //    UnloadFileByCommand(retstrs[3]);
            //    //if (!unLoad.Unload(specPath))
            //    //{
            //    //    ErrorString = unLoad.ErrorDesc;
            //    //    return null;
            //    //}
            //    if (!data.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.Background))
            //    {
            //        ErrorString = data.ErrorString;
            //        return null;
            //    }

            //}
            //else
            //{
            //    string cmdstr = "MeasureSample ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
            //        "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + "})";
            //    if (!command.Command(cmdstr, true))
            //    {
            //        ErrorString = command.ErrorDesc;
            //        return null;
            //    }
            //    if (!unLoad.Unload(specPath))
            //    {
            //        ErrorString = unLoad.ErrorDesc;
            //        return null;
            //    }
            //    if (!data.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.SingleBeam))
            //    {
            //        ErrorString = data.ErrorString;
            //        return null;
            //    }
            //}
            //float[] tr = new float[data.YDatas.Count()];
            //for (int i = 0; i < data.YDatas.Count(); i++)
            //{
            //    tr[i] = (float)data.YDatas[i];
            //}
            //Ai.Hong.CommonLibrary.SPCFile.SaveFile(File, tr, data.Parameter);


            //if (System.IO.File.Exists(specPath) && !string.Equals(specPath, File))
            //{
            //    unLoad.Unload(specPath);
            //    System.IO.File.Delete(specPath);
            //}
            //return File;
        }
Пример #13
0
        /// <summary>
        /// 光谱兼容处理
        /// </summary>
        /// <param name="sourceFile">需要处理的光谱</param>
        /// <param name="destFile">标准光谱</param>
        /// <returns></returns>
        public override string MakeCompatiable(string sourceFile, string destFile)
        {
            Ai.Hong.CommonLibrary.SpecFileFormatDouble sourceData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (!sourceData.ReadFile(sourceFile))
            {
                return(null);
            }
            Ai.Hong.CommonLibrary.SpecFileFormatDouble destData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (!destData.ReadFile(destFile))
            {
                return(null);
            }
            bool IsNeedChange = false;

            if (sourceData.YDatas.Count() < destData.YDatas.Count())
            {
                IsNeedChange = true;
                string temp = sourceFile;
                sourceFile = destFile;
                destFile   = temp;
            }
            string opusSrcFile = LoadFileByCommand(sourceFile);
            string opusDstFile = LoadFileByCommand(destFile);

            if (opusSrcFile == null || opusDstFile == null)
            {
                if (opusSrcFile != null)
                {
                    UnloadFileByCommand(opusSrcFile);
                }

                if (opusDstFile != null)
                {
                    UnloadFileByCommand(opusDstFile);
                }
                return(null);
            }

            if (ChangeDataBlockType(opusSrcFile, "Spec", "AB") == false)
            {
                return(null);
            }

            if (ChangeDataBlockType(opusDstFile, "Spec", "AB") == false)
            {
                return(null);
            }

            //谱图兼容
            OpusCMD334.OpusCommand cmd = new OpusCMD334.OpusCommand();
            string cmdstr  = string.Format("MakeCompatible ([{0}:Spec], [{1}:Spec], {{}});", opusDstFile, opusSrcFile);
            bool   cmdcode = cmd.Command(cmdstr);

            string[] cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 4 || cmdrets[0] != "OK")
            {
                return(null);
            }



            //SaveAsSPC(opusSrcFile, sourceFile);
            //SaveAsSPC(opusDstFile, destFile);

            //
            if (SaveFileByCommand(opusSrcFile) == false ||
                SaveFileByCommand(opusDstFile) == false ||
                UnloadFileByCommand(opusSrcFile) == false ||
                UnloadFileByCommand(opusDstFile) == false)
            {
                return(null);
            }
            if (IsNeedChange)
            {
                string temp = sourceFile;
                sourceFile = destFile;
                destFile   = temp;
            }
            return(sourceFile);
        }
Пример #14
0
        public override string SpecProcess(string filename, double firstX = 6900, double lastX = 7500)
        {
            if (filename == null || !System.IO.File.Exists(filename))
            {
                return(null);
            }

            OpusCMD334.OpusCommand cmd = new OpusCMD334.OpusCommand();

            //加载文件
            string opusfile = LoadFileByCommand(filename);

            if (opusfile == null)
            {
                return(null);
            }

            //剪切
            string cmdstr  = string.Format("Cut ([{0}:Spec], {{CFX={1}, CLX={2}}});", opusfile, firstX, lastX);
            bool   cmdcode = cmd.Command(cmdstr);

            string[] cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(null);
            }

            //基线校正
            cmdstr  = string.Format("Baseline ([{0}:Spec], {{BME=3}});", opusfile);
            cmdcode = cmd.Command(cmdstr);
            cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(null);
            }

            //最大最小归一化
            cmdstr  = string.Format("Normalize ([{0}:Spec], {{NME=1, NFX=4000.000000, NLX=400.000000, NWR=1}});", opusfile);
            cmdcode = cmd.Command(cmdstr);
            cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(null);
            }

            //改变数据块类型
            cmdstr  = string.Format("ChangeDataBlockType ([{0}:Spec], {{CBT='AB'}});", opusfile);
            cmdcode = cmd.Command(cmdstr);
            cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 1 || cmdrets[0] != "OK")
            {
                return(null);
            }

            if (SaveFileByCommand(opusfile) == false || UnloadFileByCommand(opusfile) == false)
            {
                return(null);
            }

            return(filename);
        }
Пример #15
0
        private string ScanSpec(string scanMethodFile, int scanCount, string File, bool IsScanBack, string addPara = "")
        {
            //if (!LoadXPM(scanMethodFile) || !System.IO.Path.HasExtension(File))
            //{
            //    return null;
            //}
            //if (IsScanBack)
            //{
            //    MoveWheel(0, scanMethodFile);
            //}
            //string specPath = File + ".0";
            //if (System.IO.File.Exists(specPath))
            //{
            //    OpusCMD334.UnloadFile unLoadFile = new OpusCMD334.UnloadFile();
            //    unLoadFile.Unload(specPath);
            //    System.IO.File.Delete(specPath);
            //}
            //if (System.IO.File.Exists(File))
            //{
            //    System.IO.File.Delete(File);
            //}

            //OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            //OpusCMD334.UnloadFile unLoad = new OpusCMD334.UnloadFile();
            //Ai.Hong.CommonLibrary.SpecFileFormatDouble spcData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            //if (IsScanBack)
            //{
            //    if (!command.Command("MeasureReference ({NSR = " + scanCount + "})", true))
            //    {
            //        ErrorString = command.ErrorDesc;
            //        return null;
            //    }
            //    OpusCMD334.SaveReference saveBack = new OpusCMD334.SaveReference();
            //    if (!saveBack.SaveReference(System.IO.Path.GetFileName(File), System.IO.Path.GetDirectoryName(File)))
            //    {
            //        ErrorString = saveBack.ErrorDesc;
            //        return null;
            //    }
            //    if (!unLoad.Unload(specPath))
            //    {
            //        ErrorString = unLoad.ErrorDesc;
            //        return null;
            //    }
            //    if (!spcData.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.Background))
            //    {
            //        ErrorString = spcData.ErrorString;
            //        return null;
            //    }
            //    Ai.Hong.CommonLibrary.SpecFileFormatDouble backData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            //    backData.Parameter = spcData.Parameter;
            //    int indexX = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, 4000);
            //    int indexY = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, 12000);

            //    if (indexX != -1 && indexY != -1)
            //    {
            //        float[] tun = new float[Math.Abs(indexX - indexY) + 1];
            //        backData.XDatas = new double[tun.Length];
            //        backData.YDatas = new double[tun.Length];
            //        for (int i = indexX; i < indexY + 1; i++)
            //        {
            //            tun[i - indexX] = (float)spcData.XDatas[i];
            //            backData.XDatas[i - indexX] = spcData.XDatas[i];
            //            backData.YDatas[i - indexX] = spcData.YDatas[i];
            //        }
            //        backData.Parameter.dataCount = (uint)tun.Length;
            //        if (tun.Length > 0)
            //        {
            //            backData.Parameter.firstX = tun[0];
            //            backData.Parameter.lastX = tun[tun.Length - 1];
            //        }
            //        backData.Parameter.maxYValue = (from p in tun select p).ToList().Max();
            //        backData.Parameter.maxYValue = (from p in tun select p).ToList().Min();
            //        spcData = backData;
            //    }
            //}
            //else
            //{
            //    if (!command.Command("MeasureSample ({NSS = " + scanCount + "," + "PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
            //        "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'})", true))
            //    {
            //        ErrorString = command.ErrorDesc;
            //        return null;
            //    }
            //    specPath = specPath.Replace(".spc", string.Empty);
            //    if (!unLoad.Unload(specPath))
            //    {
            //        ErrorString = unLoad.ErrorDesc;
            //        return null;
            //    }
            //    if (!spcData.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.SingleBeam))
            //    {
            //        ErrorString = spcData.ErrorString;
            //        return null;
            //    }
            //}
            //float[] tr = new float[spcData.YDatas.Count()];
            //for (int i = 0; i < spcData.YDatas.Count(); i++)
            //{
            //    tr[i] = (float)spcData.YDatas[i];
            //}
            //Ai.Hong.CommonLibrary.SPCFile.SaveFile(File, tr, spcData.Parameter);

            ////System.IO.File.Move(specPath, File);
            //if (System.IO.File.Exists(specPath) && !string.Equals(specPath, File))
            //{
            //    unLoad.Unload(specPath);
            //    System.IO.File.Delete(specPath);
            //}
            //return File;
            if (!LoadXPM(scanMethodFile) || !System.IO.Path.HasExtension(File))
            {
                return(null);
            }
            if (IsScanBack)
            {
                MoveWheel(0, scanMethodFile);
            }
            string specPath = File.Replace(".spc", ".0");

            if (System.IO.File.Exists(specPath))
            {
                OpusCMD334.UnloadFile unLoadFile = new OpusCMD334.UnloadFile();
                unLoadFile.Unload(specPath);
                System.IO.File.Delete(specPath);
            }
            if (System.IO.File.Exists(File))
            {
                System.IO.File.Delete(File);
            }

            OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            OpusCMD334.UnloadFile  unLoad  = new OpusCMD334.UnloadFile();

            Ai.Hong.CommonLibrary.SpecFileFormatDouble data = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (IsScanBack)
            {
                string commandString = "MeasureReference ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
                                       "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + " })";
                bool     retcode = command.Command(commandString, true);
                string[] retstrs = command.CommandResult.Split('\n');
                if (retcode == false || retstrs.Length < 1 || retstrs[0] != "OK")
                {
                    ErrorString = command.ErrorDesc;
                    return(null);
                }
                if (addPara != null)
                {
                    addPara = addPara.Replace("NSR", "NSS");
                }
                commandString = "MeasureSample ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
                                "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + "})";
                retcode = command.Command(commandString, true);
                retstrs = command.CommandResult.Split('\n');
                if (retcode == false || retstrs.Length < 4 || retstrs[0] != "OK")
                {
                    ErrorString = command.ErrorDesc;
                    return(null);
                }
                UnloadFileByCommand(retstrs[3]);
                //if (!unLoad.Unload(specPath))
                //{
                //    ErrorString = unLoad.ErrorDesc;
                //    return null;
                //}
                if (!data.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.Background))
                {
                    ErrorString = data.ErrorString;
                    return(null);
                }
            }
            else
            {
                string cmdstr = "MeasureSample ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
                                "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + "})";
                if (!command.Command(cmdstr, true))
                {
                    ErrorString = command.ErrorDesc;
                    return(null);
                }
                if (!unLoad.Unload(specPath))
                {
                    ErrorString = unLoad.ErrorDesc;
                    return(null);
                }
                if (!data.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.SingleBeam))
                {
                    ErrorString = data.ErrorString;
                    return(null);
                }
            }
            float[] tr = new float[data.YDatas.Count()];
            for (int i = 0; i < data.YDatas.Count(); i++)
            {
                tr[i] = (float)data.YDatas[i];
            }
            Ai.Hong.CommonLibrary.SPCFile.SaveFile(File, tr, data.Parameter);


            if (System.IO.File.Exists(specPath) && !string.Equals(specPath, File))
            {
                unLoad.Unload(specPath);
                System.IO.File.Delete(specPath);
            }
            return(File);
        }