c# - 如何从 C# 访问 .h 文件信息

标签 c# c parsing header-files

当使用 NI 工具创建 FPGA 位文件时,LabView 会生成一个 C .h 文件,其中包含用于与 FPGA 应用程序通信的信息,例如签名(常量)和寄存器地址(作为枚举)。

挑战在于我的应用程序是用 C# 编写的,我需要访问这些寄存器地址。

我能想到的唯一选择是:

  1. 将 .h 文件的内容剪切并粘贴到 .cs 文件中 ~~~~ ...让我不寒而栗,C# 是一个开发人员,FPGA 是另一个开发人员。
  2. 解析 .h 文件 ~~~~ ... 也让我不寒而栗 - 编写我自己的语言解析器:(

必须有更好的方法!!!

示例.h:

 /*
 * Generated with the FPGA Interface C API Generator 12.0.0
 * for NI-RIO 12.0.0 or later.
 */

#ifndef __NiFpga_M_OTRM_OVDFPGA_h__
#define __NiFpga_M_OTRM_OVDFPGA_h__

#ifndef NiFpga_Version
   #define NiFpga_Version 1200
#endif

#include "NiFpga.h"

/**
 * The filename of the FPGA bitfile.
 *
 * This is a #define to allow for string literal concatenation. For example:
 *
 *    static const char* const Bitfile = "C:\\" NiFpga_M_OTRM_OVDFPGA_Bitfile;
 */
#define NiFpga_M_OTRM_OVDFPGA_Bitfile "NiFpga_M_OTRM_OVDFPGA.lvbitx"

/**
 * The signature of the FPGA bitfile.
 */
static const char* const NiFpga_M_OTRM_OVDFPGA_Signature = "D0751ADE3A0EC976606D63C425B35E85";

typedef enum
{
   NiFpga_M_OTRM_OVDFPGA_IndicatorBool_FallingEdge = 0x8132,
   NiFpga_M_OTRM_OVDFPGA_IndicatorBool_StopSignal = 0x813A,
} NiFpga_M_OTRM_OVDFPGA_IndicatorBool;

....

#endif

最佳答案

鉴于它可能只是您需要解析的一小部分内容,事实上,它不需要解析,但可能只需要进行一些文本操作/搜索替换。应该不会太难。此外,您还可以使用 C++.NET 将这些内容包装到可在 C# 中使用的 API 中。

您可能还想看看“SWIG”之类的东西

http://www.swig.org/

关于c# - 如何从 C# 访问 .h 文件信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21294733/

相关文章:

c# - 从 C# 中的一行中删除子字符串 "dynamically"

c# - 在 Bouncy CaSTLe 中使用正确的加密服务提供商更新 x509Certificate2

c++ - 如何在 char* 中存储整数和字符的串联?

c - 为什么 GDB 在行之间不可预测地跳转并将变量打印为 "<value optimized out>"?

python - 使用 Python 拆分字符串时遇到问题

c# - AI在垂直井字棋c#中发挥不佳

将 char 复制到 char 数组

c - 在 C 中解析字节流(嵌入式编程)

php - PHP解析/语法错误;以及如何解决它们

c# - 在 T4 模板中使用 .NET Core 程序集