C#实现FPGA自动烧录(Vivado)

需要提前安装Vivado Lab

  1. 打开控制面板
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");
     }
  1. 获取所有下载器编号
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(' ');
        }
  1. 连接硬件服务器
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);
       }
   }
  1. 烧录
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");
        }
相关推荐
·云扬·11 分钟前
【Java源码阅读系列37】深度解读Java BufferedReader 源码
java·开发语言
liulilittle42 分钟前
C++ i386/AMD64平台汇编指令对齐长度获取实现
c语言·开发语言·汇编·c++
Thomas_YXQ1 小时前
Unity URP法线贴图实现教程
开发语言·unity·性能优化·游戏引擎·unity3d·贴图·单一职责原则
Zz_waiting.1 小时前
Javaweb - 10.4 ServletConfig 和 ServletContext
java·开发语言·前端·servlet·servletconfig·servletcontext·域对象
Touper.2 小时前
JavaSE -- 泛型详细介绍
java·开发语言·算法
sun0077002 小时前
std::forward作用
开发语言·c++·算法
一名用户2 小时前
unity实现梦日记式传送组件
后端·c#·unity3d
Zhen (Evan) Wang3 小时前
(豆包)xgb.XGBRegressor 如何进行参数调优
开发语言·python
虾球xz3 小时前
CppCon 2018 学习:THE MOST VALUABLE VALUES
开发语言·c++·学习
阿蒙Amon4 小时前
C#扩展方法全解析:给现有类型插上翅膀的魔法
开发语言·c#