• 大小: 45KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-06-12
  • 语言: C#
  • 标签: usart串口  

资源简介

基于C#程序的串口收发软件,易于初学者学习引用。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
namespace uart_test
{
    public partial class Form1 : Form
    {
        Boolean UartClose = false;  //ToolOpen 的控制命令 
        public SerialPort PortM3;      //定义M3的端口
        Uart UartInitial = new Uart();

        #region
            public string ConvertString(string value int frombase int tobase)
            {
                string temp = ““;
                int intValue = Convert.ToInt32(value frombase);

                temp = Convert.ToString(intValue tobase).ToUpper();
                if (temp.Length < 2)
                { temp = “0“ + temp; }
                return temp;
            }
        #endregion


        public Form1()
        {
            InitializeComponent();
            comboBoxPort.Items.AddRange(SerialPort.GetPortNames());
            
        }

        private void butSend_Click(object sender EventArgs e)
        {
            if (UartClose)
            {
                butSend.BackColor = Color.FromArgb(255 192 192);
                butSend.Text = “发送开启“;
                if (PortM3 != null)
                {
                    PortM3.Close();
                }
                UartClose = false;
            }
            else
            {

                if (UartInitial.SerialPortOpen(serialBoardcomboBoxPort.SelectedItem.ToString()))
                {
                    butSend.Text = “发送关闭“;
                    butSend.BackColor = Color.Red;
                    UartClose = true;
                    PortM3 = serialBoard;
                    //----发送数据---------------

                    PortM3.Write(textBoxSend.Text);
    

                    ////----接收数据---------------
                    //_keepReading = true;
                    //_readThread = new Thread(ReadPort);
                    //_readThread.Start();


                }
            }
        }

        private void button1_Click(object sender EventArgs e)
        {
            //Byte[] TxData ={ 1 2 3 4 5 6 255 8123231111 };
            //PortM3.Write(TxData 0 8);
            //PortM3.Write(TxData0TxData.Length);
            //PortM3.WriteLine(TxData.ToString());
            //textBoxRec.Text = TxData.ToString();

            //string StrTemp = this.PortM3.ReadLine();

            //textBoxRec.Text = StrTemp;
            //_keepReading = true;
            //ReadPort();

        }



        private void serialBoard_DataReceived(object sender SerialDataReceivedEventArgs e)
        {
            //string temptxt = this.PortM3.ReadLine();

            //string b = temptxt;

        //    /*-------按每个字节进行读取---------------------*/
        //    ////int SDateTemp = this.serialPort1.ReadByte(); 

        //    //int bytes = thi

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-09-17 16:48  串口测试\
     目录           0  2014-09-17 16:48  串口测试\uart_test\
     目录           0  2014-09-17 16:48  串口测试\uart_test\uart_test\
     文件         916  2014-05-21 08:59  串口测试\uart_test\uart_test.sln
     文件       15872  2015-10-21 09:50  串口测试\uart_test\uart_test.suo
     目录           0  2014-09-17 16:48  串口测试\uart_test\uart_test\bin\
     目录           0  2014-09-17 16:48  串口测试\uart_test\uart_test\bin\Debug\
     文件       24576  2014-05-21 16:34  串口测试\uart_test\uart_test\bin\Debug\uart_test.exe
     文件       30208  2014-05-21 16:34  串口测试\uart_test\uart_test\bin\Debug\uart_test.pdb
     文件        5632  2005-12-08 14:51  串口测试\uart_test\uart_test\bin\Debug\uart_test.vshost.exe
     文件        8145  2014-05-21 16:34  串口测试\uart_test\uart_test\Form1.cs
     文件        8831  2014-05-21 15:47  串口测试\uart_test\uart_test\Form1.Designer.cs
     文件        6186  2014-05-21 15:47  串口测试\uart_test\uart_test\Form1.resx
     目录           0  2014-09-17 16:48  串口测试\uart_test\uart_test\obj\
     目录           0  2014-09-17 16:48  串口测试\uart_test\uart_test\obj\Debug\
     目录           0  2014-05-21 09:02  串口测试\uart_test\uart_test\obj\Debug\Refactor\
     目录           0  2014-05-21 08:59  串口测试\uart_test\uart_test\obj\Debug\TempPE\
     文件         842  2014-05-21 15:47  串口测试\uart_test\uart_test\obj\Debug\uart_test.csproj.GenerateResource.Cache
     文件       24576  2014-05-21 16:34  串口测试\uart_test\uart_test\obj\Debug\uart_test.exe
     文件         180  2014-05-21 15:47  串口测试\uart_test\uart_test\obj\Debug\uart_test.Form1.resources
     文件       30208  2014-05-21 16:34  串口测试\uart_test\uart_test\obj\Debug\uart_test.pdb
     文件         180  2014-05-21 09:33  串口测试\uart_test\uart_test\obj\Debug\uart_test.Properties.Resources.resources
     文件         978  2015-10-21 09:47  串口测试\uart_test\uart_test\obj\uart_test.csproj.FileListAbsolute.txt
     文件         468  2014-05-21 08:59  串口测试\uart_test\uart_test\Program.cs
     目录           0  2014-09-17 16:48  串口测试\uart_test\uart_test\Properties\
     文件        1176  2014-05-21 08:59  串口测试\uart_test\uart_test\Properties\AssemblyInfo.cs
     文件        2874  2014-05-21 08:59  串口测试\uart_test\uart_test\Properties\Resources.Designer.cs
     文件        5612  2014-05-21 08:59  串口测试\uart_test\uart_test\Properties\Resources.resx
     文件        1094  2014-05-21 08:59  串口测试\uart_test\uart_test\Properties\Settings.Designer.cs
     文件         249  2014-05-21 08:59  串口测试\uart_test\uart_test\Properties\Settings.settings
     文件        1160  2014-05-21 10:39  串口测试\uart_test\uart_test\Uart.cs
............此处省略1个文件信息

评论

共有 条评论

相关资源