-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows node-hid apps don't exit if device.on('data', ...)
event handler and device doesn't send data
#358
Comments
To remove Electron as a potential issue, can you create a Node.js program that connects to your device in the same way? |
I will do that, will take a couple minutes to set up though... Also some more details, by chance I tried removing a |
// Helper to synchronize the hid reads
function sync_hid_read(handle) {
return new Promise((resolve, reject) => {
handle.on("data", (data) => {
return resolve(data);
});
handle.on("error", (e) => {
return reject(e);
});
});
} I think I may have found the issue... I tried to write a sync helper for I think I have some misunderstanding on how promises work since I don't grasp why this doesn't work correctly... will try to figure it out and update here. |
so even with a more simple read the node process doesn't end... any clues? basically console.log("test"); will run and print but let handle = new hid.HID(device.path);
handle.write(header);
// Wait for device to respond
let done = false;
handle.on("data", (data) => {
console.log(data);
done = true;
});
handle.on("error", (e) => {
console.log(e);
done = true;
});
while (!done) { await sleep(50);}
console.log("done");
handle.close(); will print the data variable, followed by |
My bad, this is not the case, had messed something up prior in testing which gave this issue, above issue still a mystery. |
That code does not work stand-alone as you need to put I made some assumptions about the actual Node.js program you've created and made this gist: test-teensyrawhid-await.js The dependencies are On MacOS 10.14.6 and Windows 10 Pro 1903, this program successfully exits. I do notice on Windows it takes about an extra second for it to exit. (I'm suspecting all Windows HID close() issues as now being related to a long-standing issue with hidapi that hopefully will be fixed soon thanks to libusb/hidapi#133 being raised. Or it could be that Windows just takes about a second to teardown the HID subsystem for a closed device) |
Also does this mean you're not longer getting the error code this issue is titled with and instead the issue is that the process isn't exiting? |
@todbot sorry here is a more complete example code for me - this still fails to return in my case: let sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
let example = async () => {
// Needs to be implemented to return a device from hid.devices()
let device = get_device();
if(device) {
update_label(true, `Reading ${device.product}'s settings`);
// custom header for my specific device which triggers the device to write
// data
let header = [0x00, 0x01];
let handle = new hid.HID(device.path);
handle.write(header);
// Wait for device to respond
let done = false;
handle.on("data", (data) => {
console.log(data);
done = true;
});
handle.on("error", (e) => {
console.log(e);
done = true;
});
while (!done) {
await sleep(50);
}
console.log("done");
handle.close();
}
}
example(); output:
and waits forever after I haven't been able to recreate the crash scenario so potentially it's an electron issue, the electron app does a lot more with node-hid so I don't think this example encompasses the entire complexity of the usage but it does encompass what ends up triggering the issue... any tips on getting more information out of electron? |
So regarding the initial issue of the crash, for whatever reason it seems by replace my frankenstein's monster edition of I believe there must be some kind of issue with Thank you. |
Hi, At this point I'm not sure what the issue is you're seeing. |
so if you comment out the |
device.on('data', ...)
event handler and device doesn't send data
Hi @Newbrict,
Then the application will not exit because of a blocking If you have the ability to try |
You are correct my device sends data once. I will try to figure out how to load node-hid from github rather than npm and update here. |
Thanks for the confirmation. In
then remove |
I tried that, but it seems the hidapi submodule isn't pulled?
|
Hmm right, hidapi is a submodule now. Not sure the nodejs way to do this but if you |
two issues: seems and
any tips? |
No clue. I don't use yarn. |
Hi @todbot - Do we still plan on publishing a new 1.2.0 release soon? |
Hello @todbot |
For now you should remove your device listeners before exiting. |
At first the issue was that the App Would not close, but then I found out that I don't call The Issue I am Facing is currently is wired. This Happens only if the Device is not streaming data to the PC, Also even if I request data from the device in the window close event of electron before app exits (to get a last response from the device). I tried removing the Event listeners separately, no fix. I issue now is that Electron is trying to close the main Thread, But there is an AsyncWorker for the read Event that is running, this Worker gets interrupted buy the The Problem somehow lies here. I am totally speculating but when I Add and Empty I will make a minimum Sample code to reproduce the bug for you. but after the weekend. and I will open a separate issue. |
@Lan-Hekary Hi I just meet same problem on version 2.1.2
The app will quit after 1000ms. No crash any more. |
Hi
I am have a piece of hardware which disconnects itself from usb (without physical d/c) approximately at the same time that I do
handle.close()
I am getting this error randomly about every 1/5th runs. I tried to google this issue but I only find non electron apps talking about heap corruption, unsure if it's related.Environment:
Please provide some guidance on how to test this issue, I am having trouble reproducing it consistently
The text was updated successfully, but these errors were encountered: