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");
        }
相关推荐
我不会编程55515 小时前
Python Cookbook-5.1 对字典排序
开发语言·数据结构·python
李少兄15 小时前
Unirest:优雅的Java HTTP客户端库
java·开发语言·http
“抚琴”的人15 小时前
【机械视觉】C#+VisionPro联合编程———【六、visionPro连接工业相机设备】
c#·工业相机·visionpro·机械视觉
无名之逆15 小时前
Rust 开发提效神器:lombok-macros 宏库
服务器·开发语言·前端·数据库·后端·python·rust
似水এ᭄往昔15 小时前
【C语言】文件操作
c语言·开发语言
啊喜拔牙15 小时前
1. hadoop 集群的常用命令
java·大数据·开发语言·python·scala
北京太速科技股份有限公司16 小时前
太速科技-FMC144 -八路 250MSPS 14bit AD FMC子卡
fpga开发
xixixin_16 小时前
为什么 js 对象中引用本地图片需要写 require 或 import
开发语言·前端·javascript
W_chuanqi16 小时前
安装 Microsoft Visual C++ Build Tools
开发语言·c++·microsoft
anlogic16 小时前
Java基础 4.3
java·开发语言