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");
        }
相关推荐
皓木.几秒前
Mybatis-Plus
java·开发语言
不良人天码星几秒前
lombok插件不生效
java·开发语言·intellij-idea
源码哥_博纳软云23 分钟前
JAVA同城服务场馆门店预约系统支持H5小程序APP源码
java·开发语言·微信小程序·小程序·微信公众平台
学会沉淀。30 分钟前
Docker学习
java·开发语言·学习
西猫雷婶1 小时前
python学opencv|读取图像(二十一)使用cv2.circle()绘制圆形进阶
开发语言·python·opencv
kiiila1 小时前
【Qt】对象树(生命周期管理)和字符集(cout打印乱码问题)
开发语言·qt
周湘zx1 小时前
项目三:信号源的FPGA实现
fpga开发
小_太_阳1 小时前
Scala_【2】变量和数据类型
开发语言·后端·scala·intellij-idea
直裾2 小时前
scala借阅图书保存记录(三)
开发语言·后端·scala
唐 城2 小时前
curl 放弃对 Hyper Rust HTTP 后端的支持
开发语言·http·rust