This question already has answers here:
Power off an USB device in software on Windows
(5 answers)
Closed 9 years ago.
What I want to write is an application that would be able to access my USB port.
To control when to charge my phone and when not to. And perhaps with time I would like to extend the application to control light bulbs, fans and the television in my room.
I want to learn how to work this out rather than just copy some line of codes and paste. I wish for a quick and very simplified tutorial on this, I would be highly grateful (small language please, You all know am still learning :-)).
The exact job I want to achieve is just to make the port send out power when needed. That is it should be switched off and on using codes if possible.
It isn't possible to change the power status of a USB port from User mode code. It's not a .NET limitation, no user application can change the power status of a USB port. Actually, I think that the power state is controlled by the chipset itself and you can't turn it off without using a specialized chipset.
Besides, if your device short-circuited, you could burn your chipset and your motherboard.
The only (safe) solution is to use an external device that will control a relay to turn power on or off for your devices.
There are multiple answers to similar questions, eg Windows- Power off a USB device in Software
A good option is to use an external device like Arduino (or Netduino), .NET Gadgeteer or any number of external boards. Prices and capabilities vary of course.
If you want to build the device yourself, you can find numerous USB relays with a simple Google search
EDIT
Regarding serial ports, there is almost no relation at all between the two port types. Serial ports are not designed to provide power. You can use tricks to use a pin's voltage to power some external device, although this will lead to problems because there is not enough current to power most devices. Burning the chipset is another likely outcome.
A USB port on the other hand, is explicitly designed to provide power through specific wires which can't be controlled normally. This is why you can charge your phone from a desktop's USB port even if the machine has shut down.
EDIT 2: Sleep-and-charge ports
As Ben Voigt noted, not all USB ports allow charging while shutdown.
There are multiple port types that support charging. Charging ports provide more current than plain ports but shut down when the computer is switched off. Sleep-and-charge ports on the other hand can provide power even when the computer is off.
Related
Is it possible to monitor WiFi traffic and send data myself? My goal is to learn how to monitor probe requests, send deauth packets, and other operations similar to AirCrack and the other libraries found on the BackTrack os flavor.
You might have a tough time doing what you want to do in a Windows environment. If you poke around the Aircrack site a bit you'll see that the Windows version is pretty useless in comparison to its Linux counterpart, in large part due to the open source driver availability in Linux and the lack thereof in Windows. You can definitely packet sniff etc. ( http://www.codeproject.com/Articles/12458/SharpPcap-A-Packet-Capture-Framework-for-NET ) but you won't get the robustness that you can get out of a similar application in Linux.
I don't know about sending just random radio signals, but you can certainly monitor the traffic and data. Here is an article which describes how to do it.
AirPcap from Riverbed. USB adapter that can run in monitor mode and has an API for channel switching and more, and you can send Wi-Fi frames if you buy the right adapter. Wireshark has builtin support too. The Alfa cards are a good choice, but only for 'nix
I have used the LPT port before with a VB6 library called inpout32.dll. I'm much more familiar with that but it is not used in modern computers, such as laptops.
I need to control a device with on / off capabilities. This would have been very easy with LPT, but I need to work with USB and C# in this case. There are some USB2LPT cables out there on the market, but I read that they can't be programmed the same way.
Has anyone used those cables before? If yes, how can I work with them. Otherwise what are my alternatives?
Having read up on this question regarding working with USB devices, I got to wondering what method is being used by the operating system to differentiate between types of USB device?
For example, I can plug in a USB mouse and the computer "just knows" it's a mouse. If I plug in my 1GB USB drive it "just knows" it's 1GB's worth of removable storage.
What sort of code is being used by the device to 'announce' what type it is? Or is the operating system polling the device and getting some standardised response?
How would I program a device to identify itself as, say, a keyboard?
In order to build a device that works over USB, you will almost certainly have to read the USB specification available from http://www.usb.org/developers/docs/
In regards to your specific question, there are GET methods associated with various standard USB variables. These are stored in the firmware of the device and provided when requested. Eg, GET_DESCRIPTOR, GET_STATUS etc are request types that can be sent to the device.
USB has its own set of protocols that would be quite a task to implement in their entirety, so most device manufacturers buy a USB controller chip from some third party.
If you're just interested in hacking something together, then I think the specification will be enough to get you sending a few packets.
The only other option I can think of may not be suitable for your project; wire-tap a real keyboard, let the keyboard to all the complicated address resolution and device identification etc, then just have your device push data onto the wires as and when.
This is something I have managed before when I build a keyboard black-box for password sniffing at high-school, the black-box stored keypresses then regurgitated them onto the wires as if it were a keyboard. Once it had stored a few passwords, and I retrieved it, I had to plug it in attached to the keyboard, then unplug the keyboard before setting it to output the keypresses (with a handy gedit window open :P) otherwise the keyboard would interrupt the transmission with its own data.
The type (or rather, the device class) is determined by reading the device's class from the device's device and interface descriptors. You may want to read this segment about USB device descriptors from USB in a Nutshell for information. (I also recommend reading the whole thing, if you're interested)
In Device Manager open the properties of a device and select the Details tab. The various values give the information (or rather is generated from the information from the device and its driver).
I'm interested in creating a wireless network of laptops using Bluetooth developed in C#.
I want to get the list of Bluetooth activated devices in range ( preferable computers, not dongles, headsets or phones). I don't think I need to use a Bluetooth adapter specific stack coz I have seen Windows searching for Bluetooth devices in range. How can I run such a search in my C# app and list the computers in range?
Please help me to do this, also let me know if my effort is wrong. Thank you.
There is a nice C# Bluetooth library available in 32feet.NET.
If you have no need for any of the additional features it offers and you wish to do the P/Invoke on your own, documentation can be found here; specifically the BluetoothFindFirstDevice and BluetoothFindNextDevice for device discovery.
Additionally, you can use windows sockets to do device/service discovery. Information on that can be found here.
If you wish to specifically filter out types of Bluetooth devices, you will want to look at the ulClassOfDevice field in the BluetoothDeviceInfo.
I am working on a personal project involving sending simple signals from my computer to a circuit via USB. Basically I am using the USB signal as the gate signal for a MOSFET which will in turn activate a relay to turn on/off various AC peripherals. For example if I want to turn on a light bulb for 5 seconds every minute I would be sending a 1 down the first wire for the first 5 seconds of every minute.
This is my problem: I have no idea how to manually send a 0/1 down a specific wire on a USB cable, or even interact with a USB port at all :(
So I guess there are multiple parts to this question, is it possible to interact directly with the bits being sent via a USB port? If so how would I do this? I am familiar with C++ and C#, so I really hope that you can do it in one of those...
Thanks!
edit Hmm so it looks like the USB port actually only has one 5V pin so direct USB interaction wont work. Going to take a look at a parallel adapter and get back on it.
USB is a bad fit for anything that doesn't have a USB interface at the other end of the wire. If you don't want to get into building your own USB device, I'd suggest buying a USB to serial adapter, which gives you two directly-controllable output lines (the flow control lines), or a USB to parallel adapter, which gives you more than 8 lines.
Chris Johnson's answer has a link to instructions for Windows serial port programming. You'll want to look at section 7 -- the SETDTR, CLRDTR, SETRTS, and CLRRTS are your flow control line toggles (for the DTR and RTS lines, respectively).
As far as hardware goes, a "1" (SET) value on a flow control line is +3 to +15 volts on the line, and a "0" is -3 to -15. Actual voltages can vary between devices; measure it to be sure. (EDITED; I got the 1 and 0 mixed up. The control lines use the opposite convention from the data lines.)
Here are Wikipedia pages for voltage characteristics and pinouts.
EDIT: Having done some more research on USB-to-parallel adapters, I don't think they will give the needed level of control. For best results, you'll need a PCI or PCMCIA parallel card, or a parallel port built into the motherboard.
I'm not a Windows programmer, but this library might be useful for controlling the parallel port's lines from Windows.
The easiest thing to do for this application is to use serial port emulation, either with a USB-Serial cable, or with a USB-Serial converter chip (e.g. the FTDI FT232) in your hardware device.
Either way, this allows you to interact with your USB device as you would a serial port (see, e.g. here for how to do this in C++ in Windows)
Much like Chris suggested, you can get a USB slave device from FTDI. $27 at digikey will get you a small board with all the fine wiring already done.
However, for your purposes the bit-banging mode described on page 39 of the datasheet would be much better than the UART mode (UARTs generate pulses at several kilohertz, you want to have the voltage stay at the level you set it to).
Hopefully your MOSFET will turn on with a 3V signal since the FTDI will put out approximately 3.1-3.2V for a high output.
Also, make sure you use the latest drivers from FTDI... a couple years ago they had drivers (WHQL-certified even) that caused frequent BSOD, and I've often found that driver CDs that come with hardware are several years out of date.
I built something very similar to what you are doing (I was running a car window motor from a usb device, used a mossfet H bridge (the HDR1X8 on the diagram) to drive the motor.). You need a USB to I/O device this is what I used (I got a U421, they fit perfectly over the center line of a breadboard, the 401 works well with breadboards too if you don't have a split one.
They give you a dll and you just link in to it with your code. its just as simple as making a call to WriteA and WriteB for writing out to your mosfet device. Be warned logic level lines are not meant to drive current so you will need to hook this up to a transistor if you expect any kind of medium to large current flow. See App1 in the application notes of the menu on the usbmicro site to see the proper way to hook it up.
Use a USB prototype board. It usually comes with a software SDK.
Check out these links from my web site:
1.You can use a usb to serial converter. All you need to know is here
2.You can use programming to access the usb directly but for this one you have to have a driver already installed for you device. Details are here