在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例Windows系统编程 → 钻机参数采集(winform串口数据实时绘图和静态绘图软件)

钻机参数采集(winform串口数据实时绘图和静态绘图软件)

Windows系统编程

下载此实例
  • 开发语言:C#
  • 实例大小:7.43M
  • 下载次数:68
  • 浏览次数:446
  • 发布时间:2020-04-19
  • 实例类别:Windows系统编程
  • 发 布 人:robot666
  • 文件格式:.rar
  • 所需积分:2
 相关标签:

实例介绍

【实例简介】为实验室项目做的小软件,串口通信模式能够接收数据采集卡的数据进行动态显示,U盘数据处理模式能够读取文件进行静态图形显示。

【实例截图】

登录账号:123456 密码:123

from clipboard


from clipboard


from clipboard

【核心代码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.IO.Ports;

namespace 酒店管理
{
    public partial class quankou : Form
    {
        private SerialPort ComDevice = new SerialPort();
        public quankou()
        {
            InitializeComponent();
            this.init();
        }
        string a1 ;
        string a2  ;
        string a3;
        double a4;
        double a5;

        string b1;
        string b2;
        string b3;
        double b4;
        double b5;

        string c1;
        string c2;
        string c3;
        double c4;
        double c5;

        string d1;
        string d2;
        string d3;
        double d4;
        double d5;

        string e1;
        string e2;
        string e3;
        double e4;
        double e5;

        string f1;
        string f2;
        string f3;
        double f4;
        double f5;
       
        public void init()
        {
            btnSend.Enabled = false;
            cbbComList.Items.AddRange(SerialPort.GetPortNames());
            if (cbbComList.Items.Count > 0)
            {
                cbbComList.SelectedIndex = 0;
            }
            cbbBaudRate.SelectedIndex = 5;
            cbbDataBits.SelectedIndex = 0;
            cbbParity.SelectedIndex = 0;
            cbbStopBits.SelectedIndex = 0;
            // pictureBox1.BackgroundImage = Properties.Resources.red;
            ComDevice.DataReceived  = new SerialDataReceivedEventHandler(Com_DataReceived);//绑定事件
        }
        private Timer timer2 = new Timer();
        private Timer timer3 = new Timer();
        private DataTable dt1 = new DataTable();
        private DateTime dtTime = new DateTime();
        private void btnOpen_Click(object sender, System.EventArgs e)
        {
            if (cbbComList.Items.Count <= 0)
            {
                MessageBox.Show("没有发现串口,请检查线路!");
                return;
            }
            if (ComDevice.IsOpen == false)
            {
                ComDevice.PortName = cbbComList.SelectedItem.ToString();
                ComDevice.BaudRate = Convert.ToInt32(cbbBaudRate.SelectedItem.ToString());
                ComDevice.Parity = (Parity)Convert.ToInt32(cbbParity.SelectedIndex.ToString());
                ComDevice.DataBits = Convert.ToInt32(cbbDataBits.SelectedItem.ToString());
                ComDevice.StopBits = (StopBits)Convert.ToInt32(cbbStopBits.SelectedItem.ToString());
                try
                {
                    ComDevice.Open();
                    btnSend.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                btnOpen.Text = "关闭串口";
                //pictureBox1.BackgroundImage = Properties.Resources.green;
            }
            else
            {
                try
                {
                    ComDevice.Close();
                    btnSend.Enabled = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                btnOpen.Text = "打开串口";
                timer1.Enabled = false;
                //pictureBox1.BackgroundImage = Properties.Resources.red;
            }
            cbbComList.Enabled = !ComDevice.IsOpen;
            cbbBaudRate.Enabled = !ComDevice.IsOpen;
            cbbParity.Enabled = !ComDevice.IsOpen;
            cbbDataBits.Enabled = !ComDevice.IsOpen;
            cbbStopBits.Enabled = !ComDevice.IsOpen;
        }
        public void ClearSelf()
        {
            if (ComDevice.IsOpen)
            {
                ComDevice.Close();
            }
        }
        public bool SendData(byte[] data)
        {
            if (ComDevice.IsOpen)
            {
                try
                {
                    ComDevice.Write(data, 0, data.Length);//发送数据
                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("串口未打开", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return false;
        }
        private void btnSend_Click(object sender, System.EventArgs e)
        {  
            if (cbTimeSend.Checked)
            {
                timer1.Enabled = true;
            }
            else
            {
                timer1.Enabled = false;
            }
            byte[] sendData = null;

            if (rbtnSendHex.Checked)
            {
                sendData = strToHexByte(txtSendData.Text.Trim());
            }
            else if (rbtnSendASCII.Checked)
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }
          
          
            else
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }

            if (this.SendData(sendData))//发送数据成功计数
            {
                lblSendCount.Invoke(new MethodInvoker(delegate
                {
                    lblSendCount.Text = (int.Parse(lblSendCount.Text)   txtSendData.Text.Length).ToString();
                }));
            }
            else
            {
            }
        }
        private byte[] strToHexByte(string hexString)
        {
            hexString = hexString.Replace(" ", "");
            if ((hexString.Length % 2) != 0) hexString  = " ";
            byte[] returnBytes = new byte[hexString.Length / 2];
            for (int i = 0; i < returnBytes.Length; i  )
                returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2).Replace(" ", ""), 16);
            return returnBytes;
        }
        private void Com_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            byte[] ReDatas = new byte[ComDevice.BytesToRead];
            ComDevice.Read(ReDatas, 0, ReDatas.Length);//读取数据
            this.AddData(ReDatas);//输出数据
        }
        public void AddData(byte[] data)
        {
            if (rbtnHex.Checked)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < data.Length; i  )
                {
                    sb.AppendFormat("{0:x2}"   " ", data[i]);
                }
                AddContent(sb.ToString().ToUpper());
            }
            else if (rbtnASCII.Checked)
            {
                AddContent(new ASCIIEncoding().GetString(data));
            }
          
           
            else
            { }

            lblRevCount.Invoke(new MethodInvoker(delegate
            {
                lblRevCount.Text = (int.Parse(lblRevCount.Text)   data.Length).ToString();
            }));
        }
        private void AddContent(string content)
        {
            this.BeginInvoke(new MethodInvoker(delegate
            {
                if (chkAutoLine.Checked && txtShowData.Text.Length > 0)
                {
                    txtShowData.AppendText("\r\n");
                }
                txtShowData.AppendText(content);
            }));
        }
        private void btnClearRev_Click(object sender, System.EventArgs e)
        {
            txtShowData.Clear();
        }
        private void btnClearSend_Click(object sender, System.EventArgs e)
        {
            txtSendData.Clear();
        }
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
        }
       
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            string strSecond = txtSecond.Text;
            try
            {
                int isecond = int.Parse(strSecond) * 100;//Interval以微秒为单位  
                timer1.Interval = isecond;
                if (timer1.Enabled == true)
                {
                    btnSend.PerformClick(); //产生“发送”的click事件  
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("错误的定时输入!", "Error");
            }  
        }
        double index = 0;
        Int32 num = 0;
        private void timer2_tick(object sender, EventArgs e)
        {
            string str = txtShowData.Text.ToString();
            string[] strArr = str.Split(new char[] { ' ', '\n', '-' });
             a1 = strArr[3   21 * num];
             a2 = strArr[4   21 * num];
             a3 = a1   a2;
             a4 = Convert.ToInt32(a3, 16);
             a5 = a4;

             b1 = strArr[5   21 * num];
             b2 = strArr[6   21 * num];
             b3 = b1   b2;
             b4 = Convert.ToInt32(b3, 16);
             b5 = b4;

             c1 = strArr[7   21 * num];
             c2 = strArr[8   21 * num];
             c3 = c1   c2;
             c4 = Convert.ToInt32(c3, 16);
             c5 = c4 ;

             d1 = strArr[9   21 * num];
             d2 = strArr[10   21 * num];
             d3 = d1   d2;
             d4 = Convert.ToInt32(d3, 16);
             d5 = d4 ;

             e1 = strArr[11   21 * num];
             e2 = strArr[12   21 * num];
             e3 = e1   e2;
             e4 = Convert.ToInt32(e3, 16);
             e5 = e4 ;

             f1 = strArr[13   21 * num];
             f2 = strArr[14   21 * num];
             f3 = f1   f2;
             f4 = Convert.ToInt32(f3, 16);
             f5 = f4;

            double dy = a5;
            double dy1 = b5;
            double dy2 = c5;
            double dy3 = d5;
            double dy4 = e5;
            double dy5 = f5;
            dy = dy * 0.03 * 0.2;
            dy1 = dy1 * 0.03 * 0.2;
            dy2 = dy2 * 0.03 * 0.2;
            dy3 = dy3 * 0.03 * 0.2;
            dy4 = dy4 * 0.02;
            dy5 = dy5 * 0.4;
            this.chart1.Series[0].Points.RemoveAt(0);
            this.chart1.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy.ToString("0.00"));
            this.chart2.Series[0].Points.RemoveAt(0);
            this.chart2.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy1.ToString("0.00"));
            this.chart3.Series[0].Points.RemoveAt(0);
            this.chart3.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy2.ToString("0.00"));
            this.chart4.Series[0].Points.RemoveAt(0);
            this.chart4.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy3.ToString("0.00"));
            this.chart5.Series[0].Points.RemoveAt(0);
            this.chart5.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy4.ToString("0.00"));
            this.chart6.Series[0].Points.RemoveAt(0);
            this.chart6.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy5.ToString("0.00"));
            index = index 0.1;
            num  ;
        }
        private void button1_Click(object sender, System.EventArgs e)
        {

            chart1.Series[0].Points.Clear();
            chart2.Series[0].Points.Clear();
            chart3.Series[0].Points.Clear();
            chart4.Series[0].Points.Clear();
            chart5.Series[0].Points.Clear();
            chart6.Series[0].Points.Clear();

            txtSendData.Text = "64 04 03 E7 00 08 48 4A";
            cbTimeSend.Checked = true;
            txtSecond.Text = "1";

            if (cbTimeSend.Checked)
            {
                timer1.Enabled = true;
            }
            else
            {
                timer1.Enabled = false;
            }
            byte[] sendData = null;

            if (rbtnSendHex.Checked)
            {
                sendData = strToHexByte(txtSendData.Text.Trim());
            }
            else if (rbtnSendASCII.Checked)
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }


            else
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }

            if (this.SendData(sendData))//发送数据成功计数
            {
                lblSendCount.Invoke(new MethodInvoker(delegate
                {
                    lblSendCount.Text = (int.Parse(lblSendCount.Text)   txtSendData.Text.Length).ToString();
                }));
            }
            else
            {
            }

         

                this.chart1.Titles.Add("液压缸进口压力");
                this.chart1.ChartAreas[0].AxisX.Title = "时间";
                this.chart1.ChartAreas[0].AxisY.Title = "压力(MPa)";
                this.chart1.ChartAreas[0].AxisX.Interval = 10;
                this.chart1.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart1.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart1.ChartAreas[0].AxisY.Interval = 5;
                this.chart1.ChartAreas[0].AxisY.Maximum = 30;
                //this.chart1.Series.Add("series1");

                this.chart2.Titles.Add("液压缸出口压力");
                this.chart2.ChartAreas[0].AxisX.Title = "时间";
                this.chart2.ChartAreas[0].AxisY.Title = "压力(MPa)";
                this.chart2.ChartAreas[0].AxisX.Interval = 10;
                this.chart2.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart2.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart2.ChartAreas[0].AxisY.Interval = 5;
                this.chart2.ChartAreas[0].AxisY.Maximum = 30;
                //this.chart2.Series.Add("series1");

                this.chart3.Titles.Add("液压马达进口压力");
                this.chart3.ChartAreas[0].AxisX.Title = "时间";
                this.chart3.ChartAreas[0].AxisY.Title = "压力(MPa)";
                this.chart3.ChartAreas[0].AxisX.Interval = 10;
                this.chart3.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart3.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart3.ChartAreas[0].AxisY.Interval = 5;
                this.chart3.ChartAreas[0].AxisY.Maximum =30;
                //this.chart3.Series.Add("series1");

                this.chart4.Titles.Add("液压马达出口压力");
                this.chart4.ChartAreas[0].AxisX.Title = "时间";
                this.chart4.ChartAreas[0].AxisY.Title = "压力(MPa)";
                this.chart4.ChartAreas[0].AxisX.Interval = 10;
                this.chart4.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart4.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart4.ChartAreas[0].AxisY.Interval = 5;
                this.chart4.ChartAreas[0].AxisY.Maximum = 30;
                //this.chart4.Series.Add("series1");

                this.chart5.Titles.Add("液压马达流量");
                this.chart5.ChartAreas[0].AxisX.Title = "时间";
                this.chart5.ChartAreas[0].AxisY.Title = "流量(L/min)";
                this.chart5.ChartAreas[0].AxisX.Interval = 10;
                this.chart5.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart5.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart5.ChartAreas[0].AxisY.Interval = 10;
                this.chart5.ChartAreas[0].AxisY.Maximum = 100;
               // this.chart5.Series.Add("series1");

                this.chart6.Titles.Add("主轴转速");
                this.chart6.ChartAreas[0].AxisX.Title = "时间";
                this.chart6.ChartAreas[0].AxisY.Title = "转速(n/min)";
                this.chart6.ChartAreas[0].AxisX.Interval = 10;
                this.chart6.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart6.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart6.ChartAreas[0].AxisY.Interval = 200;
                this.chart6.ChartAreas[0].AxisY.Maximum = 2000;
                //this.chart6.Series.Add("series1");
                //使图标刚开始的时候是空的,随着时间的推移才逐渐画满,可以在初始化的时候填几个Y坐标为0的点:
                for (int i = 0; i < 60; i  )
                {
                    System.Windows.Forms.DataVisualization.Charting.DataPoint dp = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
                    dp.SetValueXY(DateTime.Now.AddSeconds(-60   i).ToString("HH:mm:ss"), 0);
                    this.chart1.Series[0].Points.Add(dp);
                    this.chart2.Series[0].Points.Add(dp);
                    this.chart3.Series[0].Points.Add(dp);
                    this.chart4.Series[0].Points.Add(dp);
                    this.chart5.Series[0].Points.Add(dp);
                    this.chart6.Series[0].Points.Add(dp);
                }

                chart1.Series[0].IsValueShownAsLabel = false ;
                this.chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line ;
                this.chart1.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart1.Series[0].BorderWidth = 3;
                chart2.Series[0].IsValueShownAsLabel = false;
                this.chart2.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.chart2.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart2.Series[0].BorderWidth = 3;
                chart3.Series[0].IsValueShownAsLabel = false;
                this.chart3.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.chart3.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart3.Series[0].BorderWidth = 3;
                chart4.Series[0].IsValueShownAsLabel = false;
                this.chart4.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.chart4.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart4.Series[0].BorderWidth = 3;
                chart5.Series[0].IsValueShownAsLabel = false;
                this.chart5.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.chart5.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart5.Series[0].BorderWidth = 3;
                chart6.Series[0].IsValueShownAsLabel = false;
                this.chart6.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.chart6.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart6.Series[0].BorderWidth = 3;
                
       
                timer2.Interval = 100 * 1;
                timer2.Tick  = new EventHandler(timer2_tick);
                timer2.Start();
                dtTime = DateTime.Now;
           // }

        }

        private void btnstart_Click(object sender, EventArgs e)
        {
            txtSendData.Text = "64 04 03 E7 00 08 48 4A";
            cbTimeSend.Checked=true ;
            txtSecond.Text  = "1";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer2.Stop();
           cbTimeSend.Checked = false ;
        }

        private void continu_show_Click(object sender, EventArgs e)
        {
            chart1.Series[0].Points.Clear();
            chart2.Series[0].Points.Clear();
            chart3.Series[0].Points.Clear();
            chart4.Series[0].Points.Clear();
            chart5.Series[0].Points.Clear();
            chart6.Series[0].Points.Clear();

            txtSendData.Text = "64 04 03 E7 00 08 48 4A";
            cbTimeSend.Checked = true;
            txtSecond.Text = "1";

            if (cbTimeSend.Checked)
            {
                timer1.Enabled = true;
            }
            else
            {
                timer1.Enabled = false;
            }
            byte[] sendData = null;

            if (rbtnSendHex.Checked)
            {
                sendData = strToHexByte(txtSendData.Text.Trim());
            }
            else if (rbtnSendASCII.Checked)
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }


            else
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }

            if (this.SendData(sendData))//发送数据成功计数
            {
                lblSendCount.Invoke(new MethodInvoker(delegate
                {
                    lblSendCount.Text = (int.Parse(lblSendCount.Text)   txtSendData.Text.Length).ToString();
                }));
            }
            else
            {
            }


            this.chart1.Titles.Clear();
            this.chart1.Titles.Add("液压缸进口压力");
            this.chart1.ChartAreas[0].AxisX.Title = "时间";
            this.chart1.ChartAreas[0].AxisY.Title = "压力(MPa)";
            this.chart1.ChartAreas[0].AxisX.Interval = 10;
            this.chart1.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart1.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart1.ChartAreas[0].AxisY.Interval = 5;
            this.chart1.ChartAreas[0].AxisY.Maximum = 30;
            //this.chart1.Series.Add("series1");
            this.chart2.Titles.Clear();
            this.chart2.Titles.Add("液压缸出口压力");
            this.chart2.ChartAreas[0].AxisX.Title = "时间";
            this.chart2.ChartAreas[0].AxisY.Title = "压力(MPa)";
            this.chart2.ChartAreas[0].AxisX.Interval = 10;
            this.chart2.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart2.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart2.ChartAreas[0].AxisY.Interval = 5;
            this.chart2.ChartAreas[0].AxisY.Maximum = 30;
            //this.chart2.Series.Add("series1");
            this.chart3.Titles.Clear();
            this.chart3.Titles.Add("液压马达进口压力");
            this.chart3.ChartAreas[0].AxisX.Title = "时间";
            this.chart3.ChartAreas[0].AxisY.Title = "压力(MPa)";
            this.chart3.ChartAreas[0].AxisX.Interval = 10;
            this.chart3.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart3.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart3.ChartAreas[0].AxisY.Interval = 5;
            this.chart3.ChartAreas[0].AxisY.Maximum = 30;
            //this.chart3.Series.Add("series1");
            this.chart4.Titles.Clear();
            this.chart4.Titles.Add("液压马达出口压力");
            this.chart4.ChartAreas[0].AxisX.Title = "时间";
            this.chart4.ChartAreas[0].AxisY.Title = "压力(MPa)";
            this.chart4.ChartAreas[0].AxisX.Interval = 10;
            this.chart4.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart4.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart4.ChartAreas[0].AxisY.Interval = 5;
            this.chart4.ChartAreas[0].AxisY.Maximum = 30;
            //this.chart4.Series.Add("series1");
            this.chart5.Titles.Clear();
            this.chart5.Titles.Add("液压马达流量");
            this.chart5.ChartAreas[0].AxisX.Title = "时间";
            this.chart5.ChartAreas[0].AxisY.Title = "流量(L/min)";
            this.chart5.ChartAreas[0].AxisX.Interval = 10;
            this.chart5.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart5.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart5.ChartAreas[0].AxisY.Interval = 10;
            this.chart5.ChartAreas[0].AxisY.Maximum = 100;
            // this.chart5.Series.Add("series1");
            this.chart6.Titles.Clear();
            this.chart6.Titles.Add("主轴转速");
            this.chart6.ChartAreas[0].AxisX.Title = "时间";
            this.chart6.ChartAreas[0].AxisY.Title = "转速(n/min)";
            this.chart6.ChartAreas[0].AxisX.Interval = 10;
            this.chart6.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart6.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart6.ChartAreas[0].AxisY.Interval = 200;
            this.chart6.ChartAreas[0].AxisY.Maximum = 2000;
            //this.chart6.Series.Add("series1");
            //使图标刚开始的时候是空的,随着时间的推移才逐渐画满,可以在初始化的时候填几个Y坐标为0的点:
            for (int i = 0; i < 60; i  )
            {
                System.Windows.Forms.DataVisualization.Charting.DataPoint dp = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
                dp.SetValueXY(DateTime.Now.AddSeconds(-60   i).ToString("HH:mm:ss"), 0);
                this.chart1.Series[0].Points.Add(dp);
                this.chart2.Series[0].Points.Add(dp);
                this.chart3.Series[0].Points.Add(dp);
                this.chart4.Series[0].Points.Add(dp);
                this.chart5.Series[0].Points.Add(dp);
                this.chart6.Series[0].Points.Add(dp);
            }

            chart1.Series[0].IsValueShownAsLabel = false;
            this.chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart1.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart1.Series[0].BorderWidth = 3;
            chart2.Series[0].IsValueShownAsLabel = false;
            this.chart2.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart2.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart2.Series[0].BorderWidth = 3;
            chart3.Series[0].IsValueShownAsLabel = false;
            this.chart3.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart3.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart3.Series[0].BorderWidth = 3;
            chart4.Series[0].IsValueShownAsLabel = false;
            this.chart4.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart4.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart4.Series[0].BorderWidth = 3;
            chart5.Series[0].IsValueShownAsLabel = false;
            this.chart5.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart5.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart5.Series[0].BorderWidth = 3;
            chart6.Series[0].IsValueShownAsLabel = false;
            this.chart6.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart6.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart6.Series[0].BorderWidth = 3;
            timer2.Interval = 100 * 1;
            //timer2.Tick  = new EventHandler(timer2_tick);
            timer2.Start();
            dtTime = DateTime.Now;
        }
       
    }
}

标签:

实例下载地址

钻机参数采集(winform串口数据实时绘图和静态绘图软件)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警