2

I'm writing a Data Aquisition application but instead of having a traditional boring front end I've been tasked to put a Web 2.0 front end on it, I heard the Node.js was good at calling C++ code, but since I got to the stage where I should be thinking about linking my DLL to my frontend I've hit a brick wall.

I'm aware I could write the code natively without using an add on such as node-ffi, but to be frank the syntax for performing these bindings with Google's V8 syntax seemed fairly complex, therefore I'm guessing ffi is the easiest way to handle this.

I know a pre question has been asked before and has an answer here but I am still a little shaky on how to write the shim to allow me to call my C++ dll from node.

I have the following C++ header:

#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;
} 

I assume that I dont need to supply the implementation details of my .cpp file, but what I want to know is how can I make these methods visible to node.js and how can I wrap them in node-ffi?

I am also concerned that I may have problems linking this dll to the front end as my .dll has a dependency on the NIDAQmx .dll, will this cause problems further down the pipe line?

Community
  • 1
  • 1
Halfpint
  • 3,967
  • 9
  • 50
  • 92

0 Answers0