• 大小: 799KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-06-16
  • 语言: C#
  • 标签: c#  串口通信  显示波形  

资源简介

c# 与单片机之间进行串口通信 ,显示单片机采集的心电波形

资源截图

代码片段和文件信息

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.IO.Ports;
namespace WindowsFormsApplication_serialport_no1
{
    public partial class Form1 : Form
    {
        double tt = 0;
        int time_table = 0;
        int timer = 0;
        public int dian_number = 0;
        double num;
        public string data;
        public short qtemp;
        public int x = 0;
        public string lastport = “COM1“;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender EventArgs e)
        {
            comboBox_COM.Items.AddRange(SerialPort.GetPortNames());
            serialPort1.PortName = lastport ;
            serialPort1.BaudRate = 9600;
            serialPort1.DataBits = 7;
            serialPort1.Close();
           
        }

        private void timer1_Tick(object sender EventArgs e)
        {
            if (serialPort1.IsOpen == true)
            {
                try
                {

                    string data;
                    string stri;
                    data = serialPort1.ReadExisting();
                    int len = data.Length;
                    for (int m = 0; m < len / 7; m++)
                    {
                        try
                        {
                            stri = data.Substring(m * 7 len - 1-m*7);
                            int i = stri.IndexOf(“A“) + 1;
                            int j = stri.IndexOf(“B“);
                            if (i < j)
                            {
                                try
                                {
                                    string str = stri.Substring(i j - i);
                                    num = double.Parse(str);
                                    //   if(dianya[dian_number]!=null)
                                    //       dianya[dian_number] = num;
                                    dian_number++;
                                    time_table++;
                                    this.Invoke(new EventHandler(huatu));
                                }
                                catch
                                {
                                }

                            }
                        }
                        catch
                        { 
                        }
                    }

                }


                catch
                {

                }
            }
            /*
            char[] str = { (char)2 (char)48 (char)49 (char)67 (char)56 (char)48 (char)50 (char)3 (char)55 (char)49 };
            string str1 = str[0].ToString() + str[1].ToString() + str[2].ToString() + str[3].ToString() + str[4].ToString() + str[5].ToString() + str[6]

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-05-22 22:48  c# 串口通信显示心电波形\
     目录           0  2016-05-22 22:48  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\
     文件         187  2015-01-20 09:43  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\App.config
     文件       14659  2015-05-01 16:12  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\Form1.Designer.cs
     文件        8176  2015-05-01 16:20  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\Form1.cs
     文件      470676  2015-05-01 16:20  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\Form1.resx
     文件         550  2015-01-20 09:49  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\Program.cs
     目录           0  2016-05-22 22:48  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\Properties\
     文件        1396  2015-01-20 09:43  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\Properties\AssemblyInfo.cs
     文件        2928  2015-01-20 09:44  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\Properties\Resources.Designer.cs
     文件        5612  2015-01-20 09:43  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\Properties\Resources.resx
     文件        1125  2015-01-20 09:44  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\Properties\Settings.Designer.cs
     文件         249  2015-01-20 09:43  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\Properties\Settings.settings
     文件        3923  2015-04-30 20:34  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\WindowsFormsApplication_serialport_no1.csproj
     目录           0  2016-05-22 22:48  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\bin\
     目录           0  2016-05-22 22:48  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\bin\Debug\
     文件      327168  2016-05-22 22:56  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\bin\Debug\WindowsFormsApplication_serialport_no1.exe
     文件         187  2015-01-20 09:43  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\bin\Debug\WindowsFormsApplication_serialport_no1.exe.config
     文件       75264  2016-05-22 22:56  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\bin\Debug\WindowsFormsApplication_serialport_no1.pdb
     文件       22984  2016-05-22 22:57  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\bin\Debug\WindowsFormsApplication_serialport_no1.vshost.exe
     文件         187  2015-01-20 09:43  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\bin\Debug\WindowsFormsApplication_serialport_no1.vshost.exe.config
     文件         490  2010-03-17 22:39  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\bin\Debug\WindowsFormsApplication_serialport_no1.vshost.exe.manifest
     目录           0  2016-05-22 22:48  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\obj\
     目录           0  2016-05-22 22:56  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\obj\Debug\
     文件        1481  2015-04-30 20:28  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7352  2016-05-22 22:56  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2016-05-23 09:47  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\obj\Debug\TempPE\
     文件           0  2015-01-20 09:44  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2015-01-20 09:44  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2015-01-20 09:44  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     文件      309892  2015-05-01 16:20  c# 串口通信显示心电波形\WindowsFormsApplication_serialport_no1\obj\Debug\WindowsFormsApplication_serialport_no1.Form1.resources
............此处省略9个文件信息

评论

共有 条评论