Ejemplo n.º 1
0
        /// <summary>
        /// 定时器,每秒钟刷新一次
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                //如果本地缓冲区数据足够则读取数据并显示,如果不够,返回
                if (aitask.AvailableSamples < readValue.Length)
                {
                    return;
                }
                timer1.Enabled = false;

                aitask.ReadData(ref readValue, -1);
                toolStripStatusLabel.Text = "正在读取数据中...";
                ArrayManipulation.Transpose(readValue, ref displayValue);
                int      size = displayValue.Length / 3;
                double[] buf1 = new double[size];
                double[] buf2 = new double[size];
                double[] buf3 = new double[size];
                Buffer.BlockCopy(displayValue, 0, buf1, 0, size * sizeof(double));
                Buffer.BlockCopy(displayValue, size * sizeof(double), buf2, 0, size * sizeof(double));
                Buffer.BlockCopy(displayValue, size * sizeof(double), buf3, 0, size * sizeof(double));
                stripChart_position.Plot(_displacementsensor.Convert(buf2));
                //stripChart_position.Plot(Conversion.resistance(buf2, RMax, 10, "cm"));
                //stripChart_weight.Plot(Conversion.Weight(buf1, 12, 250, 2000, 350, 500, "kg"));

                stripChart_weight.Plot(_loadCell.Convert(buf1));
                stripChart1.Plot(_thermistor.Convert(buf3));

                timer1.Enabled = true;
            }
            catch (JYDriverException ex)
            {
                if (ex.ErrorCode == -2 || ex.ErrorCode == -4 || ex.ErrorCode == -304)
                {
                    led1.Value      = false;
                    button1.Enabled = true;
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (Exception ex)
            {
                aitask?.Stop();

                Start.Enabled             = true;
                toolStripStatusLabel.Text = "读取数据失败";
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void easyButton1_Click(object sender, EventArgs e)
        {
            value = (double)numericUpDown_value.Value;
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = value;
            }
            double[] res;

            switch (comboBox1.SelectedItem.ToString())
            {
            case "位移传感器":
                numericUpDown_result.Value = (decimal)DisplacementSensor.Convert(value, (double)numericUpDown_maxDisp.Value, (double)numericUpDown_maxR.Value, (double)numericUpDown_minR.Value);
                res = DisplacementSensor.Convert(values, (double)numericUpDown_maxDisp.Value, (double)numericUpDown_maxR.Value, (double)numericUpDown_minR.Value);
                easyChartX1.Plot(res);
                break;

            case "荷重传感器":
                numericUpDown_result.Value = (decimal)LoadCell.Convert(value, (double)numericUpDown_sensitivity.Value, (double)numericUpDown_maxLoad.Value, (double)numericUpDown_excitationVolt.Value);
                res = LoadCell.Convert(values, (double)numericUpDown_sensitivity.Value, (double)numericUpDown_maxLoad.Value, (double)numericUpDown_excitationVolt.Value);
                easyChartX1.Plot(res);
                break;

            case "热电阻RTD_PT100":
                numericUpDown_result.Value = (decimal)RTD.Convert(value);
                res = RTD.Convert(values);
                easyChartX1.Plot(res);
                break;

            case "热敏电阻Thermistor":
                numericUpDown_result.Value = (decimal)Thermistor.Convert(value, (double)numericUpDown_resistorRT.Value, (double)numericUpDown_beta.Value);
                res = Thermistor.Convert(values, (double)numericUpDown_resistorRT.Value, (double)numericUpDown_beta.Value);
                easyChartX1.Plot(res);
                break;

            case "热电偶Thermocouple":
                numericUpDown_result.Value = (decimal)Thermocouple.Convert((ThermocoupleType)Enum.Parse(typeof(ThermocoupleType), comboBox2.Text), value, checkBox_cjcEnable.Checked, (double)numericUpDown_cjcTemperature.Value);
                res = Thermocouple.Convert((ThermocoupleType)Enum.Parse(typeof(ThermocoupleType), comboBox2.Text), values, checkBox_cjcEnable.Checked, (double)numericUpDown_cjcTemperature.Value);
                easyChartX1.Plot(res);
                break;

            default:
                break;
            }
        }