资源简介

串口文件传输,包含了CRC校验,可以和设备之间采用应答方式传输文件,文件是bin文件,可自己修改,整个传输的进度有进度条,一个文件分成多个包传输,如果传输错误,可以自动将当前包再发一次。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 串口下载
{
    public partial class Form1 : Form
    {
        SerialPort myport = new SerialPort();
        string filename = null;
        static byte[] download = new byte[11] { 0x5A0xA50x0B0x050x000x000x000x000x000x000x00};

        byte mcu_ack = 0;
        bool UartSendStart = false;
        byte[] Mcu_Rev_Data = new byte[2048];
        bool str_link_sta = true;

        uint crc16_ccitt(byte[] tmp int num)
        {
            uint CrcTmp = 0x0;
            int i = 0 j = 0;
            uint s = 0;
            uint tmpcrc = 0;
            uint temp = 0;
            for (i = 0; i < num; i++)
            {
                temp = tmp[i];
                tmpcrc = temp << 8;
                tmpcrc &= 0xff00;
                CrcTmp ^= tmpcrc;     /*高8位异或*/
                for (j = 0; j < 8; j++)
                {
                    s = CrcTmp & 0x8000;
                    CrcTmp <<= 1;
                    CrcTmp &= ~((uint)0x0001);
                    if (s == 0x8000)
                    {
                        CrcTmp ^= 0x1021;
                    }
                }
            }
            return CrcTmp;
        }
        public Form1()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
            myport.DataReceived += Port_DataReceived;

            string[] ports = SerialPort.GetPortNames();//获取当前计算机的串行端口名称数组  ports = {COM1COM2.....}
            if (ports == null || ports.Length <= 0)
            {
                comboBox_port.Items.Add(“无端口“);
            }
            else
            {
                comboBox_port.Items.AddRange(ports);
                comboBox_port.SelectedIndex = 0;
            }

            cBxbaud.Items.AddRange(new object[]{
            “1200““2400““4800““9600““19200““38400““115200“
            });

            cBxbaud.SelectedIndex = 6;
            progressBar1.Maximum = 100;
            progressBar1.Value = 0;

            //textBox1.Enabled = false;
            button1.Enabled = true;
            button2.Enabled = true;
            button3.Enabled = true;
            button4.Enabled = true;
            button5.Enabled = true;
            button6.Enabled = true;
            //textBox2.Text = “bin串口协议:“ + “AA 08 E6 87 32 C9 1A 55“;
        }
        public void openPort(SerialPort SP)
        {
            try
            {
                SP.PortName = comboBox_port.Text;
                SP.BaudRate = Convert.ToInt32(cBxbaud.Text);
                SP.Parity = Parity.None;
                SP.StopBits = StopBits.One;
                SP.DataBits = 8;
            

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

    ..A..H.     38912  2020-05-29 11:12  SerialDown\.vs\串口下载\v16\.suo

     文件          0  2020-04-24 10:57  SerialDown\.vs\串口下载\v16\Server\sqlite3\db.lock

     文件     602112  2020-05-29 11:12  SerialDown\.vs\串口下载\v16\Server\sqlite3\storage.ide

     文件        189  2020-04-24 10:57  SerialDown\App.config

     文件      20480  2020-05-29 11:12  SerialDown\bin\Debug\串口下载.exe

     文件        189  2020-04-24 10:57  SerialDown\bin\Debug\串口下载.exe.config

     文件      46592  2020-05-29 11:12  SerialDown\bin\Debug\串口下载.pdb

     文件      15727  2020-05-29 11:11  SerialDown\Form1.cs

     文件      19868  2020-04-24 15:23  SerialDown\Form1.Designer.cs

     文件       5817  2020-04-24 15:23  SerialDown\Form1.resx

     文件       1435  2020-04-24 15:51  SerialDown\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7140  2020-04-24 10:57  SerialDown\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1375  2020-05-29 11:12  SerialDown\obj\Debug\串口下载.csproj.FileListAbsolute.txt

     文件       1012  2020-04-24 15:23  SerialDown\obj\Debug\串口下载.csproj.GenerateResource.cache

     文件        424  2020-05-29 11:12  SerialDown\obj\Debug\串口下载.csprojAssemblyReference.cache

     文件      20480  2020-05-29 11:12  SerialDown\obj\Debug\串口下载.exe

     文件        180  2020-04-24 15:23  SerialDown\obj\Debug\串口下载.Form1.resources

     文件      46592  2020-05-29 11:12  SerialDown\obj\Debug\串口下载.pdb

     文件        180  2020-04-24 10:59  SerialDown\obj\Debug\串口下载.Properties.Resources.resources

     文件        524  2020-04-24 10:57  SerialDown\Program.cs

     文件       1330  2020-04-24 10:57  SerialDown\Properties\AssemblyInfo.cs

     文件       2837  2020-04-24 10:57  SerialDown\Properties\Resources.Designer.cs

     文件       5612  2020-04-24 10:57  SerialDown\Properties\Resources.resx

     文件       1099  2020-04-24 10:57  SerialDown\Properties\Settings.Designer.cs

     文件        249  2020-04-24 10:57  SerialDown\Properties\Settings.settings

     文件       3612  2020-04-24 10:59  SerialDown\串口下载.csproj

     文件       1129  2020-04-24 10:57  SerialDown\串口下载.sln

     目录          0  2020-05-29 11:12  SerialDown\.vs\串口下载\v16\Server\sqlite3

     目录          0  2020-04-24 10:57  SerialDown\.vs\串口下载\v16\Server

     目录          0  2020-04-24 10:57  SerialDown\.vs\串口下载\v16

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

评论

共有 条评论