How to use .NET framework to toggle the power on a USB-powered dev

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

We have a C#.NET win-forms application that talks to a device plugged into
the USB port. Sometimes when severe communications interruptions occur, such
as from a burst of ESD electricity, we need to toggle the power on that
device in order to bring it back to life.

We can do this by unplugging the usb cable from the PC, obviously, but our
program needs to recover without manual intervention.

Can anyone tell me how to toggle the power off, then back on, to a
particular USB port, programmatically? If I can do this via the .NET
framework, that would be best, but if I have to I can call win32 api calls...

This is critical as it is needed to pass an agency certification test, and
is delaying a product launch. Any help is much appreciated!

thanks!
Robb
 
Hi Robb,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to turn off a certain usb
device and turn it back on. If there is any misunderstanding, please feel
free to let me know.

As far as I know, 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. So you have to 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 the following sites for more information.

http://www.usb.org/
http://www.microsoft.com/hwdev/bus/USB/
http://www.lvr.com/usb.htm
http://www.beyondlogic.org

In Windows, you can use Win32_USBController to power off a certain device.
For more information, please check the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/
win32_usbcontroller.asp

Besides posting here, you can also post in microsoft.public.ddk. There are
more professionals in that group to help you with this issue. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Kevin,

We do have a driver we are using, which is from Texas Instruments. My
question is how do I use the .NET framework to access that driver and tell it
to reset itself? The Win32 serial API seems to have some of the correct
commands in it (thanks) but I'm not sure how to use them to tell a specific
device on a specific COM port to reset. I know the COM port #, and I know
the name of the driver..how do I say "reset yourself"? Even if I could reset
that port it would accomplish what I need.

Basically I am trying to do one of two things:

1. Ideally, tell windows to stop sending power to a certain port. This
will cause the USB device on that port to see the power loss and reset itself.

2. If that is not possible, another idea is to just "reset" the port in
question. If ai Can do that, it might interupt the flow of USB traffic to
the device long enough for the device to detect it, and reset itself.

Can you tell me if either of these is possible via the .NET framework?

thanks
Robb
 
Hi Robb,

As far as I know, we cannot power off a certain USB port. However, we can
tell a certain USB device to reset itself if the device's driver supports
this operation. Based on my research, there is a Reset method in
CIM_USBDevice class that can request a reset of the logical device. You can
check the following link for more information.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/
cim_usbdevice.asp

Since I'm not quite familiar with WMI, I suggest you post in
microsoft.public.win32.programmer.wmi newsgroup. It is a managed newsgroup.

If this can be done with WMI, the method can be called via .NET framework
through System.Management namespace. Here is an example of how to perform
this using .NET.

http://www.codeproject.com/csharp/PrntJobControllerUsingWMI.asp

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top