• 大小: 61KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: C#
  • 标签: 串口  

资源简介

自己用C#编写的基于串口的Chart数据曲线图,已调试通过。

资源截图

代码片段和文件信息

using System;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;
using System.Windows.Forms.DataVisualization.Charting;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private Random RandomNum = new Random();
        private string values;
        private string Xstring;
        private string Ystring;
        private string Ystring2;
       

        public Form1()
        {
            InitializeComponent();
            chart1.Series[“Series1“].Color = Color.Green;
            chart1.Series[“Series1“].XValueType = ChartValueType.String;
            chart1.Series[“Series2“].XValueType = ChartValueType.String;

            chart1.ChartAreas[“ChartArea1“].AxisY.Minimum = -700;
            chart1.ChartAreas[“ChartArea1“].AxisY.Maximum = 700;

            chart1.ChartAreas[“ChartArea1“].AxisX.ScrollBar.IsPositionedInside = false;//设置滚动条是在外部显示
            chart1.ChartAreas[“ChartArea1“].AxisX.ScrollBar.Size = 20;//设置滚动条的宽度
            chart1.ChartAreas[“ChartArea1“].AxisX.ScrollBar.Buttonstyle = ScrollBarButtonstyles.SmallScroll;//滚动条只显示向前的按钮,主要是为了不显示取消显示的按钮
            chart1.ChartAreas[“ChartArea1“].AxisX.ScaleView.Size = 10;//设置图表可视区域数据点数,说白了一次可以看到多少个X轴区域
            chart1.ChartAreas[“ChartArea1“].AxisX.ScaleView.MinSize = 1;//设置滚动一次,移动几格区域
            chart1.ChartAreas[“ChartArea1“].AxisX.Interval = 1;//设置X轴的间隔,设置它是为了看起来方便点,也就是要每个X轴的记录都显示出来
            chart1.ChartAreas[0].AxisX.ScaleView.Scroll(DateTime.Now);   /*滚动到最新时间数据*/



            //chart1.ChartAreas[“ChartArea1“].AxisX.Minimum = 0;
            //chart1.ChartAreas[“ChartArea1“].AxisX.Maximum = 1000;




        }

        public void SendMotorFunc(string strFunc)
        {
            if (serialPortMotor.IsOpen)
            {
             
                serialPortMotor.Write(strFunc);
              
            }
        }
   
        private void buttonOpen_Click(object sender EventArgs e)
        {
            try
            {
                //Xstring = “abc23456defg“;

                //Ystring = Xstring.Substring(Xstring.IndexOf(“c“) + 1 Xstring.IndexOf(“de“) - Xstring.IndexOf(“c“) - 1);
                //Ystring = Xstring.Substring(Xstring.LastIndexOf(“c“)+1 2);
                //Ystring = Xstring.Substring(Xstring.IndexOf(“c“));
                //MessageBox.Show(Ystring);
                timer1.Enabled = true;
                timer1.Interval = 1000;

                serialPortMotor.Open();
                richTextBox1.AppendText(“串口打开成功“);

              
            }
            catch
            {
                richTextBox1.AppendText(“串口打开失败“);
            }
        }

        private void buttonClose_Click(object sender EventArgs e)
        {


            timer1.Enabled = false;

            if (serialPortMotor.IsOpen)
            {
                serialPortMotor.Close();
                ric

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        184  2014-12-29 12:32  chart-test-c#\WindowsFormsApplication1\App.config

     文件      14336  2016-02-22 09:27  chart-test-c#\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe

     文件        184  2014-12-29 12:32  chart-test-c#\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe.config

     文件      30208  2016-02-22 09:27  chart-test-c#\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb

     文件      24216  2016-03-04 09:00  chart-test-c#\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe

     文件        184  2014-12-29 12:32  chart-test-c#\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.config

     文件        490  2010-03-17 22:39  chart-test-c#\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest

     文件       8265  2016-02-22 09:27  chart-test-c#\WindowsFormsApplication1\Form1.cs

     文件       8766  2016-02-19 09:30  chart-test-c#\WindowsFormsApplication1\Form1.Designer.cs

     文件       6215  2016-02-19 09:30  chart-test-c#\WindowsFormsApplication1\Form1.resx

     文件       2176  2016-02-10 20:46  chart-test-c#\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7106  2016-03-04 09:00  chart-test-c#\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2014-12-29 12:22  chart-test-c#\WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2014-12-29 12:22  chart-test-c#\WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2014-12-29 12:22  chart-test-c#\WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       4608  2015-01-21 21:06  chart-test-c#\WindowsFormsApplication1\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件       5797  2016-03-04 09:00  chart-test-c#\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt

     文件        977  2016-02-19 09:30  chart-test-c#\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache

     文件       3954  2016-02-17 09:20  chart-test-c#\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csprojResolveAssemblyReference.cache

     文件      14336  2016-02-22 09:27  chart-test-c#\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.exe

     文件        180  2016-02-19 09:30  chart-test-c#\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Form1.resources

     文件      30208  2016-02-22 09:27  chart-test-c#\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.pdb

     文件        180  2016-02-17 09:20  chart-test-c#\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources

     文件        536  2014-12-29 12:22  chart-test-c#\WindowsFormsApplication1\Program.cs

     文件       1372  2014-12-29 12:22  chart-test-c#\WindowsFormsApplication1\Properties\AssemblyInfo.cs

     文件       2888  2014-12-29 12:32  chart-test-c#\WindowsFormsApplication1\Properties\Resources.Designer.cs

     文件       5612  2014-12-29 12:22  chart-test-c#\WindowsFormsApplication1\Properties\Resources.resx

     文件       1124  2014-12-29 12:32  chart-test-c#\WindowsFormsApplication1\Properties\Settings.Designer.cs

     文件        249  2014-12-29 12:22  chart-test-c#\WindowsFormsApplication1\Properties\Settings.settings

     文件       3965  2016-02-10 22:22  chart-test-c#\WindowsFormsApplication1\WindowsFormsApplication1.csproj

............此处省略13个文件信息

评论

共有 条评论