示例#1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            /*ScriptSet dualScript = new ScriptSet();
             *
             * XmlSerializer serializer = new XmlSerializer(typeof(ScriptSet), "");
             * TextWriter textWriter = new StreamWriter(@Directory.GetCurrentDirectory() + @"\xml\BottomScript.xml");
             * using (TextWriter tw = new Utf8StringWriter())
             * {
             *  serializer.Serialize(textWriter, dualScript);
             * }
             * textWriter.Close();*/

            GlobalFunc.logManager.CreateLogFile();
            GlobalFunc.logManager.CreateUserLogFile();
            GlobalFunc.assembly = Assembly.Load("LCMS");

            if (!Directory.Exists(@"C:\LCMS\defaultSetting"))
            {
                Directory.CreateDirectory(@"C:\LCMS\defaultSetting");
            }

            try
            {
                XmlSerializer deserializer1 = new XmlSerializer(typeof(BasicSetting));
                TextReader    textReader    = new StreamReader(@Directory.GetCurrentDirectory() + @"\xml\Basic.xml");
                GlobalFunc.basicSetting = (BasicSetting)deserializer1.Deserialize(textReader);
                textReader.Close();

                if (GlobalFunc.basicSetting.GetTemp.ToLower() == "on")
                {
                    GlobalFunc.getTemp = true;
                }
                else if (GlobalFunc.basicSetting.GetTemp.ToLower() == "off")
                {
                    GlobalFunc.getTemp = false;
                }

                GlobalFunc.intIOAddress = Convert.ToInt32(GlobalFunc.basicSetting.IoAddress, 16);

                XmlSerializer deserializer2 = new XmlSerializer(typeof(ScriptSet));
                TextReader    textReader2   = new StreamReader(@Directory.GetCurrentDirectory() + @"\xml\DualScript.xml");
                GlobalFunc.dualScriptSet = (ScriptSet)deserializer2.Deserialize(textReader2);
                textReader2.Close();

                XmlSerializer deserializer3 = new XmlSerializer(typeof(ScriptSet));
                TextReader    textReader3   = new StreamReader(@Directory.GetCurrentDirectory() + @"\xml\TopScript.xml");
                GlobalFunc.topScriptSet = (ScriptSet)deserializer3.Deserialize(textReader3);
                textReader3.Close();

                XmlSerializer deserializer4 = new XmlSerializer(typeof(ScriptSet));
                TextReader    textReader4   = new StreamReader(@Directory.GetCurrentDirectory() + @"\xml\BottomScript.xml");
                GlobalFunc.bottomScriptSet = (ScriptSet)deserializer4.Deserialize(textReader4);
                textReader4.Close();

                GlobalFunc.LoadIsotopXML();

                #region check inpot32.dll is existed
                if (!File.Exists(@"C:\Windows\System32\inpout32.dll"))
                {
                    if (File.Exists(@Directory.GetCurrentDirectory() + @"\inpout32.dll"))
                    {
                        MessageBox.Show(@"Please copy inpout32.dll from C:\LCMS to C:\Windows\System32");
                    }
                    else
                    {
                        MessageBox.Show("Can't find inpout32.dll in program directory");
                    }
                }
                #endregion

                if (GlobalFunc.basicSetting.InsalledIO.ToLower() == "true")
                {
                    try
                    {
                        //reset to only led #1 on
                        PortAccess.Output(GlobalFunc.intIOAddress, 0);
                    }
                    catch
                    {
                        MessageBox.Show("IO Addresws not found");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (GlobalFunc.basicSetting.Lang == "Zn")
            {
                GlobalFunc.rm = new ResourceManager("LCMS.Lang.LangZn", GlobalFunc.assembly);
            }
            else
            {
                GlobalFunc.rm = new ResourceManager("LCMS.Lang.LangEn", GlobalFunc.assembly);
            }
            //string text = (1.3 * Math.Pow(10, 9) * 365).ToString();

            BKManager.SetLiveTime();
            GlobalFunc.SetMeasureSetting();
            GlobalFunc.tc = new TestConnection();

            Application.Run(new SplashScreen());

            //Application.Run(GlobalFunc.tc);
            //Application.Run(new SettingForm());
            //Application.Run(new OutputWord());
            //Application.Run(new MainForm());
            //Application.Run(new LoginForm());
        }
示例#2
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            GlobalFunc.logManager.WriteLog("Open LCMS");
            int countTime = 0;

            #region loading basic.xml
            try
            {
                XmlSerializer deserializer1 = new XmlSerializer(typeof(BasicSetting));
                TextReader    textReader    = new StreamReader(@Directory.GetCurrentDirectory() + @"\xml\Basic.xml");
                GlobalFunc.basicSetting = (BasicSetting)deserializer1.Deserialize(textReader);
                textReader.Close();
                if (GlobalFunc.basicSetting.Lang == "Zn")
                {
                    GlobalFunc.rm = new ResourceManager("LCMS.Lang.LangZn", GlobalFunc.assembly);
                }
                else
                {
                    GlobalFunc.rm = new ResourceManager("LCMS.Lang.LangEn", GlobalFunc.assembly);
                }

                noticeLabel.Invoke(new MethodInvoker(delegate { noticeLabel.Text = GlobalFunc.rm.GetString("loadBasicXML"); }));

                countTime += 50;
                if (GlobalFunc.basicSetting.GetTemp.ToLower() == "on")
                {
                    GlobalFunc.getTemp = true;
                }
                else if (GlobalFunc.basicSetting.GetTemp.ToLower() == "off")
                {
                    GlobalFunc.getTemp = false;
                }
                countTime += 50;


                XmlSerializer deserializer2 = new XmlSerializer(typeof(ScriptSet));
                TextReader    textReader2   = new StreamReader(@Directory.GetCurrentDirectory() + @"\xml\DualScript.xml");
                GlobalFunc.dualScriptSet = (ScriptSet)deserializer2.Deserialize(textReader2);
                textReader2.Close();
                countTime += 50;

                XmlSerializer deserializer3 = new XmlSerializer(typeof(ScriptSet));
                TextReader    textReader3   = new StreamReader(@Directory.GetCurrentDirectory() + @"\xml\TopScript.xml");
                GlobalFunc.topScriptSet = (ScriptSet)deserializer3.Deserialize(textReader3);
                textReader3.Close();
                countTime += 50;

                XmlSerializer deserializer4 = new XmlSerializer(typeof(ScriptSet));
                TextReader    textReader4   = new StreamReader(@Directory.GetCurrentDirectory() + @"\xml\BottomScript.xml");
                GlobalFunc.bottomScriptSet = (ScriptSet)deserializer4.Deserialize(textReader4);
                textReader4.Close();
                countTime += 50;

                GlobalFunc.LoadRoiElement();
                GlobalFunc.LoadIsotopXML();

                if (GlobalFunc.basicSetting.InsalledIO.ToLower() == "true")
                {
                    GlobalFunc.intIOAddress = Convert.ToInt32(GlobalFunc.basicSetting.IoAddress, 16);
                    try
                    {
                        //reset to only led #1 on
                        PortAccess.Output(GlobalFunc.intIOAddress, 0);
                    }
                    catch
                    {
                        MessageBox.Show("IO Address not found");
                    }

                    #region check inpot32.dll is existed
                    noticeLabel.Invoke(new MethodInvoker(delegate { noticeLabel.Text = GlobalFunc.rm.GetString("checkIO"); }));
                    if (!File.Exists(@"C:\Windows\System32\inpout32.dll"))
                    {
                        if (File.Exists(@Directory.GetCurrentDirectory() + @"\inpout32.dll"))
                        {
                            noticeLabel.Invoke(new MethodInvoker(delegate
                            {
                                MessageBox.Show(@"Please copy inpout32.dll from C:\LCMS to C:\Windows\System32");
                            }));
                        }
                        else
                        {
                            noticeLabel.Invoke(new MethodInvoker(delegate
                            {
                                MessageBox.Show("Can't find inpout32.dll in program directory");
                            }));
                        }
                    }
                    countTime += 50;
                    Thread.Sleep(1000);
                    #endregion
                }
                countTime += 50;
                Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            #endregion

            #region check exe path is correct
            //no more use mca32
            //backgroundWorker.ReportProgress(30);
            //if (!File.Exists(GlobalFunc.basicSetting.ExePath))
            //{
            //    for (int k = 0; k < 10; k++)
            //    {
            //        noticeLabel.Invoke(new MethodInvoker(delegate { noticeLabel.Text = GlobalFunc.rm.GetString("exeNotFound"); }));
            //        Thread.Sleep(1000);
            //    }
            //}
            //Thread.Sleep(3000); //wait 5 second to start connect
            #endregion

            if (GlobalFunc.basicSetting.PresetDetector.ToLower() == "top" || GlobalFunc.basicSetting.PresetDetector.ToLower() == "dual")
            {
                #region Detector 1
                noticeLabel.Invoke(new MethodInvoker(delegate { noticeLabel.Text = GlobalFunc.rm.GetString("connectDetector1"); }));
                backgroundWorker.ReportProgress(50);
                countTime += 50;
                noticeLabel.Invoke(new MethodInvoker(delegate
                {
                    GlobalFunc.tc.checkDetector1Connection();
                }));
                if (!GlobalFunc.connectedToDetector1)
                {
                    detectorLabel1.Invoke(new MethodInvoker(delegate { detectorLabel1.Text = GlobalFunc.rm.GetString("failConnectDetector1"); }));
                }
                else
                {
                    detectorLabel1.Invoke(new MethodInvoker(delegate
                    {
                        detectorLabel1.Text = GlobalFunc.rm.GetString("successDetector1");
                        GlobalFunc.tc.GetDetector1ICR();
                    }));
                    detectorLabel1.ForeColor = Color.Blue;
                }
                #endregion
                Thread.Sleep(3000);
            }

            if (GlobalFunc.basicSetting.PresetDetector.ToLower() == "bottom" || GlobalFunc.basicSetting.PresetDetector.ToLower() == "dual")
            {
                #region Detector 2
                noticeLabel.Invoke(new MethodInvoker(delegate { noticeLabel.Text = GlobalFunc.rm.GetString("connectDetector2"); }));
                backgroundWorker.ReportProgress(50);
                countTime += 50;
                noticeLabel.Invoke(new MethodInvoker(delegate
                {
                    GlobalFunc.tc.checkDetector2Connection();
                }));
                if (!GlobalFunc.connectedToDetector2)
                {
                    detectorLabel2.Invoke(new MethodInvoker(delegate { detectorLabel2.Text += GlobalFunc.rm.GetString("failConnectDetector2"); }));
                }
                else
                {
                    detectorLabel2.Invoke(new MethodInvoker(delegate
                    {
                        detectorLabel2.Text += GlobalFunc.rm.GetString("successDetector2");
                        GlobalFunc.tc.GetDetector2ICR();
                    }));
                    detectorLabel2.ForeColor = Color.Blue;
                }
                #endregion
            }

            for (int i = 0; i < 1000 - countTime; i++)
            {
                Thread.Sleep(10);
                backgroundWorker.ReportProgress(i);
            }
        }
示例#3
0
        public static Profile LoadProfile(string fileName)
        {
            try
            {
                Profile loadProfile = new Profile();
                string  line;
                string  path = @"C:\LCMS\Profile\" + fileName;
                using (StreamReader reader = File.OpenText(path))
                {
                    bool   matrixTopOn    = false;
                    bool   matrixBottomOn = false;
                    bool   matrixDual     = false;
                    IsoSeq ise            = new IsoSeq();
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Contains("Profile Name:"))
                        {
                            loadProfile.ProfileName = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("Detector:"))
                        {
                            loadProfile.Detector = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("Location:"))
                        {
                            loadProfile.Location = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("Alarm Type:"))
                        {
                            loadProfile.Alarm = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("No. of Region:"))
                        {
                            loadProfile.NoOfRegion = Convert.ToInt32(line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1)));
                        }
                        else if (line.Contains("Date:"))
                        {
                            loadProfile.Date = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("Roi Path1:"))
                        {
                            loadProfile.RoiPath1 = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("Roi Path2:"))
                        {
                            loadProfile.RoiPath2 = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("Live Time:"))
                        {
                            loadProfile.LiveTime = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("Background Top CPS:"))
                        {
                            string inner = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                            if (inner != "")
                            {
                                loadProfile.BkTopCPS = inner.Split(',').ToList();
                            }
                        }
                        else if (line.Contains("Background Bottom CPS:"))
                        {
                            string inner = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                            if (inner != "")
                            {
                                loadProfile.BKBottomCPS = inner.Split(',').ToList();
                            }
                        }
                        else if (line.Contains("Quantity of Isotope:"))
                        {
                            loadProfile.Qty = Convert.ToInt32(line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1)));
                        }
                        else if (line.Contains("Roi#"))
                        {
                            ise        = new IsoSeq();
                            ise.Number = Convert.ToInt32(line.Substring(line.IndexOf("#") + 1, 1));
                            ise.Name   = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("Activity:"))
                        {
                            ise.Activity = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                            ise.Activity = (Convert.ToDouble(ise.Activity) / 1000).ToString();
                        }
                        else if (line.Contains("Ref Datetime:"))
                        {
                            ise.RefDateTime = DateTime.Parse(line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1)));
                        }
                        else if (line.Contains("Measure Time:"))
                        {
                            ise.MeasureTime = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("DIL"))
                        {
                            ise.DIL = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("AL") && !line.Contains("%"))
                        {
                            ise.AL = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("AL%"))
                        {
                            ise.AL_PC = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("Top CPS:") && !line.Contains("Bakcground"))
                        {
                            ise.TopCPS = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                        }
                        else if (line.Contains("Bottom CPS:") && !line.Contains("Background"))
                        {
                            ise.BottomCPS = line.Substring(line.IndexOf(":") + 1, line.Length - (line.IndexOf(":") + 1));
                            loadProfile.IsoSeqList.Add(ise);
                        }
                        else if (line.Contains("Matrix Top:"))
                        {
                            matrixTopOn    = true;
                            matrixBottomOn = false;
                            matrixDual     = false;
                        }
                        else if (matrixTopOn)
                        {
                            if (!line.Contains("Matrix Top:") && line != "" && !line.Contains("Matrix Bottom:") && !line.Contains("Matrix Dual:"))
                            {
                                string[] mTop = line.Split(',');
                                for (int i = 0; i < mTop.Length; i++)
                                {
                                    if (mTop[i] != "")
                                    {
                                        loadProfile.MatrixTop.Add(Convert.ToSingle(mTop[i]));
                                    }
                                }
                            }
                            else if (line.Contains("Matrix Bottom:"))
                            {
                                matrixTopOn    = false;
                                matrixBottomOn = true;
                                matrixDual     = false;
                            }
                        }
                        else if (line.Contains("Matrix Bottom:"))
                        {
                            matrixTopOn    = false;
                            matrixBottomOn = true;
                            matrixDual     = false;
                        }
                        else if (matrixBottomOn)
                        {
                            if (!line.Contains("Matrix Bottom:") && line != "" && !line.Contains("Matrix Top:") && !line.Contains("Matrix Dual:"))
                            {
                                string[] mBottom = line.Split(',');
                                for (int i = 0; i < mBottom.Length; i++)
                                {
                                    if (mBottom[i] != "")
                                    {
                                        loadProfile.MatrixBottom.Add(Convert.ToSingle(mBottom[i]));
                                    }
                                }
                            }
                            else if (line.Contains("Matrix Dual:"))
                            {
                                matrixTopOn    = false;
                                matrixBottomOn = false;
                                matrixDual     = true;
                            }
                        }
                        else if (line.Contains("Matrix Dual:"))
                        {
                            matrixTopOn    = false;
                            matrixBottomOn = false;
                            matrixDual     = true;
                        }
                        else if (matrixDual)
                        {
                            if (!line.Contains("Matrix Dual:") && line != "" && !line.Contains("Matrix Top:") && !line.Contains("Matrix Bottom:"))
                            {
                                string[] mDual = line.Split(',');
                                for (int i = 0; i < mDual.Length; i++)
                                {
                                    if (mDual[i] != "")
                                    {
                                        loadProfile.MatrixDual.Add(Convert.ToSingle(mDual[i]));
                                    }
                                }
                            }
                        }
                    }
                }

                GlobalFunc.LoadIsotopXML();
                for (int i = 0; i < loadProfile.IsoSeqList.Count; i++)
                {
                    loadProfile.Activity.Add(Convert.ToDouble(loadProfile.IsoSeqList[i].Activity));
                    loadProfile.Ref_Date.Add(loadProfile.IsoSeqList[i].RefDateTime);
                    if (loadProfile.Alarm == "DIL")
                    {
                        loadProfile.AlarmLevel.Add(Convert.ToDouble(loadProfile.IsoSeqList[i].DIL));
                        loadProfile.AlarmPCLevel.Add(Convert.ToDouble(loadProfile.IsoSeqList[i].AL_PC));
                    }
                    else if (loadProfile.Alarm == "AL")
                    {
                        loadProfile.AlarmLevel.Add(Convert.ToDouble(loadProfile.IsoSeqList[i].AL));
                        loadProfile.AlarmPCLevel.Add(Convert.ToDouble(loadProfile.IsoSeqList[i].AL_PC));
                    }
                    loadProfile.AlarmPCLevel.Add(Convert.ToDouble(loadProfile.IsoSeqList[i].AL_PC));
                    for (int j = 0; j < GlobalFunc.isotopeList1.Count; j++)
                    {
                        if (loadProfile.IsoSeqList[i].Name == GlobalFunc.isotopeList1[j].Code)
                        {
                            loadProfile.HalfTime.Add(Convert.ToDouble(GlobalFunc.isotopeList1[j].HalfLife));
                            loadProfile.RatioPeak.Add(Convert.ToDouble(GlobalFunc.isotopeList1[j].Bop));

                            break;
                        }
                    }
                }

                if (loadProfile.Detector == "Dual")
                {
                    for (int i = 0; i < loadProfile.BkTopCPS.Count; i++)
                    {
                        double value = Convert.ToDouble(loadProfile.BkTopCPS[i]) + Convert.ToDouble(loadProfile.BKBottomCPS[i]);
                        //string strValue = Math.Round(value, 2).ToString();
                        loadProfile.FinalBkCPS.Add(value);
                    }
                    loadProfile.FinalMatrix = loadProfile.MatrixDual;
                }
                else if (loadProfile.Detector == "Top")
                {
                    for (int i = 0; i < loadProfile.BkTopCPS.Count; i++)
                    {
                        loadProfile.FinalBkCPS.Add(Convert.ToDouble(loadProfile.BkTopCPS[i]));
                    }
                    loadProfile.FinalMatrix = loadProfile.MatrixTop;
                }
                else if (loadProfile.Detector == "Bottom")
                {
                    for (int i = 0; i < loadProfile.BKBottomCPS.Count; i++)
                    {
                        loadProfile.FinalBkCPS.Add(Convert.ToDouble(loadProfile.BKBottomCPS[i]));
                    }
                    loadProfile.FinalMatrix = loadProfile.MatrixBottom;
                }
                loadProfile.FinalBkCPS.RemoveAt(loadProfile.FinalBkCPS.Count - 1);
                return(loadProfile);
            }
            catch (Exception ex)
            {
                GlobalFunc.logManager.WriteLog("load profile error:" + ex.Message);
                return(null);
            }
        }