예제 #1
0
        public ChoiceWnd()
        {
            InitializeComponent();
            notelabel.ForeColor = this.ForeColor;
            this.BackColor      = Color.White;
            btn_quit.bgColor    = this.BackColor;
            btn_quit.SetStyle(Color.Beige, MyButtonType.round2Button);
            btn_quit.Text        = StringResource.str("quit");
            btn_quit.ValidClick += new EventHandler(btn_quit_ValidClick);
            bNo0Choice           = true;
            RectButton btn;

            foreach (int x in Enumerable.Range(1, MAX_NUMBER))
            {
                btn         = find_btn(x);
                btn.bgColor = this.BackColor;
                btn.SetStyle(btColor, MyButtonType.round2RectButton);

                btn.ValidClick += new EventHandler(btn_ValidClick);
            }
            TopMost = true;
            Hide();
        }
예제 #2
0
        static public void Action(string action, object param)
        {
            if (GlobalConfig.ISDEBUG)
            {
                success = true;
                return;
            }
            if (action == "navto1v" || action == "navto120mv")
            {
                if (nav_range == action)
                {
                    return;
                }
                nav_range = action;
                if (action == "navto1v")
                {
                    port.Write(StringResource.str("NAV_1V_" + GlobalConfig.sNavmeter)); //1v
                }
                if (action == "navto120mv")
                {
                    port.Write(StringResource.str("NAV_120MV_" + GlobalConfig.sNavmeter)); //120mv
                }
                if (action == "navto10mv")
                {
                    //     port.Write(StringResource.str("NAV_10MV_" + GlobalConfig.sNavmeter)); //10mv
                }
                if (action == "navto30v")
                {
                    //     port.Write(StringResource.str("NAV_30V_" + GlobalConfig.sNavmeter)); //10mv
                }
                Thread.Sleep(2000);
                return;
            }
            if (action == "navzero")
            {
                Thread.Sleep(1000);
                port.Write(StringResource.str("NAV_ZEROON_" + GlobalConfig.sNavmeter)); //120mv
                Thread.Sleep(1000);
                return;
            }
            if (action == "navread")
            {
                reading = -9999;
                port.DiscardInBuffer();
                port.Write(StringResource.str("NAV_READ_" + GlobalConfig.sNavmeter)); //1v
                Thread.Sleep(10);
                int timeout = 20;
                while ((timeout-- > 0) && (reading < -9000))
                {
                    Thread.Sleep(50);
                    ScanPort();
                }
                return;
            }
            if (action == "daoutput")
            {
                success = false;
                port.DiscardInBuffer();
                byte[] bts = (param as byte[]);
                port.Write(bts, 0, bts.Length);
                int timeout = 400;
                while ((timeout-- > 0) && (!success))
                {
                    ScanPort();
                    Thread.Sleep(5);
                }
            }
            if (action == "toggle1" || action == "toggle10" ||
                action == "poscurrent" || action == "negcurrent" || action == "defcurrent")
            {
                //55 73 55 55 02 56
                success = false;
                int retry = 3;
                while (retry-- > 0)
                {
                    port.DiscardInBuffer();
                    if (action == "toggle1")
                    {
                        portcmd[3] = (byte)(portcmd[3] | 0x01);
                    }
                    else
                    {
                        portcmd[3] = (byte)(portcmd[3] & 0xfe);
                    }


                    portcmd[3] = (byte)(portcmd[3] & 0xf5); //0101

                    if (action == "poscurrrent")            //1xxx
                    {
                        portcmd[3] = (byte)(portcmd[3] | 0xf8);
                    }
                    else if (action == "negcurrrent") //xx1x
                    {
                        portcmd[3] = (byte)(portcmd[3] | 0xf2);
                    }

                    port.Write(portcmd, 0, portcmd.Length);
                    int timeout = 400;
                    while ((timeout-- > 0) && (!success))
                    {
                        ScanPort();
                        Thread.Sleep(5);
                    }
                    if (success)
                    {
                        if (action == "toggle1")
                        {
                            xstate = 1;
                        }
                        else
                        {
                            xstate = 10;
                        }
                        break;
                    }
                    Thread.Sleep(500);
                }
                if (!success)
                {
                    Program.MsgShow("开关切换失败,请重启后再试");
                }
            }
            if (action == "togglex")
            {
                //55 73 55 55 02 56
                success = false;
                port.DiscardInBuffer();
                port.Write(togglecmd, 0, togglecmd.Length);
                int timeout = 400;
                while ((timeout-- > 0) && (!success))
                {
                    ScanPort();
                    Thread.Sleep(5);
                }
                if (success)
                {
                    if (xstate == 1)
                    {
                        xstate = 10;
                    }
                    else
                    {
                        xstate = 1;
                    }
                }
            }
        }
예제 #3
0
파일: kbdwnd.cs 프로젝트: ymz000/kpgweigher
        private void btn_ok_Click(object sender, EventArgs e)
        {
            string llimit = StringResource.str(param + "_llimit");
            string ulimit = StringResource.str(param + "_ulimit");

            scale = 1;
            if (btn_kscale.bOn)
            {
                scale = 0.000001M;
            }
            else if (btn_mscale.bOn)
            {
                scale = 0.001M;
            }
            else if (btn_gscale.bOn)
            {
                scale = 1;
            }
            if (data.ToString() == "")
            {
//              Program.MsgShow(StringResource.str("emptydata"));
                return;
            }
            try
            {
                if (llimit == "Invalid String Key") //no limits setting
                {
                    kbdhandler(param, data.ToString());
                }
                else
                {
                    if (llimit.IndexOf(".") < 0) //int case
                    {
                        Int32 ll = Int32.Parse(llimit);
                        Int32 hl = Int32.Parse(ulimit);

                        if (Int32.Parse(data.ToString()) < ll || Int32.Parse(data.ToString()) > hl)
                        {
                            throw new Exception(StringResource.str("out_of_range"));
                        }
                    }
                    else
                    {
                        double ll = double.Parse(llimit);
                        double hl = double.Parse(ulimit);
                        if (double.Parse(data.ToString()) < ll || double.Parse(data.ToString()) > hl)
                        {
                            throw new Exception(StringResource.str("out_of_range"));
                        }
                    }
                    kbdhandler(param, data.ToString());
                }
            }
            catch (Exception err)
            {
                Program.MsgShow(err.Message);
                return;
            }
            deep--;
            if (deep <= 0)
            {
                Hide();
                deep = 0;
            }
            else
            {
                Invalidate();
            }
        }
예제 #4
0
파일: kbdwnd.cs 프로젝트: ymz000/kpgweigher
        public kbdWnd()
        {
            InitializeComponent();

            RectButton[] btns = new RectButton[] { btn_backspace, btn_clr, btn_quit, btn_ok,
                                                   btn_num0, btn_num1, btn_num2, btn_num3, btn_num4,
                                                   btn_num5, btn_num6, btn_num7, btn_num8, btn_num9,
                                                   btn_numN, btn_numP };
            foreach (RectButton btn in btns)
            {
                btn.SetStyle(btColor, MyButtonType.roundRectButton);
                btn.BackColor = this.BackColor;
            }
            RectButton[] scalebtns = new RectButton[] { btn_kscale, btn_mscale, btn_gscale };
            foreach (RectButton btn in scalebtns)
            {
                btn.SetStyle(Color.Orange, MyButtonType.roundButton);
                btn.BackColor = this.BackColor;
            }

            btn_kscale.Text = "µ";
            btn_mscale.Text = "m";
            btn_gscale.Text = "G";

            btn_kscale.ValidClick += new EventHandler(btn_kscale_ValidClick);
            btn_mscale.ValidClick += new EventHandler(btn_kscale_ValidClick);
            btn_gscale.ValidClick += new EventHandler(btn_kscale_ValidClick);

            roundRect1.SetStyle(Color.Beige, MyButtonType.roundRect);

            btn_backspace.ValidClick += new EventHandler(btn_backspace_Click);
            btn_clr.ValidClick       += new EventHandler(btn_clr_Click);
            btn_quit.ValidClick      += new EventHandler(btn_quit_Click);
            btn_ok.ValidClick        += new EventHandler(btn_ok_Click);
            btn_num0.ValidClick      += new EventHandler(btn_num0_Click);
            btn_num1.ValidClick      += new EventHandler(btn_num1_Click);
            btn_num2.ValidClick      += new EventHandler(btn_num2_Click);
            btn_num3.ValidClick      += new EventHandler(btn_num3_Click);
            btn_num4.ValidClick      += new EventHandler(btn_num4_Click);
            btn_num5.ValidClick      += new EventHandler(btn_num5_Click);
            btn_num6.ValidClick      += new EventHandler(btn_num6_Click);
            btn_num7.ValidClick      += new EventHandler(btn_num7_Click);
            btn_num8.ValidClick      += new EventHandler(btn_num8_Click);
            btn_num9.ValidClick      += new EventHandler(btn_num9_Click);
            btn_numN.ValidClick      += new EventHandler(btn_numN_Click);
            btn_numP.ValidClick      += new EventHandler(btn_numP_Click);
            btn_backspace.Text        = StringResource.str("backspace");
            btn_clr.Text              = StringResource.str("clr");
            btn_quit.Text             = StringResource.str("quit");
            btn_ok.Text   = StringResource.str("ok");
            btn_num0.Text = "0";
            btn_num1.Text = "1";
            btn_num2.Text = "2";
            btn_num3.Text = "3";
            btn_num4.Text = "4";
            btn_num5.Text = "5";
            btn_num6.Text = "6";
            btn_num7.Text = "7";
            btn_num8.Text = "8";
            btn_num9.Text = "9";
            btn_numN.Text = "-";
            btn_numP.Text = ".";
            data          = new StringBuilder("", 10);
            note          = "Note";
            TopMost       = true;
            password      = false;
            Hide();
        }
예제 #5
0
 static public int xstate       = 1; //can be 1 or 10;
 static public void Action(string action, object param)
 {
     if (GlobalConfig.ISDEBUG)
     {
         success = true;
         return;
     }
     if (action == "navto1v" || action == "navto120mv")
     {
         if (nav_range == action)
         {
             return;
         }
         nav_range = action;
         if (action == "navto1v")
         {
             port.Write(StringResource.str("NAV_1V_" + GlobalConfig.sNavmeter)); //1v
         }
         if (action == "navto120mv")
         {
             port.Write(StringResource.str("NAV_120MV_" + GlobalConfig.sNavmeter)); //120mv
         }
         if (action == "navto10mv")
         {
             //     port.Write(StringResource.str("NAV_10MV_" + GlobalConfig.sNavmeter)); //10mv
         }
         if (action == "navto30v")
         {
             //     port.Write(StringResource.str("NAV_30V_" + GlobalConfig.sNavmeter)); //10mv
         }
         Thread.Sleep(2000);
         return;
     }
     if (action == "navzero")
     {
         Thread.Sleep(1000);
         port.Write(StringResource.str("NAV_ZEROON_" + GlobalConfig.sNavmeter)); //120mv
         Thread.Sleep(1000);
         return;
     }
     if (action == "navread")
     {
         reading = -9999;
         port.DiscardInBuffer();
         port.Write(StringResource.str("NAV_READ_" + GlobalConfig.sNavmeter)); //1v
         Thread.Sleep(10);
         int timeout = 20;
         while ((timeout-- > 0) && (reading < -9000))
         {
             Thread.Sleep(50);
             ScanPort();
         }
         return;
     }
     if (action == "daoutput")
     {
         success = false;
         port.DiscardInBuffer();
         byte[] bts = (param as byte[]);
         port.Write(bts, 0, bts.Length);
         int timeout = 400;
         while ((timeout-- > 0) && (!success))
         {
             ScanPort();
             Thread.Sleep(5);
         }
     }
     if (action == "togglex")
     {
         //55 73 55 55 02 56
         success = false;
         port.DiscardInBuffer();
         port.Write(togglecmd, 0, togglecmd.Length);
         int timeout = 400;
         while ((timeout-- > 0) && (!success))
         {
             ScanPort();
             Thread.Sleep(5);
         }
         if (success)
         {
             if (xstate == 1)
             {
                 xstate = 10;
             }
             else
             {
                 xstate = 1;
             }
         }
     }
 }