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");
        }
相关推荐
k09337 分钟前
sourceTree回滚版本到某次提交
开发语言·前端·javascript
神奇夜光杯15 分钟前
Python酷库之旅-第三方库Pandas(202)
开发语言·人工智能·python·excel·pandas·标准库及第三方库·学习与成长
Themberfue17 分钟前
Java多线程详解⑤(全程干货!!!)线程安全问题 || 锁 || synchronized
java·开发语言·线程·多线程·synchronized·
plmm烟酒僧19 分钟前
Windows下QT调用MinGW编译的OpenCV
开发语言·windows·qt·opencv
测试界的酸菜鱼30 分钟前
Python 大数据展示屏实例
大数据·开发语言·python
晨曦_子画40 分钟前
编程语言之战:AI 之后的 Kotlin 与 Java
android·java·开发语言·人工智能·kotlin
Black_Friend1 小时前
关于在VS中使用Qt不同版本报错的问题
开发语言·qt
希言JY1 小时前
C字符串 | 字符串处理函数 | 使用 | 原理 | 实现
c语言·开发语言
残月只会敲键盘1 小时前
php代码审计--常见函数整理
开发语言·php