2

我正在编写一个 Data Aquisition 应用程序,但我没有使用传统无聊的前端,而是将 Web 2.0 前端放在上面,我听说 Node.js 擅长调用 C++ 代码,但自从我开始我应该考虑将我的 DLL 链接到我的前端的阶段我已经碰壁了。

我知道我可以在不使用诸如 node-ffi 之类的附加组件的情况下本地编写代码,但坦率地说,使用 Google 的 V8 语法执行这些绑定的语法似乎相当复杂,因此我猜 ffi 是最简单的方法处理这个(事情。

我知道之前已经问过一个前置问题,并且在这里有一个答案,但我仍然对如何编写 shim 以允许我从节点调用我的 C++ dll 感到有点不安。

我有以下 C++ 标头:

#include "NIDAQmx.h"
#include <string>
using std::string;
namespace DAQReaderDll
{
    class DAQReader
    {
        private:
            int32      m_read;
            int32      m_error;
            TaskHandle m_handle;
            bool       m_isRunning;
            char       m_errBuff[2048];

        public:
            __declspec(dllexport) DAQReader();
            __declspec(dllexport) ~DAQReader();
            __declspec(dllexport) void startDevice();
            __declspec(dllexport) void stopDevice();
            __declspec(dllexport) float32 getSample();
            __declspec(dllexport) bool    isRunning();
            __declspec(dllexport) string  getError();

    };

    // Used inside the DLL
    int SAMPLE_SIZE = 1000;
    int READ_SPEED  = 1000;
    int AS_PSI      = 2980;
} 

我假设我不需要提供 .cpp 文件的实现细节,但我想知道的是如何使这些方法对 node.js 可见以及如何将它们包装在 node-ffi 中?

我还担心将这个 dll 链接到前端可能会遇到问题,因为我的 .dll 依赖于 NIDAQmx .dll,这是否会导致问题进一步下线?

4

0 回答 0