Exemplo n.º 1
0
 public void KbdData(string param, string data)
 {
     try
     {
         if (param == "chan")
         {
             selectedRx = Convert.ToInt32(data) - 1;
         }
         if (param == "stdchan")
         {
             Program.lst_rxinfo[selectedRx].iStdChan = Convert.ToInt32(data);
         }
         if (param == "current")
         {
             double ix = Convert.ToDouble(data);
             Program.lst_rxinfo[selectedRx].iIx = -1; //0.1mA
             if (ix > 0.0005)
             {
                 Program.lst_rxinfo[selectedRx].iIx = 0; //1mA
             }
             if (ix > 0.005)
             {
                 Program.lst_rxinfo[selectedRx].iIx = 1; //10mA
             }
             if (ix > 0.05)
             {
                 Program.lst_rxinfo[selectedRx].iIx = 2; //0.1A
             }
             if (ix > 0.2)
             {
                 Program.lst_rxinfo[selectedRx].iIx = 3; //0.3A
             }
             if (ix > 0.7)
             {
                 Program.lst_rxinfo[selectedRx].iIx = 4; //1A
             }
             if (ix > 3)
             {
                 Program.lst_rxinfo[selectedRx].iIx = 5; //5A
             }
         }
         if (param == "serial")
         {
             Program.lst_rxinfo[selectedRx].sSerial = data;
         }
         if (param == "vname")
         {
             double rname = Math.Abs(Convert.ToDouble(data));
             Program.lst_rxinfo[selectedRx].dRxInput = rname;
             ActionMgr.SetIxRange(selectedRx, rname);
         }
         InitDisplay(selectedRx);
     }
     catch
     {
     }
 }
Exemplo n.º 2
0
 public TaskMachine()
 {
     act_mgr  = new ActionMgr();
     data_mgr = new DataMgr();
 }
Exemplo n.º 3
0
 public TaskMachine()
 {
     act_mgr = new ActionMgr();
     data_mgr = new DataMgr();
 }
Exemplo n.º 4
0
        public void pc_cmd(string cmd)
        {
            DeviceMgr.SysLog(cmd);
            if (cmd == "ECHO")
            {
                DeviceMgr.Resend();
                return;
            }
            if (cmd == "S")
            {
                if (task.bRunning)
                {
                    statusBar1_StartStopClick(null, null); //click stop
                }
                return;
            }

            if (cmd == "H")
            {
                if ((!task.bRunning) && (!DeviceMgr.IsInAction()))
                {
                    DeviceMgr.Reset();//reset
                }
                return;
            }
            Match m;

            m = reg_mode.Match(cmd);
            if (m.Success)
            {
                oper_mode = m.Groups[1].Value;
                return;
            }
            m = reg_statistic.Match(cmd);
            if (m.Success)
            {
                syscfg.iFilter = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_filter.Match(cmd);
            if (m.Success)
            {
                if (m.Groups[1].Value == "2")
                {
                    syscfg.sFilterType = "filtertype3";
                }
                else if (m.Groups[1].Value == "1")
                {
                    syscfg.sFilterType = "filtertype2";
                }
                else if (m.Groups[1].Value == "3")
                {
                    syscfg.sFilterType = "filtertype4";
                }
                else
                {
                    syscfg.sFilterType = "filtertype1";
                }
                return;
            }
            m = reg_ix.Match(cmd);
            if (m.Success)
            {
                #region current convert
                double myIx = double.Parse(m.Groups[1].Value) / 1000;
                if (myIx >= 5.5)
                {
                    Program.lst_rxinfo[0].iIx   = 5; //5A x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 2.2)
                {
                    Program.lst_rxinfo[0].iIx   = 5; //5A
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                if (myIx >= 1.1)
                {
                    Program.lst_rxinfo[0].iIx   = 4; //1A x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 0.66)
                {
                    Program.lst_rxinfo[0].iIx   = 4; //1A x 2
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                if (myIx >= 0.33)
                {
                    Program.lst_rxinfo[0].iIx   = 3; //0.3A x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 0.22)
                {
                    Program.lst_rxinfo[0].iIx   = 3; //0.3A
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                if (myIx >= 0.11)
                {
                    Program.lst_rxinfo[0].iIx   = 2; //0.1A x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 0.022)
                {
                    Program.lst_rxinfo[0].iIx   = 2; //0.1A
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                if (myIx >= 0.011)
                {
                    Program.lst_rxinfo[0].iIx   = 1; //10mA x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 0.0022)
                {
                    Program.lst_rxinfo[0].iIx   = 1; //10mA
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }

                if (myIx >= 0.0011)
                {
                    Program.lst_rxinfo[0].iIx   = 0; //1mA x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                if (myIx >= 0.00022)
                {
                    Program.lst_rxinfo[0].iIx   = 0; //1mA
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                if (myIx >= 0.00011)
                {
                    Program.lst_rxinfo[0].iIx   = -1; //0.1mA x 2
                    Program.lst_rxinfo[0].bSqrt = true;
                    return;
                }
                {
                    Program.lst_rxinfo[0].iIx   = -1; //0.1mA
                    Program.lst_rxinfo[0].bSqrt = false;
                    return;
                }
                #endregion
            }
            m = reg_delay.Match(cmd);
            if (m.Success)
            {
                syscfg.iMeasDelay = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_meastimes.Match(cmd);
            if (m.Success)
            {
                syscfg.iMeasTimes = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_switch.Match(cmd);
            if (m.Success)
            {
                syscfg.iKTT = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_measure.Match(cmd);
            if (m.Success)
            {
                syscfg.iMeasTimes = Convert.ToInt32(m.Groups[1].Value);
                RsInfo rs = Program.lst_rsinfo[Program.mainwnd.selectedRs];
                RxInfo rx = Program.lst_rxinfo[Program.mainwnd.selectedRx];
                if (!task.bRunning)
                {
                    statusBar1_StartStopClick(null, null); //click start
                }
                return;
            }
            m = reg_sampletimes.Match(cmd);
            if (m.Success)
            {
                syscfg.iSampleTimes = Convert.ToInt32(m.Groups[1].Value);
                return;
            }
            m = reg_alpha.Match(cmd);
            if (m.Success)
            {
                Program.lst_rsinfo[0].iRRange = ActionMgr.RNG_INVALID;
                Program.lst_rsinfo[0].dAlpha  = Convert.ToDouble(m.Groups[1].Value);
                return;
            }
            m = reg_beta.Match(cmd);
            if (m.Success)
            {
                Program.lst_rsinfo[0].iRRange = ActionMgr.RNG_INVALID;
                Program.lst_rsinfo[0].dBeta   = Convert.ToDouble(m.Groups[1].Value);

                return;
            }
            m = reg_temp.Match(cmd);
            if (m.Success)
            {
                syscfg.dTemp = Convert.ToDouble(m.Groups[1].Value);
                return;
            }
            m = reg_rsa.Match(cmd);
            if (m.Success)
            {
                Program.lst_rsinfo[0].iRRange  = ActionMgr.RNG_INVALID;
                Program.lst_rsinfo[0].dValue   = Convert.ToDouble(m.Groups[1].Value);
                Program.lst_rxinfo[0].cStdChan = 'A';
                return;
            }
            m = reg_rsid.Match(cmd);
            if (m.Success)
            {
                Program.lst_rsinfo[0].iRRange = ActionMgr.RNG_INVALID;
                Program.lst_rsinfo[0].sSerial = m.Groups[1].Value;
                return;
            }
            m = reg_rxid.Match(cmd);
            if (m.Success)
            {
                Program.lst_rxinfo[0].sSerial = m.Groups[1].Value;
                return;
            }

            m = reg_rsb.Match(cmd);
            if (m.Success)
            {
                Program.lst_rxinfo[0].dRxInput = Convert.ToDouble(m.Groups[1].Value);
                ActionMgr.SetIxRange(0, Program.lst_rxinfo[0].dRxInput, false);
                Program.lst_rxinfo[0].cStdChan = 'B';
                return;
            }
        }
Exemplo n.º 5
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
            {
            }
        }
Exemplo n.º 6
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);
 }