// cnc_resetconnect.cc
#include <node.h>
#include <node_buffer.h>
#include <iostream>
#include <windows.h>
namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
using v8::Number;
using v8::Uint32;
using v8::Integer;
using v8::Exception;
using v8::Array;
/* allocate library handle 3 */
//FWLIBAPI short WINAPI cnc_allclibhndl3(const char *, unsigned short, long, unsigned short *);
void Cnc_allclibhndl3(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
// Check the number of arguments passed.
if (args.Length() != 4 ) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
HINSTANCE hDLL;
hDLL=LoadLibrary("Fwlib32.dll");//加载动态链接库Fwlib32.dll文件;
if (!hDLL) {
// Throw an Error that is passed back to JavaScript
DWORD dRe = GetLastError();
char sz[4];
sprintf(sz, "cat not get lib, error is %d", dRe);
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, sz)));
return;
}
typedef short(WINAPI *pMax)(const char *, unsigned short, long, unsigned short *);//函数指针
pMax pCnc_resetconnect=NULL;
pCnc_resetconnect=(pMax)GetProcAddress(hDLL,"cnc_allclibhndl3");
if ( !pCnc_resetconnect ) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "can not get function: cnc_allclibhndl3 from Fwlib32.dll.")));
return;
}
String::Utf8Value utf(args[0]->ToString());
char* bufferdata = *utf;
int a = args[1]->Uint32Value();
int b = args[2]->Uint32Value();
int c = args[3]->Uint32Value();
// char buf[256];
// sprintf(buf, "%s : %d : %d : %d", bufferdata, a, b, c);
// MessageBox(NULL, buf, "", MB_OK);
unsigned short iThr = c;
short value = pCnc_resetconnect(bufferdata, a, b, &iThr);
Local<Integer> num = Uint32::New(isolate, value);
Local<Integer> handle = Uint32::New(isolate, iThr);
Local<Object> obj = Object::New(isolate);
obj->Set(String::NewFromUtf8(isolate, "re"), num);
obj->Set(String::NewFromUtf8(isolate, "handle"), handle);
args.GetReturnValue().Set(obj);
}
/* reset all socket connection */
//FWLIBAPI short WINAPI cnc_resetconnect(unsigned short);
void Cnc_resetconnect(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
// Check the number of arguments passed.
if (args.Length() != 1) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
HINSTANCE hDLL;
hDLL = LoadLibrary("Fwlib32.dll");//加载动态链接库Fwlib32.dll文件;
if (!hDLL) {
// Throw an Error that is passed back to JavaScript
DWORD dRe = GetLastError();
char sz[4];
sprintf(sz, "cat not get lib, error is %d", dRe);
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, sz)));
return;
}
typedef short(WINAPI *pMax)( unsigned short );//函数指针
pMax pCnc_resetconnect = NULL;
pCnc_resetconnect = (pMax)GetProcAddress(hDLL, "cnc_resetconnect");
if (!pCnc_resetconnect) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "can not get function: cnc_resetconnect from Fwlib32.dll.")));
return;
}
unsigned short a = args[0]->Uint32Value();
short value = pCnc_resetconnect(a);
Local<Integer> num = Uint32::New(isolate, value);
// Set the return value (using the passed in
// FunctionCallbackInfo<Value>&)
args.GetReturnValue().Set(num);
}
#define MAX_AXIS 48
typedef struct odbaxis {
short dummy; /* dummy */
short type; /* axis number */
long data[MAX_AXIS]; /* data value */
} ODBAXIS;
char* GetOdbaxis(short value, ODBAXIS dta, Isolate* isolate, Local<Object>& obj)
{
Local<Integer> num = Uint32::New(isolate, value);
Local<Integer> dummy = Uint32::New(isolate, dta.dummy);
Local<Integer> type = Uint32::New(isolate, dta.type);
Local<Array> arr = Array::New(isolate, MAX_AXIS );
for (int i = 0; i < MAX_AXIS; ++i)
{
arr->Set(i, Number::New(isolate, dta.data[i]) );
}
obj->Set(String::NewFromUtf8(isolate, "re"), num);
obj->Set(String::NewFromUtf8(isolate, "dummy"), dummy);
obj->Set(String::NewFromUtf8(isolate, "type"), type);
obj->Set(String::NewFromUtf8(isolate, "data"), arr);
return NULL;
}
/* read machine axis position */
//FWLIBAPI short WINAPI cnc_machine(unsigned
#include <node.h>
#include <node_buffer.h>
#include <iostream>
#include <windows.h>
namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
using v8::Number;
using v8::Uint32;
using v8::Integer;
using v8::Exception;
using v8::Array;
/* allocate library handle 3 */
//FWLIBAPI short WINAPI cnc_allclibhndl3(const char *, unsigned short, long, unsigned short *);
void Cnc_allclibhndl3(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
// Check the number of arguments passed.
if (args.Length() != 4 ) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
HINSTANCE hDLL;
hDLL=LoadLibrary("Fwlib32.dll");//加载动态链接库Fwlib32.dll文件;
if (!hDLL) {
// Throw an Error that is passed back to JavaScript
DWORD dRe = GetLastError();
char sz[4];
sprintf(sz, "cat not get lib, error is %d", dRe);
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, sz)));
return;
}
typedef short(WINAPI *pMax)(const char *, unsigned short, long, unsigned short *);//函数指针
pMax pCnc_resetconnect=NULL;
pCnc_resetconnect=(pMax)GetProcAddress(hDLL,"cnc_allclibhndl3");
if ( !pCnc_resetconnect ) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "can not get function: cnc_allclibhndl3 from Fwlib32.dll.")));
return;
}
String::Utf8Value utf(args[0]->ToString());
char* bufferdata = *utf;
int a = args[1]->Uint32Value();
int b = args[2]->Uint32Value();
int c = args[3]->Uint32Value();
// char buf[256];
// sprintf(buf, "%s : %d : %d : %d", bufferdata, a, b, c);
// MessageBox(NULL, buf, "", MB_OK);
unsigned short iThr = c;
short value = pCnc_resetconnect(bufferdata, a, b, &iThr);
Local<Integer> num = Uint32::New(isolate, value);
Local<Integer> handle = Uint32::New(isolate, iThr);
Local<Object> obj = Object::New(isolate);
obj->Set(String::NewFromUtf8(isolate, "re"), num);
obj->Set(String::NewFromUtf8(isolate, "handle"), handle);
args.GetReturnValue().Set(obj);
}
/* reset all socket connection */
//FWLIBAPI short WINAPI cnc_resetconnect(unsigned short);
void Cnc_resetconnect(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
// Check the number of arguments passed.
if (args.Length() != 1) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
HINSTANCE hDLL;
hDLL = LoadLibrary("Fwlib32.dll");//加载动态链接库Fwlib32.dll文件;
if (!hDLL) {
// Throw an Error that is passed back to JavaScript
DWORD dRe = GetLastError();
char sz[4];
sprintf(sz, "cat not get lib, error is %d", dRe);
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, sz)));
return;
}
typedef short(WINAPI *pMax)( unsigned short );//函数指针
pMax pCnc_resetconnect = NULL;
pCnc_resetconnect = (pMax)GetProcAddress(hDLL, "cnc_resetconnect");
if (!pCnc_resetconnect) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate, "can not get function: cnc_resetconnect from Fwlib32.dll.")));
return;
}
unsigned short a = args[0]->Uint32Value();
short value = pCnc_resetconnect(a);
Local<Integer> num = Uint32::New(isolate, value);
// Set the return value (using the passed in
// FunctionCallbackInfo<Value>&)
args.GetReturnValue().Set(num);
}
#define MAX_AXIS 48
typedef struct odbaxis {
short dummy; /* dummy */
short type; /* axis number */
long data[MAX_AXIS]; /* data value */
} ODBAXIS;
char* GetOdbaxis(short value, ODBAXIS dta, Isolate* isolate, Local<Object>& obj)
{
Local<Integer> num = Uint32::New(isolate, value);
Local<Integer> dummy = Uint32::New(isolate, dta.dummy);
Local<Integer> type = Uint32::New(isolate, dta.type);
Local<Array> arr = Array::New(isolate, MAX_AXIS );
for (int i = 0; i < MAX_AXIS; ++i)
{
arr->Set(i, Number::New(isolate, dta.data[i]) );
}
obj->Set(String::NewFromUtf8(isolate, "re"), num);
obj->Set(String::NewFromUtf8(isolate, "dummy"), dummy);
obj->Set(String::NewFromUtf8(isolate, "type"), type);
obj->Set(String::NewFromUtf8(isolate, "data"), arr);
return NULL;
}
/* read machine axis position */
//FWLIBAPI short WINAPI cnc_machine(unsigned