3 Star 6 Fork 3

卖菇凉小蘑菇/Ymodem-IAP

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Form1.cs 3.46 KB
一键复制 编辑 原始数据 按行查看 历史
桂慧 提交于 2017-11-03 18:01 . 第二次提交源代码
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 Ymodem;
namespace IAP
{
public partial class mainForm : Form
{
public mainForm()
{
InitializeComponent();
}
private void mainForm_Load(object sender, EventArgs e)
{
foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
{
this.SerialPortComboBox.Items.Add(s);
this.SerialPortComboBox.Text = this.SerialPortComboBox.Items[0].ToString();
}
}
private void selectFileButton_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
if (button.Text == "选择程序")
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
this.pathTextBox.Text = openFileDialog.FileName.ToString();
}
}
}
private void downloadButton_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
if (button.Text == "开始下载")
{
button.Text = "正在下载";
ymodem = new Ymodem.Ymodem();
ymodem.Path = pathTextBox.Text.ToString();
ymodem.PortName = SerialPortComboBox.SelectedItem.ToString();
ymodem.BaudRate = Convert.ToInt32(BaudRateComboBox.SelectedItem.ToString());
downloadThread = new System.Threading.Thread(ymodem.YmodemUploadFile);
ymodem.NowDownloadProgressEvent += new EventHandler(NowDownloadProgressEvent);
ymodem.DownloadResultEvent += new EventHandler(DownloadFinishEvent);
downloadThread.Start();
}
}
#region 下载进度委托及事件响应
private delegate void NowDownloadProgress(int nowValue);
private void NowDownloadProgressEvent(object sender, EventArgs e)
{
int value = Convert.ToInt32(sender);
NowDownloadProgress count = new NowDownloadProgress(UploadFileProgress);
this.Invoke(count, value);
}
private void UploadFileProgress(int count)
{
DownloadProgressBar.Value = count;
}
#endregion
#region 下载完成委托及事件响应
private delegate void DownloadFinish(bool finish);
private void DownloadFinishEvent(object sender, EventArgs e)
{
bool finish = (Boolean)sender;
DownloadFinish status = new DownloadFinish(UploadFileResult);
this.Invoke(status,finish);
}
private void UploadFileResult(bool result)
{
if (result == true)
{
MessageBox.Show("下载成功");
this.downloadButton.Text = "开始下载";
this.DownloadProgressBar.Value = 0;
}
else
{
MessageBox.Show("下载失败");
this.downloadButton.Text = "开始下载";
this.DownloadProgressBar.Value = 0;
}
}
#endregion
private void DownloadProgressBar_Click(object sender, EventArgs e)
{
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/qq1847123212/Ymodem-IAP.git
git@gitee.com:qq1847123212/Ymodem-IAP.git
qq1847123212
Ymodem-IAP
Ymodem-IAP
master

搜索帮助