Esempio n. 1
0
        private void calculate_random(object obj)
        {
            SimulatorParam param  = (SimulatorParam)obj;
            Random         random = new Random();

            int timeout = param.stepTime * 1000;

            while (true)
            {
                int value = random.Next((int)param.min, (int)param.max);
                param.tag.Data.UpdateValue(value, DateTime.Now);
                Thread.Sleep(timeout);
            }
        }
Esempio n. 2
0
        private void calculate_sinusoid(object obj)
        {
            SimulatorParam param = (SimulatorParam)obj;

            int    intervalCount = SIN_WAVE / param.stepTime;   //количество меток времени для записи в архив
            double kof           = 2 * Math.PI / intervalCount; //угловой коэффициент
            int    timeout       = param.stepTime * 1000;


            param.tag.Data.UpdateValue(0, DateTime.Now);
            Thread.Sleep(timeout);
            while (true)
            {
                double angle = kof;
                for (int i = 0; i < intervalCount; i++)
                {
                    double value = Math.Sin(angle) * param.max;
                    angle += kof;
                    param.tag.Data.UpdateValue(value, DateTime.Now);
                    Thread.Sleep(timeout);
                }
            }
        }
Esempio n. 3
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (!isConnect)
            {
                notify("Отсутствует подключение с сервером!!!");
                return;
            }



            switch (comboBox1.SelectedIndex)
            {
            case 0:
                simulator = new SimulatorRandom();
                break;

            case 1:
                simulator = new SimulatorSinusoid();
                break;
            }


            PIPoint tag = searchPoint(textBoxTag.Text);

            if (tag == null)
            {
                return;
            }

            SimulatorParam param = new SimulatorParam();

            try
            {
                if (comboBox1.SelectedIndex == 0)
                {
                    param.min = double.Parse(textBox4.Text);
                }
                param.max      = double.Parse(textBox5.Text);
                param.stepTime = int.Parse(textBox6.Text);

                if (param.stepTime >= 43200)
                {
                    throw new Exception("Step Time не может быть больше 12 часов!!!");
                }
                ;
                param.tag = tag;
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("{0}", ex.Message), "Ошибка ввода данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (simulator != null)
            {
                simulator.Start(param);
                notify("Simulator запущен!");
                btnStart.Enabled = false;
                btnStop.Enabled  = true;
            }
            else
            {
                notify("Не удалось определить тип Simulator!!!");
            }
        }
Esempio n. 4
0
 public void Start(SimulatorParam param)
 {
     thread = new Thread(new ParameterizedThreadStart(calculate_random));
     thread.Start(param);
 }