|
@@ -58,6 +58,17 @@ protected:
|
|
|
string _message;
|
|
string _message;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+static string
|
|
|
|
|
+narrow(wchar_t* wide)
|
|
|
|
|
+{
|
|
|
|
|
+ wstring ws(wide);
|
|
|
|
|
+ ostringstream os;
|
|
|
|
|
+ for (size_t i = 0; i < ws.size(); i++) {
|
|
|
|
|
+ os << os.narrow(ws[i], '?');
|
|
|
|
|
+ }
|
|
|
|
|
+ return os.str();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
class HID
|
|
class HID
|
|
|
: public Nan::ObjectWrap
|
|
: public Nan::ObjectWrap
|
|
|
{
|
|
{
|
|
@@ -167,7 +178,10 @@ HID::write(const databuf_t& message)
|
|
|
throw(JSException)
|
|
throw(JSException)
|
|
|
{
|
|
{
|
|
|
if(!_hidHandle) {
|
|
if(!_hidHandle) {
|
|
|
- throw JSException("Cannot write to closed device");
|
|
|
|
|
|
|
+ char buf[1024];
|
|
|
|
|
+ memset(buf, 0, sizeof(buf));
|
|
|
|
|
+ sprintf(buf, "Cannot write to closed device. size:%d", message.size());
|
|
|
|
|
+ throw JSException(buf);
|
|
|
}
|
|
}
|
|
|
//unsigned char buf[message.size()];
|
|
//unsigned char buf[message.size()];
|
|
|
unsigned char* buf = new unsigned char[message.size()];
|
|
unsigned char* buf = new unsigned char[message.size()];
|
|
@@ -179,7 +193,10 @@ HID::write(const databuf_t& message)
|
|
|
res = hid_write(_hidHandle, buf, message.size());
|
|
res = hid_write(_hidHandle, buf, message.size());
|
|
|
delete[] buf;
|
|
delete[] buf;
|
|
|
if (res < 0) {
|
|
if (res < 0) {
|
|
|
- throw JSException("Cannot write to HID device");
|
|
|
|
|
|
|
+ char buf[1024];
|
|
|
|
|
+ memset(buf, 0, sizeof(buf));
|
|
|
|
|
+ sprintf(buf, "Cannot write to HID device.error:%d", GetLastError());
|
|
|
|
|
+ throw JSException(buf);
|
|
|
}
|
|
}
|
|
|
return res; // return actual number of bytes written
|
|
return res; // return actual number of bytes written
|
|
|
}
|
|
}
|
|
@@ -490,17 +507,6 @@ NAN_METHOD(HID::write)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static string
|
|
|
|
|
-narrow(wchar_t* wide)
|
|
|
|
|
-{
|
|
|
|
|
- wstring ws(wide);
|
|
|
|
|
- ostringstream os;
|
|
|
|
|
- for (size_t i = 0; i < ws.size(); i++) {
|
|
|
|
|
- os << os.narrow(ws[i], '?');
|
|
|
|
|
- }
|
|
|
|
|
- return os.str();
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
NAN_METHOD(HID::getDeviceInfo)
|
|
NAN_METHOD(HID::getDeviceInfo)
|
|
|
{
|
|
{
|
|
|
Nan::HandleScope scope;
|
|
Nan::HandleScope scope;
|
|
@@ -561,6 +567,9 @@ NAN_METHOD(HID::devices)
|
|
|
Local<Object> deviceInfo = Nan::New<Object>();
|
|
Local<Object> deviceInfo = Nan::New<Object>();
|
|
|
Nan::Set(deviceInfo, Nan::New<String>("vendorId").ToLocalChecked(), Nan::New<Integer>(dev->vendor_id));
|
|
Nan::Set(deviceInfo, Nan::New<String>("vendorId").ToLocalChecked(), Nan::New<Integer>(dev->vendor_id));
|
|
|
Nan::Set(deviceInfo, Nan::New<String>("productId").ToLocalChecked(), Nan::New<Integer>(dev->product_id));
|
|
Nan::Set(deviceInfo, Nan::New<String>("productId").ToLocalChecked(), Nan::New<Integer>(dev->product_id));
|
|
|
|
|
+ if (dev->hardware_id) {
|
|
|
|
|
+ Nan::Set(deviceInfo, Nan::New<String>("hardwareId").ToLocalChecked(), Nan::New<String>(dev->hardware_id).ToLocalChecked());
|
|
|
|
|
+ }
|
|
|
if (dev->path) {
|
|
if (dev->path) {
|
|
|
Nan::Set(deviceInfo, Nan::New<String>("path").ToLocalChecked(), Nan::New<String>(dev->path).ToLocalChecked());
|
|
Nan::Set(deviceInfo, Nan::New<String>("path").ToLocalChecked(), Nan::New<String>(dev->path).ToLocalChecked());
|
|
|
}
|
|
}
|