c# - .Net 中是否有任何用于 XModem 的第三方库可以帮助更新固件?
问题描述
我最近开发了一个.Net Console app
可以与 sas Expander 卡通信的。
问题来了。
我想使用我的控制台应用程序更新卡中的固件。
我已经知道它可以通过Xmodem
协议更新
并且可以通过使用成功ExtraPuTTy
。
发送 fwdl
命令后ExtraPuTTy
:
发送y
命令后ExtraPuTTy
:
选择File Transfer
和send
转账完成后,卡会重启并给出响应bp1>
SAS 卡已连接到RS232
端口。
固件文件的扩展名为.FW
.
我在.Net
代码中尝试的内容:
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Windows.Forms;
using System.Text;
using System.IO;
namespace ConsoleApp3
{
class Program
{
[STAThread]
static void Main()
{
string[] ports = SerialPort.GetPortNames();
string com = "";
Console.WriteLine("The following serial ports were found:");
foreach (string port in ports)
{
Console.WriteLine(port);
Console.WriteLine("Please choose which port name you want ?");
com = Console.ReadLine();
}
SerialPort mySerialPort = new SerialPort(com);
mySerialPort.BaudRate = 115200;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.RtsEnable = true;
mySerialPort.DtrEnable = true;
mySerialPort.ReadTimeout = 500000;
mySerialPort.WriteTimeout = 1500;
mySerialPort.NewLine = "\r";
mySerialPort.Open();
if (mySerialPort.IsOpen)
{
mySerialPort.Write("\r");
}
List<string> Commands = new List<string>();
string command = "";
int counter = 0;
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
while (true)
{
ConsoleKeyInfo consoleInput = Console.ReadKey();
if (consoleInput.KeyChar == '\r')
{
Commands.Add(command);
counter = Commands.Count - 1;
mySerialPort.Write(command + "\r");
if (command == "fwdl")
{
ClearCurrentConsoleLine();
}
if (command == "y")
{
String FileName = "";
OpenFileDialog openfile1 = new OpenFileDialog();
if (openfile1.ShowDialog() == DialogResult.OK)
{
FileName = openfile1.FileName;
}
}
ClearCurrentConsoleLine();
command = "";
}
else if (consoleInput.Key == ConsoleKey.UpArrow)
{
if ((counter >= 0) && (counter < Commands.Count))
{
ClearCurrentConsoleLine();
Console.Write(Commands[counter]);
foreach (string obj in Commands)
{
command = obj;
}
if (consoleInput.KeyChar == '\r')
{
Commands.Add(command);
counter = Commands.Count - 1;
mySerialPort.Write(command + "\r");
ClearCurrentConsoleLine();
command = "";
}
}
if (counter > 0)
{
counter--;
}
else
{
counter = Commands.Count - 1;
}
}
else
{
command += consoleInput.KeyChar.ToString();
}
}
}
private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting(); // it might be better to use --> string indata = sp.ReadLine();
Console.Write(indata);
}
private static void ClearCurrentConsoleLine()
{
int currentLineCursor = Console.CursorTop;
Console.SetCursorPosition(6, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth));
Console.SetCursorPosition(6, currentLineCursor);
}
}
}
我只找到固件文件并将固件文件的名称存储在变量中。
我尝试XModem c#
在 Github 中搜索。
我发现的是https://github.com/yang-chanhong/XModem。
我不确定该代码是否可以在我的控制台应用程序中使用。
.Net 中是否有任何用于 XModem 的第三方库可以帮助更新固件?
我的控制台应用程序正在使用.Net Framework 4.7.2
.
..................................................... ...........
更新1:
在我的应用程序中添加app1.config
文件后
并复制XmodeProtocol中的配置,
我输入using XModemProtocol;
了Program.cs
.
错误出现了:
看起来XmodeProtocol 的配置不够清晰,无法实现。
我错过了XmodeProtocol的东西README.md
吗?
..................................................... ……
更新 2:
我在XmodeProtocol上下载了源代码
并单击add reference
。
选择Project
选择并按下Browse
按钮。
我没有看到组件文件。
下一步我应该怎么做才能添加项目作为参考?
解决方案
推荐阅读
- ada - 在 Spark 中证明 Floor_Log2
- python - 根据同一列中的连续重复值合并特定行
- html - 溢出剪辑,其余内容可见
- ios - 如何访问 AppStore Connect 中的“协议、税务和银行业务”?
- post - 用于获取访问令牌的 ADFS 身份验证代码
- mysql - 使用 perl cgi 更新 db 行
- rust - 有没有办法关闭`tokio::runtime::current_thread::Runtime`?
- ios - Apple Watch 简单的“模块化大型”并发症不会显示在自定义屏幕中,除非我也启用所有其他并发症
- git - 为 Azure Devops 中托管的 git 存储库指定部署密钥
- firefox - sqlite 选择请求不获取 moz_place