当使用 NI 工具创建 FPGA 位文件时,LabView 会生成一个 C .h 文件,其中包含用于与 FPGA 应用程序通信的信息,例如签名(常量)和寄存器地址(作为枚举)。
挑战在于我的应用程序是用 C# 编写的,我需要访问这些寄存器地址。
我能想到的唯一选择是:
- 将 .h 文件的内容剪切并粘贴到 .cs 文件中 ~~~~ ...让我不寒而栗,C# 是一个开发人员,FPGA 是另一个开发人员。
- 解析 .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”之类的东西
关于c# - 如何从 C# 访问 .h 文件信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21294733/