代码拉取完成,页面将自动刷新
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)
{
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。