Exemple #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);
        }
 /// <summary>
 /// 从OPUS卸载光谱文件
 /// </summary>
 /// <param name="path">光谱路径</param>
 /// <returns></returns>
 private bool UnLoadFile(string path)
 {
     lock (thisLock)
     {
         if (!System.IO.File.Exists(path))
         {
             ErrorString = "File " + path + "\r\n is not exist!";
             return(false);
         }
         OpusCMD334.UnloadFile unloadFile = new OpusCMD334.UnloadFile();
         if (!unloadFile.Unload(path))
         {
             ErrorString = unloadFile.ErrorDesc;
             return(false);
         }
         return(true);
     }
 }
Exemple #3
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);
        }
Exemple #4
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;
        }
Exemple #5
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);
        }