How to program computer to communicate with External USB Device

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
Hi there,

I am not getting a clear idea about how to program Computer to control USB devices such as camera, printer, and mouse. Take one example like I have one camera and I have connected it to the computer and I want to control a camera via Computer. How to program the computer to control camera

I understand I have to write a program for computer to control camera. A program can written in any language like c++, java and C#.

I’m not clear idea How to program computer to communicate with External USB Device
 

danadak

Joined Mar 10, 2018
4,057
USB is not a simple protocol.

A faster more straight forward way would be to use an embedded processor with
USB library, and interface that to PC via UART. An example -

http://www.cypress.com/documentatio...d-psoc-5lp-introduction-implementing-usb-data

http://www.cypress.com/documentatio...oc-5lp-usb-general-data-transfer-standard-hid


Or find out what chip in PC is USB interface and see if that manufacturer has
an API library. Downside is solution that is specific to that PC version and its chipset.


Regards, Dana.
 
Last edited:

Papabravo

Joined Feb 24, 2006
22,058
The USB specifications are available for downloading. The interface can be bit-banged, but as has been noted it is not a straightforward process. Not the least of the problems on a Windows machine is that the windows registry gets corrupted and requires cleanup whenever the initial negotiation (enumeration) process fails. It is a really big PITA.

https://www.usb.org/documents?search=&tid_2[0]=40&items_per_page=50

Without some hardware assist on your processor of choice or a USB peripheral chip you're going to have to do some heavy lifting. I also recommend a USB Protocol Analyzer if you're going to attempt this project.
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
USB is not a simple protocol.

A faster more straight forward way would be to use an embedded processor with
USB library, and interface that to PC via UART. An example -

http://www.cypress.com/documentatio...d-psoc-5lp-introduction-implementing-usb-data

http://www.cypress.com/documentatio...oc-5lp-usb-general-data-transfer-standard-hid


Or find out what chip in PC is USB interface and see if that manufacturer has
an API library. Downside is solution that is specific to that PC version and its chipset.


Regards, Dana.

Not to mention writing a driver for a PC. ;)
 

wayneh

Joined Sep 9, 2010
18,088
I’m not clear idea How to program computer to communicate with External USB Device
Don’t expect clarity, you’ll never achieve that. But you can get a good idea of how it’s done by looking over the open source code that’s available for printer drivers, camera drivers and so on. Don’t reinvent those wheels, just tweak them to your needs.
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
I think my question was wrong. My question should be “How do we create device driver for new device on windows system”?

Manufactures of devices such as camera, printer provide their own device driver

If any device is connected to computer. It will work only if the device has device driver. Device driver is program that will run on computer to control device. We write program to transfer or receive information from device

If we want to develop device driver then we need tool like visual studio and we can write C# .NET program to make new device
 

Georacer

Joined Nov 25, 2009
5,182
I have never written a true device driver for an operating system, but I know that it's not trivial.
I have done it in low-level microcontrollers, implementing datasheets essentially, but that's not the same thing.

I have also heard that Linux supposedly has a better device hardware abstraction layer than Windows.
Perhaps starting there would be more educational?

https://www.amazon.com/Linux-Device-Drivers-Jonathan-Corbet/dp/0596005903
 

wayneh

Joined Sep 9, 2010
18,088
I think my question was wrong. My question should be “How do we create device driver for new device on windows system”?

Manufactures of devices such as camera, printer provide their own device driver

If any device is connected to computer. It will work only if the device has device driver. Device driver is program that will run on computer to control device. We write program to transfer or receive information from device

If we want to develop device driver then we need tool like visual studio and we can write C# .NET program to make new device
Did you see my post #9? Open source drivers are widely available and sometimes superior to those from the manufacturer. You can freely read the code. You’ll get a lot farther much faster by taking advantage of all that work that has been done before you.
 

MrSoftware

Joined Oct 29, 2013
2,273
If you want to write your own driver, you have some homework to do. Start with the Microsoft Windows Driver Kit (WDK). Note that if your device follows some standards, then there may already be a Microsoft driver that will work with it, saving you a ton of time and effort. Or you might be able to start with one of these example drivers and mold it to fit your needs.

If you want your driver to be used in public, it will need to be signed, by you and by Microsoft. Else your users will have to jump through hoops to make it work. It has been a few years since I certified a driver so the details may have changed, but in general you need to setup a test machine and use the Microsoft HCK (Hardware Certification Kit) to run a series of tests on your driver. You sign your driver before testing, then submit your signed driver and your test results together to Microsoft. If the tests passed then Microsoft will sign your driver and now it is ready for public use. Start reading here for more info. If you change your driver (bug fix, etc..) then you have to repeat all of this to certify the new driver. I don't know what they call it now, but you will be able to login to your Microsoft account and see all of the reported crashes for your driver and some data about what was happening when it crashed. That will help you fix bugs once your driver is public.
 
Top