Ejemplo n.º 1
0
        public void KbdData(string param, string data)
        {
            try
            {
                if (param.StartsWith("scale"))
                {
                    param = param.Remove(0, "scale".Length);
                    if (ActionMgr.ConvertToRange(param) != ActionMgr.RNG_INVALID)
                    {
                        RunWnd.syscfg.SetScaleAdjust(ActionMgr.ConvertToRange(param), Convert.ToDouble(data));
                    }
                    return;
                }
                if (param == "5" || param == "10")
                {
                    RunWnd.syscfg.SetCurrent(5, (param.IndexOfAny("5".ToCharArray()) < 0), Convert.ToDouble(data));
                }
                if (param == "1" || param == "2")
                {
                    RunWnd.syscfg.SetCurrent(4, (param.IndexOfAny("1".ToCharArray()) < 0), Convert.ToDouble(data));
                }
                if (param == "0.3" || param == "0.6")
                {
                    RunWnd.syscfg.SetCurrent(3, (param.IndexOfAny("3".ToCharArray()) < 0), Convert.ToDouble(data));
                }
                if (param == "0.1" || param == "0.2")
                {
                    RunWnd.syscfg.SetCurrent(2, (param.IndexOfAny("1".ToCharArray()) < 0), Convert.ToDouble(data));
                }
                if (param == "0.01" || param == "0.02")
                {
                    RunWnd.syscfg.SetCurrent(1, (param.IndexOfAny("1".ToCharArray()) < 0), Convert.ToDouble(data));
                }
                if (param == "0.001" || param == "0.002")
                {
                    RunWnd.syscfg.SetCurrent(0, (param.IndexOfAny("1".ToCharArray()) < 0), Convert.ToDouble(data));
                }
                if (param == "0.0001" || param == "0.0002")
                {
                    RunWnd.syscfg.SetCurrent(-1, (param.IndexOfAny("1".ToCharArray()) < 0), Convert.ToDouble(data));
                }
                if (param == "exportdate")
                {
                    #region remove date log
                    if (Regex.IsMatch(data, "^820\\d\\d\\d\\d\\d\\d$"))
                    {
                        data = data.Remove(0, 1);
                        try
                        {
                            foreach (string dname in Directory.GetDirectories(StringResource.basedir, "20*"))
                            {
                                string[] todel = Directory.GetFiles(dname, "20*.txt");
                                foreach (string fname in todel)
                                {
                                    FileInfo fi = new FileInfo(fname);
                                    Match    m  = Regex.Match(fi.Name, @"(\d\d\d\d)_(\d\d)_(\d\d).*");
                                    if (m.Success)
                                    {
                                        if ((Convert.ToUInt16(data.Substring(0, 4)) <= Convert.ToUInt16(m.Groups[1].Value)) &&
                                            (Convert.ToUInt16(data.Substring(4, 2)) <= Convert.ToUInt16(m.Groups[2].Value)) &&
                                            (Convert.ToUInt16(data.Substring(6, 2)) <= Convert.ToUInt16(m.Groups[3].Value)))
                                        {
                                            //do nothing
                                        }
                                        else
                                        {
                                            File.Delete(fname);
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                        return;
                    }
                    #endregion

                    if (Regex.IsMatch(data, "^20\\d\\d\\d\\d\\d\\d$"))
                    {
                        export_start = data;
                        Program.kbd.Init(StringResource.str("enter_endexport"), "endexport", false, KbdData);
                    }
                    return;
                }
                if (param == "endexport")
                {
                    if (!Regex.IsMatch(data, "^20\\d\\d\\d\\d\\d\\d$"))
                    {
                        return;
                    }

                    try
                    {
                        foreach (string dname in Directory.GetDirectories(StringResource.basedir, "20*"))
                        {
                            foreach (string fname in Directory.GetFiles(dname, "20*.txt"))
                            {
                                FileInfo fi = new FileInfo(fname);
                                Match    m  = Regex.Match(fi.Name, @"(\d\d\d\d)_(\d\d)_(\d\d).*");
                                if (m.Success)
                                {
                                    if ((Convert.ToUInt16(data.Substring(0, 4)) >= Convert.ToUInt16(m.Groups[1].Value)) &&
                                        (Convert.ToUInt16(data.Substring(4, 2)) >= Convert.ToUInt16(m.Groups[2].Value)) &&
                                        (Convert.ToUInt16(data.Substring(6, 2)) >= Convert.ToUInt16(m.Groups[3].Value)) &&
                                        (Convert.ToUInt16(export_start.Substring(0, 4)) <= Convert.ToUInt16(m.Groups[1].Value)) &&
                                        (Convert.ToUInt16(export_start.Substring(4, 2)) <= Convert.ToUInt16(m.Groups[2].Value)) &&
                                        (Convert.ToUInt16(export_start.Substring(6, 2)) <= Convert.ToUInt16(m.Groups[3].Value)))
                                    {
                                        File.Copy(fname, StringResource.udiskdir + "\\" + fi.Name, true);
                                    }
                                }
                            }
                        }
                        Program.msg.Init(StringResource.str("export_done"));
                    }
                    catch
                    {
                        Program.msg.Init(StringResource.str("export_fail"));
                        return;
                    }
                }
                if (param == "newtime")
                {
                    if (!Regex.IsMatch(newdate, "^\\d\\d\\d\\d\\d\\d\\d\\d$"))
                    {
                        return;
                    }

                    if (!Regex.IsMatch(data, "^\\d\\d\\d\\d\\d\\d$"))
                    {
                        return;
                    }
                    SystemTime time = new SystemTime();
                    time.wYear        = Convert.ToUInt16(newdate.Substring(0, 4));
                    time.wMonth       = Convert.ToUInt16(newdate.Substring(4, 2));
                    time.wDay         = Convert.ToUInt16(newdate.Substring(6, 2));
                    time.wHour        = Convert.ToUInt16(data.Substring(0, 2));
                    time.wMinute      = Convert.ToUInt16(data.Substring(2, 2));
                    time.wSecond      = Convert.ToUInt16(data.Substring(4, 2));
                    time.wMiliseconds = 0;
                    SetLocalTime(ref time);
                }
                if (param == "newdate")
                {
                    if (data.StartsWith("8")) //input of scale offset
                    {
                        string sparam = data.Remove(0, 1);
                        if (ActionMgr.ConvertToRange(sparam) != ActionMgr.RNG_INVALID)
                        {
                            this.Invoke(new Action <string>(enterscale), new string[] { sparam });
                        }
                        return;
                    }
                    if (data == "00000") //do upgrade
                    {
                        Program.Upgrade();
                        return;
                    }
                    if (data == "99999") //current calibration
                    {
                        string sparam = data.Remove(0, 1);
                        RxInfo myrx   = Program.lst_rxinfo[Program.mainwnd.selectedRx];
                        myrx.var.rRs = Program.lst_rsinfo[0].dTValue;
                        if (myrx.iRRange == ActionMgr.RNG_P001)
                        {
                            myrx.var.iK = 1; //1000:1
                        }
                        else if (myrx.iRRange == ActionMgr.RNG_P01)
                        {
                            myrx.var.iK = 10; //100:1
                        }
                        else if (myrx.iRRange == ActionMgr.RNG_P1)
                        {
                            myrx.var.iK = 100; //10:1
                        }
                        else
                        {
                            myrx.var.iK = (int)Math.Floor(1000.0 / (myrx.var.rRs * RunWnd.syscfg.GetStdCurrent(myrx.iIx, myrx.bSqrt)));
                        }

                        if (myrx.var.iK > 1020)
                        {
                            Program.msg.Init("标准电阻阻值过小,无法校准。标准电阻上电压应不小于1V");
                            return;
                        }
                        Program.msg.Init(String.Format(@"电流校准完成,电流值为{0}", Util.FormatData(Program.mainwnd.task.act_mgr.CalibrateCurr(myrx), 8)));
                        return;
                    }
                    if (data == "1" || data == "2" ||
                        data == "5" || data == "10" ||
                        data == "0.3" || data == "0.6" ||
                        data == "0.1" || data == "0.2" ||
                        data == "0.01" || data == "0.02" ||
                        data == "0.001" || data == "0.002" ||
                        data == "0.0001" || data == "0.0002")
                    {
                        this.Invoke(new Action <string>(entercurrent), new string[] { data });
                        return;
                    }
                    if (data == "65890192")
                    {
                        Process.GetCurrentProcess().Kill(); //back door to exit the current program
                        return;
                    }
                    if (data == "658901920")
                    {
                        Program.OpenLog(0);
                        return;
                    }

                    if (data == "12345678")
                    {
                        Process app = new Process();
                        app.StartInfo.WorkingDirectory = @"\Windows";
                        app.StartInfo.FileName         = @"\Windows\TouchKit.exe";
                        app.StartInfo.Arguments        = "";
                        app.Start();
                        btn_quit_ValidClick(null, null);
                        return;
                    }
                    newdate = data;
                    this.Invoke(new Action(EnterNewTime));
                    return;
                }

                if (param == "ktt")
                {
                    RunWnd.syscfg.iKTT = Convert.ToInt32(data);
                }
                if (param == "measdelay")
                {
                    RunWnd.syscfg.iMeasDelay = Convert.ToInt32(data);
                }
                if (param == "sampletimes")
                {
                    RunWnd.syscfg.iSampleTimes = Convert.ToInt32(data);
                }
                if (param == "meastimes")
                {
                    RunWnd.syscfg.iMeasTimes = Convert.ToInt32(data);
                }
                if (param == "fltlength")
                {
                    RunWnd.syscfg.iFilter = Convert.ToInt32(data);
                }
                InitDisplay();
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
 public void enterscale(string type)
 {
     Program.kbd.Init(StringResource.str("enter_" + type + "B") + "," + RunWnd.syscfg.GetScaleAdjust(ActionMgr.ConvertToRange(type)).ToString("F3"), "scale" + type, false, KbdData);
 }