[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

How to read input from USB device?

Darwin S

12/18/2002 7:07:00 PM

I have been asked to write a small demo program that is to
interact with a device that plugs into a USB port. I have
never done this before so I started looking for
information on how to do this in the .NET sdk
documentation but could not even find a reference to USB.
Can anybody give me pointer on what classes I should be
using or give some hints on how to get started? The
device sends x,y and z coordinates.

Thank you,
Darwin
5 Answers

NETMaster

12/18/2002 8:20:00 PM

0

My USB Port FAQ:

USB is a hardware bus and as such not directly exposed
to user-mode (Win32) applications (or even .NET).
Only Windows device-drivers do control the USB.
=> get a driver from manufacturer.

So if you connect a printer with USB, use the Win32/.NET printer-API.
Or if you connect a modem with USB, use the Win32 serial-API.
Or if you connect an imaging device (camera/scanner), use TWAIN/WIA.

If you want to design your own external, USB compliant hardware,
you have to understand the USB bus protocol
and implement a controller chip.
Then on Windows side, you have to write your own
device driver with the Windows DDK.
Sure there are OEM kits making all this easier.

Please visit sites like:
http://ww...
http://www.microsoft.com/hwde...
http://www.lvr.c...
http://www.beyon...
and learn the technology.


In theory, you could use Win32
CreateFile( ..., "\\.\usbdevXYZ", ...)
to open a logical USB device (only if it is designed to be
accessible this way) and then communicate with
ReadFile WriteFile
or control with
DeviceIoControl.
...but you have to get the specifications from the vendor
for the correct data block formats / commands to use.


QUESTION:
Now, which kind of device do you want to access?



--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_d... - http://dnetm...


Darwin S

12/18/2002 8:34:00 PM

0

Thank you. I was thinking that would be the case. The
device is a touch pad similar to those found on some
laptop computers. The company asking me to write the demo
provided me with the hardward and a CD. I installed the
CD and there were several .dll files installed with it.
However, Visual Studio does not recognize any of them as
being valid COM or COM+ objects so I am unable to add
references to any of these .dlls. Perhaps there is
another way to use .dlls that I am not familiar with?

Thanks,
Darwin

>-----Original Message-----
>My USB Port FAQ:
>
> USB is a hardware bus and as such not directly exposed
> to user-mode (Win32) applications (or even .NET).
> Only Windows device-drivers do control the USB.
> => get a driver from manufacturer.
>
> So if you connect a printer with USB, use the
Win32/.NET printer-API.
> Or if you connect a modem with USB, use the Win32
serial-API.
> Or if you connect an imaging device (camera/scanner),
use TWAIN/WIA.
>
> If you want to design your own external, USB
compliant hardware,
> you have to understand the USB bus protocol
> and implement a controller chip.
> Then on Windows side, you have to write your own
> device driver with the Windows DDK.
> Sure there are OEM kits making all this easier.
>
> Please visit sites like:
> http://ww...
> http://www.microsoft.com/hwde...
> http://www.lvr.c...
> http://www.beyon...
> and learn the technology.
>
>
>In theory, you could use Win32
> CreateFile( ..., "\\.\usbdevXYZ", ...)
>to open a logical USB device (only if it is designed to be
>accessible this way) and then communicate with
> ReadFile WriteFile
>or control with
> DeviceIoControl.
>....but you have to get the specifications from the vendor
>for the correct data block formats / commands to use.
>
>
>QUESTION:
> Now, which kind of device do you want to access?
>
>
>
>--
> Thomas Scheidegger - MVP .NET - 'NETMaster'
> http://www.cetus-links.org/oo_d... -
http://dnetm...
>
>
>.
>

NETMaster

12/18/2002 9:35:00 PM

0

If you plugged-in this USB touch-pad, did Windows
recognize the device and you could install a driver?
So you can actually work (e.g. move mouse-pointer) with the pad?

If no, why?
a device-driver has to be installed,
and if Windows doesn't see the device,
you will never have a chance with .NET anyway....

If yes, then why do you have to develop software for this?
Any special features of the pad? Academic research?


As .NET doesn't provide any specific device support,
I recommend to first search a classic Win32 solution,
maybe there are C++ samples on this CD-ROM?


Or for this kind of mouse-like devices,
maybe the DirectX: DirectInput API/components
could provide some more specific control:
http://msdn.microsoft.com/archive/en-us/dx8_c/directx_cpp/input_ovunderstandin...
and there will be ?soon? a wrapper for .NET.


> Perhaps there is another way to use .dlls that I am not familiar with?

.NET PInvoke, but you have to get the headers .H
and documentation for the DLL-API anyway.




--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_d... - http://dnetm...


Darwin S

12/18/2002 10:03:00 PM

0

Thank you again.

>If you plugged-in this USB touch-pad, did Windows
>recognize the device ...?

Yes, windows recognized the device. The device was
immediately usable as a mouse pointing device without the
need to install any drivers.

> If yes, then why do you have to develop software for
this?

The software I need to write will define zones on the pad
where each zone will have a specific type of function.
Some zone will act like buttons, other zones will act like
sliders and some zone will not respond to the touch. In
other words, it will not be used as a mouse pointing
device.

>..NET PInvoke, but you have to get the headers .H
>and documentation for the DLL-API anyway.

I do have a .H file but no documentation. I guess I need
to contact the company.

Thank you,
Darwin

NETMaster

12/18/2002 11:53:00 PM

0

> The software I need to write will define zones on the pad
> where each zone will have a specific type of function.
> Some zone will act like buttons, other zones will act like
> sliders and some zone will not respond to the touch. In
> other words, it will not be used as a mouse pointing
> device.

I see. Very interesting task!

Will this zones be recognized only by your own application,
or should this zones interact with other apps, Windows-desktop,
or even system-wide?

I guess doing this for your own .NET app should be possible.
But I'm not so sure for a system-wide solution built with .NET.



> I do have a .H file but no documentation. I guess I need
> to contact the company.

Once you see a possible solution with C++/Win32 or vendor DLL,
please post again and we will help you to port it to .NET.


--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_d... - http://dnetm...