需要提前安装Vivado Lab
- 打开控制面板
csharp
/// <summary>
/// 进程初始化,并打开进程
/// </summary>
public static void InitAndStart()
{
process = new Process();
process.StartInfo.FileName = @"cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.BeginOutputReadLine();
process.StandardInput.AutoFlush = true;
process.OutputDataReceived += Process_OutputDataReceived;
process.ErrorDataReceived += Process_ErrorDataReceived;
receives = new List<string>();
Write(@"D:\Xilinx\Vivado_Lab\2019.2\bin\vivado_lab.bat -mode tcl");
}
- 获取所有下载器编号
csharp
/// <summary>
/// 获取所有下载器编号
/// </summary>
/// <returns></returns>
public static string[] GetAllDownLoadNames()
{
InitAndStart();
Thread.Sleep(100);
Write("open_hw_manager");//打开硬件管理器
Thread.Sleep(100);
if (!ConnecServer())
{
return null;
}
Thread.Sleep(500);
Write("puts stdout [get_hw_targets]");//获取所有下载器资源号
Thread.Sleep(200);
CloseProcess();
return receives[receives.Count - 1].Split(' ');
}
- 连接硬件服务器
csharp
/// <summary>
/// 连接硬件服务器
/// </summary>
/// <returns></returns>
private static bool ConnecServer()
{
Write("puts stdout [connect_hw_server -allow_non_jtag]");
Stopwatch sw = new Stopwatch();
sw.Start();
while (true)
{
if (receives.Count > 0 && receives[receives.Count - 1] == "localhost:3121")
return true;
if (sw.ElapsedMilliseconds > 6000)
return false;
Thread.Sleep(500);
}
}
- 烧录
csharp
/// <summary>
/// 逻辑烧录
/// </summary>
/// <param name="downLoaderNum">下载器编号</param>
/// <param name="filePath">文件地址</param>
/// <returns></returns>
public static bool DownLoad(string downLoaderNum, string filePath)
{
InitAndStart();
Write("open_hw_manager");
Thread.Sleep(500);
if (!ConnecServer())
{
return false;
}
Write($"open_hw_target {downLoaderNum}");
Thread.Sleep(500);
Write("set_property PROGRAM.FILE {" + filePath + "} [get_hw_device]");
Thread.Sleep(500);
Write("program_hw_device [get_hw_device]");
Thread.Sleep(5000);
CloseProcess();
return receives[receives.Count - 1].EndsWith("HIGH");
}