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");
        }
相关推荐
湫ccc3 分钟前
《Python基础》之基本数据类型
开发语言·python
Matlab精灵4 分钟前
Matlab函数中的隐马尔可夫模型
开发语言·matlab·统计学习
Microsoft Word5 分钟前
c++基础语法
开发语言·c++·算法
数据小爬虫@7 分钟前
如何利用java爬虫获得淘宝商品评论
java·开发语言·爬虫
qq_1728055915 分钟前
RUST学习教程-安装教程
开发语言·学习·rust·安装
wjs202422 分钟前
MongoDB 更新集合名
开发语言
monkey_meng26 分钟前
【遵守孤儿规则的External trait pattern】
开发语言·后端·rust
legend_jz1 小时前
【Linux】线程控制
linux·服务器·开发语言·c++·笔记·学习·学习方法
tangliang_cn1 小时前
java入门 自定义springboot starter
java·开发语言·spring boot
程序猿阿伟1 小时前
《智能指针频繁创建销毁:程序性能的“隐形杀手”》
java·开发语言·前端