• 大小: 38KB
    文件类型: .rar
    金币: 2
    下载: 2 次
    发布日期: 2021-06-11
  • 语言: C#
  • 标签:

资源简介

基于C#的rs232发送和接收数据 基于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.Runtime.InteropServices;

namespace Ex13_01
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            serialPort1.PortName = “COM1“;
            serialPort1.BaudRate = 9600;
            serialPort1.Open();
            byte[] data = Encoding.Unicode.GetBytes(textBox1.Text);
            string str = Convert.Tobase64String(data);
            serialPort1.WriteLine(str);
            MessageBox.Show(“数据发送成功!““系统提示“);
        }

        private void button2_Click(object sender EventArgs e)
        {
            byte[] data = Convert.Frombase64String(serialPort1.ReadLine());
            textBox2.Text = Encoding.Unicode.GetString(data);
            serialPort1.Close();
            MessageBox.Show(“数据接收成功!““系统提示“);
        }
    }
}

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

     文件      20480  2009-04-12 22:42  串口\Ex13_01\bin\Debug\Ex13_01.exe

     文件      24064  2009-04-12 22:42  串口\Ex13_01\bin\Debug\Ex13_01.pdb

     文件       5632  2007-08-21 15:09  串口\Ex13_01\bin\Debug\Ex13_01.vshost.exe

     文件       5632  2007-08-21 15:09  串口\Ex13_01\bin\Release\Ex13_01.vshost.exe

     文件       3270  2007-08-21 15:09  串口\Ex13_01\Ex23_07.csproj

     文件       1163  2009-04-12 22:43  串口\Ex13_01\Form1.cs

     文件       4923  2007-08-21 15:09  串口\Ex13_01\Form1.Designer.cs

     文件       6013  2009-04-12 22:38  串口\Ex13_01\Form1.resx

     文件        842  2007-08-21 15:09  串口\Ex13_01\obj\Debug\Ex13_01.csproj.GenerateResource.Cache

     文件      20480  2009-04-12 22:42  串口\Ex13_01\obj\Debug\Ex13_01.exe

     文件        180  2009-04-12 22:38  串口\Ex13_01\obj\Debug\Ex13_01.Form1.resources

     文件      24064  2009-04-12 22:42  串口\Ex13_01\obj\Debug\Ex13_01.pdb

     文件        180  2007-08-21 15:09  串口\Ex13_01\obj\Debug\Ex13_01.Properties.Resources.resources

     文件        842  2009-04-12 22:38  串口\Ex13_01\obj\Debug\Ex23_07.csproj.GenerateResource.Cache

     文件        632  2007-08-21 15:09  串口\Ex13_01\obj\Ex13_01.csproj.FileList.txt

     文件        268  2009-04-12 22:42  串口\Ex13_01\obj\Ex23_07.csproj.FileList.txt

     文件        842  2007-08-21 15:09  串口\Ex13_01\obj\Release\Ex13_01.csproj.GenerateResource.Cache

     文件        180  2007-08-21 15:09  串口\Ex13_01\obj\Release\Ex13_01.Form1.resources

     文件        180  2007-08-21 15:09  串口\Ex13_01\obj\Release\Ex13_01.Properties.Resources.resources

     文件        842  2007-08-21 15:09  串口\Ex13_01\obj\unsafe\Ex13_01.csproj.GenerateResource.Cache

     文件        180  2007-08-21 15:09  串口\Ex13_01\obj\unsafe\Ex13_01.Form1.resources

     文件        180  2007-08-21 15:09  串口\Ex13_01\obj\unsafe\Ex13_01.Properties.Resources.resources

     文件        466  2007-08-21 15:09  串口\Ex13_01\Program.cs

     文件       1162  2007-08-21 15:09  串口\Ex13_01\Properties\AssemblyInfo.cs

     文件       2868  2007-08-21 15:09  串口\Ex13_01\Properties\Resources.Designer.cs

     文件       5612  2007-08-21 15:09  串口\Ex13_01\Properties\Resources.resx

     文件       1090  2007-08-21 15:09  串口\Ex13_01\Properties\Settings.Designer.cs

     文件        249  2007-08-21 15:09  串口\Ex13_01\Properties\Settings.settings

     文件       1113  2007-08-21 15:09  串口\Ex23_07.sln

    ..A..H.     16896  2009-04-12 22:44  串口\Ex23_07.suo

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

评论

共有 条评论

相关资源