• 大小: 0.08M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-24
  • 语言: 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 控制
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
        }

        private void Form1_Load(object sender EventArgs e)
        {
            this.Text = “串口助手-宇“;
            this.BackColor = Color.FromArgb(200 200 200);
            for (int i = 1; i < 20; i++)
            {
                comboBox1.Items.Add(“COM“ + i.ToString());
            }
            comboBox1.Text = “COM5“;//串口号默认值
            comboBox2.Text = “115200“;//波特率默认值
            //加载停止位
            comboBox3.Items.Add(“0“);
            comboBox3.Items.Add(“1“);
            comboBox3.Items.Add(“1.5“);
            comboBox3.Items.Add(“2“);
            comboBox3.SelectedIndex = 1;

            //加载数据位
            comboBox4.Items.Add(“8“);
            comboBox4.Items.Add(“7“);
            comboBox4.Items.Add(“6“);
            comboBox4.Items.Add(“5“);
            comboBox4.SelectedIndex = 0;

            //加载奇偶校验位
            comboBox5.Items.Add(“无“);
            comboBox5.Items.Add(“奇校验“);
            comboBox5.Items.Add(“偶校验“);
            comboBox5.SelectedIndex = 0;

            serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);//添加事件处理程序
        }

        private void comboBox1_SelectedIndexChanged(object sender EventArgs e)
        {

        }

        private void comboBox2_SelectedIndexChanged(object sender EventArgs e)
        {

        }

        private void comboBox3_SelectedIndexChanged(object sender EventArgs e)
        {

        }

        private void comboBox4_SelectedIndexChanged(object sender EventArgs e)
        {

        }
      
        private void button1_Click(object sender EventArgs e)
        {
            try
            {
                if (serialPort1.IsOpen)
                {
                    serialPort1.Close();    //关闭串口
                    button1.Text = “打开串口“;
                    button1.BackColor = Color.ForestGreen;
                    comboBox1.Enabled = true;
                    comboBox2.Enabled = true;
                    comboBox3.Enabled = true;
                    comboBox4.Enabled = true;
                    comboBox5.Enabled = true;
                  //  textBox1.Text = ““;  //清空接收区
                    label6.Text = “串口已关闭“;
                    label6.ForeColor = Color.Red;
                }
                else
                { 
                    serialPort1.PortName = comboBox1.Text;//设置串口号
                    serialPort1.BaudRate = Convert.ToInt32(comboBox2.Text 10);//十进制数据转换,设置波特率
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件         908  2020-12-21 14:08  控制.sln
     文件       36352  2021-01-09 14:40  控制.v11.suo
     目录           0  2020-12-21 14:08  控制\
     文件         187  2020-12-21 10:55  控制\App.config
     目录           0  2020-12-21 14:08  控制\bin\
     目录           0  2020-12-22 14:56  控制\bin\Debug\
     文件       20992  2021-01-07 23:35  控制\bin\Debug\控制.exe
     文件         187  2020-12-21 10:55  控制\bin\Debug\控制.exe.config
     文件       42496  2021-01-07 23:35  控制\bin\Debug\控制.pdb
     文件       22984  2021-01-09 09:45  控制\bin\Debug\控制.vshost.exe
     文件         187  2020-12-21 10:55  控制\bin\Debug\控制.vshost.exe.config
     文件         490  2019-12-07 17:10  控制\bin\Debug\控制.vshost.exe.manifest
     目录           0  2020-12-21 14:08  控制\bin\Release\
     文件       11400  2021-01-09 14:40  控制\Form1.cs
     文件       25383  2021-01-09 14:40  控制\Form1.Designer.cs
     文件        6211  2021-01-09 14:40  控制\Form1.resx
     目录           0  2020-12-21 14:08  控制\obj\
     目录           0  2021-01-07 23:35  控制\obj\Debug\
     文件        1308  2020-12-22 15:11  控制\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7007  2020-12-22 14:56  控制\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件           0  2020-12-21 10:55  控制\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2020-12-21 10:55  控制\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2020-12-21 10:55  控制\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2020-12-21 14:08  控制\obj\Debug\TempPE\
     文件        1569  2021-01-09 09:45  控制\obj\Debug\控制.csproj.FileListAbsolute.txt
     文件         975  2021-01-07 23:35  控制\obj\Debug\控制.csproj.GenerateResource.Cache
     文件        2209  2020-12-21 11:03  控制\obj\Debug\控制.csprojResolveAssemblyReference.cache
     文件       20992  2021-01-07 23:35  控制\obj\Debug\控制.exe
     文件         180  2021-01-07 23:35  控制\obj\Debug\控制.Form1.resources
     文件       42496  2021-01-07 23:35  控制\obj\Debug\控制.pdb
     文件         180  2020-12-21 14:10  控制\obj\Debug\控制.Properties.Resources.resources
............此处省略10个文件信息

评论

共有 条评论