thingsnsuch / Node-USB-Temp-Sensor

3 stars 0 forks source link

cant claim the device from windows #1

Open algaly opened 8 years ago

algaly commented 8 years ago

I've tried to use the same code with my vendorid and productid my product is an HID Device (HID-compliant vendor-defined device) i think i need the buffers to be configured the right way for me. any idea ?

i am getting this error

C:\Users\algaly\Documents\node-udemy-1\usbread\appp.js:81 interface.claim(); ^

TypeError: Cannot read property 'claim' of undefined at Object. (C:\Users\algaly\Documents\node-udemy-1\usbread\appp.j s:81:10) at Module._compile (module.js:435:26) at Object.Module._extensions..js (module.js:442:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:311:12) at Function.Module.runMain (module.js:467:10) at startup (node.js:136:18) at node.js:963:3

thingsnsuch commented 8 years ago

Hey, sorry no I don't have any idea at the moment, to be honest I haven't even thought about this project in ages, it was a little proof of concept test that I had nearly forgotten about. I had just started using nodejs as well so I had no idea what I was doing ;-)

A fair amount of my code is probably specific to the usb temperature sensor I used, which I realize now I did not link to in the readme so I don't know if you are trying to use the same device or not. I did a quick google and couldn't locate the specific one I happened to order, but I can look around and link it later if I can find it. Can you link to the device you are trying to use?

Aside from that, I do recall that I had to use the Zadig program to find the device (while plugged in) and replace the default windows driver with the winusb one. Without doing that, I could not use the device from node. I go through the process I think in more detail here: https://lukeisadog.wordpress.com/2014/04/19/reverse-engineering-a-client-usb-driver-with-nodejs/ Unfortunately I haven't been keeping up with the blog basically at all, but I would trust it more than my memory at this point.

Since my code was super sloppy and just a proof of concept, I would strip it down to as simple as possible. First, just make sure you can find the device and comment out everything but the code necessary to do that. Afterwards, add back in the line to try to open the device, if it can be found. Any of the actual transfers to the device would be dependent on the device, and if you don't have the exact same one it may blow up.

Best of luck, and let me know if I can offer any more assistance.

thingsnsuch commented 8 years ago

Oh, by the way, how exactly did you run the script? Did you clone the repo or just save the js file and try and run it? You would need at least the js file and the package.json, and you would need to run an npm install command inside the directory to install the usb module (the other 2 modules used are built into node). I didn't think to ask that stuff in my prior comment, but I want to make sure you are getting started correctly.

algaly commented 8 years ago

Hi :+1: First ,Thanks for the swift and detailed answer! I did managed to get the device list and open the device i want. thing is i cant or probably dont know how to do it the right way to read the device continually. i'll be more then glad to talk to you on skype(avi.algaly) or hangouts (algaly@gmail.com) by the way the device i am using i categorized as HID(human input device). let me know please. Avi. Thanks

thingsnsuch commented 8 years ago

Hey, glad you are getting somewhere.

I would spend some time reading up on the USB protocol and learning how it works overall, if you have not already done that.

After you have a solid feeling for interfaces, descriptors, endpoints etc, you can move on. You can use a usb monitor application like usblyzer (I think I had the trial, one of the ones I used, maybe that one, I was able to extend the trial by uninstalling and removing the install folder). You need to know what interfaces, descriptors and endpoints are on the device to read/write to the correct ones. Honestly I don't remember them super well myself since its been a while and I haven't had any refreshers in the last 1.5 years or so.

The way that I figured my device out (which I think I detailed some in the blog post), was to take an application that already communicated with the device and spied on it using usblyzer to see how another application communicates with the device. In my case, there was a control transfer that I never exactly understood that was necessary to begin communication, then I was able to do a bulk read to get the temperature data. I still had to figure out how to convert the temperature data from what I got out but once I was able to figure out what interfaces, descriptors and endpoints to use and what control transfers to get things started, it was pretty straightforward. It did take a decent bit of detective work though.

If you have this option, you will have to go back and forth between the default (maybe windows) driver and the winusb driver though because in my case, the software that came with the device required the default windows driver to work, after replacing it using Zadig with the winusb driver, the software wouldn't work anymore so thats a little bit of a pain.

Good luck!

algaly commented 8 years ago

Thanks! I'll continue update you on that.

algaly commented 8 years ago

Hi, can you please send me your device descriptor ? I am kind of lost with what i send to function device.controlTransfer(0x80, 0x05, 0x40, 0x03, 0x40, function (err, dat) {}); what parameters do i send to my device in the three time calling this function according to device descriptor. Thanks Avi.

thingsnsuch commented 8 years ago

Hey, I will try to get my device out this weekend if I can find it and give you more detailed info.

Tell me this first though, what device exactly (ideally a link to amazon or something) are you working with, and do you have any program already that can communicate with the device already that you could possibly spy on to reverse engineer the device?

I never got to a point where I 100% understood every series of bytes that got sent to the temp sensor, but I spied on the communications enough and tinkered enough to where I was able to extract what I wanted, but for a more complex device that might be tough (and there is a chance I got lucky in figuring mine out too).

I'll be happy to try and help out, but without actually having the device myself it might be impossible, but I'll try to refresh myself on all the USB terminology over the weekend.

algaly commented 8 years ago

Hi, I'll be very glad to expose every single thing in a private session. its not military secret :)

i am available on hangouts : algaly@gmail,com skype : avi.algaly

or just give me your phone and i'll call you. appreciate your help!

Avi.

thingsnsuch commented 8 years ago

I'm not sure if I'll have time to have a 1 on 1 session, but feel free to email me at lrice648@gmail.com and I'll see what I can do. I'm having a hard time finding my usb device unfortunately since I haven't worked with it in quite a while but hopefully if you can give me more info on your scenario I can provide some direction.