基本信息
源码名称:基于com串口的文件发送和接收
源码大小:0.84M
文件格式:.zip
开发语言:C#
更新时间:2020-07-29
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 1 元 
   源码介绍

基于com串口的文件发送和接收




            try
            {
                FileStream s = File.Open(fi.FullName, FileMode.Open);
                byte[] file_buf = new byte[fi.Length];
                int read_count = 0, per_count = 0;
                read_count = s.Read(file_buf, 0, file_buf.Length);
                string file_buf_full = Encoding.GetEncoding("gb2312").GetString(file_buf, 0, file_buf.Length);
                if (read_count > 0)
                {
                    string ctl_command = "";
                    ctl_command = ctl_command "<comstart>" fi.Directory.Name "_" DateTime.Now.ToString("yyyyMMddHHmmss") "_" fi.Name "</comstart>";
                    //开始发送命令标识
                    this.WriteLineSerialPort(serialPort1, ctl_command);
                    System.Threading.Thread.Sleep(50);
                    //send file
                    string file_buf_str = "";
                    while (file_buf_full.Length > 0)
                    {
                        if (file_buf_full.Length > this.filebuf)
                        {
                            file_buf_str = file_buf_full.Substring(0, this.filebuf);
                            this.WriteLineSerialPort(serialPort1, file_buf_str);
                            file_buf_full = file_buf_full.Substring(this.filebuf);
                        }
                        else
                        {
                            file_buf_str = file_buf_full;
                            this.WriteLineSerialPort(serialPort1, file_buf_str);
                            file_buf_full = "";
                        }
                        System.Threading.Thread.Sleep(50);
                    }
                    System.Threading.Thread.Sleep(50);
                    //send end
                    ctl_command = "<comend></comend>";
                    this.WriteLineSerialPort(serialPort1, ctl_command);
                    this.ResponseWrite(fi.Name "发送成功!");
                    s.Close();
                    s.Dispose();
                }
            }
            catch (Exception ex)
            {
                this.ResponseWrite(ex.ToString());
            }