I want to figure out how any usb device works. Lets say I have a scanner. When I start scanning there must be some command being given by Windows to device in order to start scanning and transfer data. I want to know how does this work ? and are there any way that I can a list of a USB device's supporting commands ? Also can I execute these commands and take the data directly from PHP ?
USB is a complicated subject, so it will not be possible to teach you everything you need to know in a single StackOverflow answer. There are lots of things to learn about such as control transfers, descriptors, interfaces, and endpoints. You can learn about them by reading the official USB 2.0 specification, or a summary of it. Once you know about that stuff, you can look at the device descriptors using a utility like lsusb
, and that might tell you a lot about what commands the device supports. If the device implements a standard class defined in the USB Specification, then you can read that document to find the list of commands. If not, then you could contact the manufacturer for documentation, or you might need to get a USB protocol analyzer and do some reverse engineering.