Exemplo n.º 1
0
        private void Btn_portOpen_Click(object sender, EventArgs e)
        {
            if (!isOpen)
            {
                try
                {
                    String  comName       = PortcomboBox.SelectedItem.ToString();
                    Boolean isOpenSuccess = usb.SetCom(PortcomboBox.SelectedItem.ToString());

                    //Timer tick
                    //System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
                    //myTimer.Tick += new EventHandler(timer1_Tick);
                    //myTimer.Enabled = true;
                    //myTimer.Interval = 10000;
                    //myTimer.Start();

                    //serial graph
                    //graph_serial();

                    if (isOpenSuccess)
                    {
                        isOpen            = true;
                        btn_portOpen.Text = "Close";

                        lbl_status.Text = "The device is active";
                        //btn_start_sample.Enabled = true;
                        ToggleControls(false);

                        sendCount = 1;
                    }
                    else
                    {
                        isOpen            = false;
                        btn_portOpen.Text = "Open";
                        lbl_status.Text   = "Could not read any response";
                        ToggleControls(true);
                        btn_stop_sample.Enabled = false;
                        //  myTimer.Stop();
                    }
                }
                catch
                {
                    lbl_status.Text = "Check COM connection";
                }
            }
            else
            {
                stop_sample();   //stop sample
                usb.CloseCom();
                btn_portOpen.Text = "Open";
                isOpen            = false;

                ToggleControls(true);
                btn_stop_sample.Enabled = false;
            }
        }
Exemplo n.º 2
0
        private void PortOpen_Click(object sender, EventArgs e)
        {
            if (!isOpen)
            {
                lblStatus.Text = "The device is active";

                //SendCommand.Enabled = true;  //button sendcommand enable
                //btn_switchGEPON.Enabled = true;
                //btn_Power.Enabled = true;

                PortOpen.Text = "Close";
                String  comName       = PortcomboBox.SelectedItem.ToString();
                Boolean isOpenSuccess = usb.SetCom(PortcomboBox.SelectedItem.ToString());

                //Timer tick
                System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
                myTimer.Tick    += new EventHandler(timer1_Tick);
                myTimer.Enabled  = true;
                myTimer.Interval = 10000;
                myTimer.Start();

                //serial graph
                //graph_serial();


                if (isOpenSuccess)
                {
                    isOpen = true;
                }
                else
                {
                    isOpen         = false;
                    PortOpen.Text  = "Open";
                    lblStatus.Text = "Could not read any response";
                    myTimer.Stop();
                }
            }
            else
            {
                usb.CloseCom();
                PortOpen.Text = "Open";
                isOpen        = false;
            }
        }
Exemplo n.º 3
0
        private void PortOpen_Click(object sender, EventArgs e)
        {
            if (!isOpen)
            {
                try
                {
                    ShowStatusBar("The device is active", true);

                    SendCommand.Enabled     = true; //button sendcommand enable
                    btn_switchGEPON.Enabled = true;
                    btn_Power.Enabled       = true;


                    String  comName       = PortcomboBox.SelectedItem.ToString();
                    Boolean isOpenSuccess = usb.SetCom(PortcomboBox.SelectedItem.ToString());
                    if (isOpenSuccess)
                    {
                        isOpen        = true;
                        PortOpen.Text = "Close";
                    }
                    else
                    {
                        isOpen        = false;
                        PortOpen.Text = "Open";
                        ShowStatusBar("Could not read any response", false);
                    }
                }
                catch { ShowStatusBar("Check COM connection", true); }
            }
            else
            {
                usb.CloseCom();
                PortOpen.Text = "Open";
                isOpen        = false;
            }
        }