예제 #1
0
        private void ConnectToDevice_Click(object sender, EventArgs e)
        {
            cnct.Address = DeviceList.Text;
            if (cnct.Connection() == "Error")
            {
                MessageBox.Show("Ошибка подключения к прибору  \n" + cnct.ErrorMessage);
            }
            string Info = cnct.Info();

            DeviceInfo.Text = "Информация о приборе: " + Info;
            cnct.CloseSession();
        }
예제 #2
0
        private void Backgroundproccess_DoWork(object sender, DoWorkEventArgs e) //процедура фонового процесса (обращение к прибору)
        {
            //var cn=(IConnect)e.Argument;
            IConnect cnct = setting.NewConnect();

            //if (cn!=null) cnct.Mode = cn.Mode;
            //if (cn != null) cnct.Address = cn.Address;


            //(Connect)e.Argument;
            if (cnct.Connection() == "Error")
            {
                MessageBox.Show("Ошибка подключения к прибору");
            }

            for (long i = 0; !backgroundproccess.CancellationPending; i++)
            {
                while (true)
                {
                    string str_f = cnct.MeasFreq();
                    if (str_f == "VCH_Error_NotEnoughPhaseData")
                    {
                        continue;
                    }

                    double f = Conversion.Val(str_f.Replace(",", "."));

                    const int f0          = 5000000;
                    double    f_new       = 0;
                    string    time_string = "";

                    if (cnct.Type == "ConnectVCH308")
                    {
                        time_string = DateTime.Now.ToString();
                        f_new       = f;
                        backgroundproccess.ReportProgress((int)i, f_new);//возвращаем частоту
                    }
                    else
                    {
                        //time_last = DateTime.Now;
                        time_string = DateTime.Now.ToString();
                        f_new       = (f0 - f) / f0;
                        backgroundproccess.ReportProgress((int)i, f_new);//возвращаем частоту
                    }
                    if (backgroundproccess.CancellationPending)
                    {
                        cnct.CloseSession();
                        break;
                    }
                }
            }
        }