Windows Embedded USB Client options - embedded

I am a very novice embedded developer and I am trying to develop a commercial product using Windows Embedded Compact and a Toradex Apalis T30 COM. Firstly just excuse me here, I am not a professional nor a trained engineer, merely a hobbyist trying to push the boundaries so forgive me if this is supposed to be trivial. I should also state that because of this I have no low level USB experience. I would like to use WEC 2013 but Toradex does not quite have it ready yet so for I guess at least another month I am stuck on WEC 7 if that makes any difference.
My problem is that I cannot seem to figure how one goes implementing USB Client functionality in WEC. As in, I want my device to be able to connect to my PC as a USB client with the PC being the host. Now by default it connects with the Active Sync (now Device Center or something) application and that allows serial communication of sorts if I am not mistaken but I really don't want to make my device dependent on ActiveSync as that will leave a very bad impression on customers as it doesn't look very professional and bears to much of an association with yesteryear's Windows Mobile.
My device is a 3D printer and I am assuming that there is no native USB class for 3D printers. All 3D printers I know of merely use a USB COM port to communicate and I guess that that should be fine for me two. Now what I want to know is how I can make my device appear as a plug and play USB COM port (able to support all the major desktop operating systems)? I know I can use an FTDI chip to do this with a UART port on my device but I am thinking that that is a bit of a waste given the fact that my COM has a built-in USB client port.
One would think that WEC would have built-in support for something like this but I cannot find any documentation regarding how to use it if it does indeed exist. The best I can find is http://msdn.microsoft.com/en-us/library/ee481935.aspx but the page does not really say anything useful.
PS. I cannot really afford to buy a USB vendor-id so I am hoping there is a solution to this that does not require one.

For windows embedded, you have to manually write a driver or a set of registry entries with the right Device Class ID, Vendor ID and Product ID. Once that is done, you need to integrate it in Windows Embedded and rebuild the solution.

Related

Limit usb power output

I work with an embedded device that has a USB host port. I would like to connect an iPhone to it and communicate via USB. I have done development on this and ported the functionality to connect to usbmux on the iPhone and have successful communication, however there is another problem.
All development was done with the iPhone connected to a powered USB hub that was connected to my device, as soon as I connected it directly, after enumeration it starts to drain the battery of my embedded device and causes a tension (voltage) drop that causes my device to turn off.
I know that after enumeration usb devices can draw up to 500 mA from the usb port, but I was wondering if there was a way to limit that to 100 mA (while still having the iPhone registered).
I found various questions regarding controlling voltage on the data pins or vcc from the usb port and I understand that's not possible, I'm looking for a software solution (although hardware solutions are welcome).
tl;dr: Is there a way to supply the iPhone with less than 500 mA after enumeration? Could I do this in software? Or do I need a hardware solution? I don't want to turn the port on/off, just limit the power draw of the iPhone.
NOTE: I am using Windows CE 6.0, if it is something that can only be done by modifying the drivers, or having direct access, there is no problem.
P.S. also, if there is a way to do this in *nix (or some other open source OS) that I could look at the source code and port it to Windows CE please let me know.
When a device shares its available configurations (see USB chapter 9), it specifies how much power it requires for each configuration. The host should look at all the available configurations and choose which one it wants.
In practice, however, these things don't work so smoothly.
The last time I looked at this, Windows always chose the first configuration. MacOS always chose the lowest power configuration (or highest, I can't remember). I never looked at WinCE or Linux.
If you're writing/modifying the driver, you can set your own rules for which configuration to choose, including looking for one that's 'self powered'. The iPhone, however, might only have one descriptor that always requests 500mA, bus powered. If so, then you're pretty much screwed since there's no way to let the iPhone know it's not OK to draw power.
That being said, I believe all the iPhone accessories are actually USB host (as opposed to USB device), and given that they don't always supply power, the iPhone must be capable of enumerating self powered.
I like the answer by Russ Schultz but I want to add another one:
No.
The descriptor of the peripheral device, iPhone in this case contains bMaxPower. If you enumerate this device, you also accept the power demand. It is not possible to only supply less, lets say 300 mA, if you already enumerated the device with the 500 mA desriptor. If this is what you wanted.
If the device provides multiple configurations, you are as mentioned by Russ free to write a driver which selects the configuration with less power. Hopefully, the device will then only consume the granted power.
Many peripheral devices just don't care. Most devices only provide one configuration with 500 mA. And there are a lot of devices which just consume more than they say ...

C++ Issue creating a mouse simulator

I have been given the following project to do:
create a program that runs on computer 1. The program will simulate mouse movements and pass that information through a usb cable from computer 1 to computer 2. Computer 2 must believe the information being passed to it is coming from a mouse-device.
Basically computer 2 has to believe that a mouse is connected to its usb-port, when actually it is another computer (computer 1), and computer 1 basically simulates mouse movements. Which movements the computer simulates doesn't really matter because that would probably be the easy bit, the harder bit is actually making the software that makes that possible.
QUESTION: Is there any program that currently does that? If so please tell me which one it is. If there isn't any program you know of, how would I go about making it myself?
PS: I would assume that this project is theoretically possible. I mean the computer 1 would just have to send signals to computer 2 that are similar to the normal signals sent to a computer by an ordinary mouse.
The ability to act as a USB host as well as a client (keyboard, mouse, etc.) is not typically part of the USB chipset in PCs. The ability to serve either role requires something unique like USB OTG; which you can find in some mobile phones.
So no, this is generally not possible with two random PCs and a USB cable. In any case, you can find a discussion on this here:
Emulate USB Device with USB Host
The thread mentions that you could make a proxying device with active electronics in it to sit between two host-only devices and be capable of translating to appear as a client to one. But with just a plain old USB cable you can't.
Since you're so specific about wanting it to be done with USB and no need to install special software you are probably not interested in something like Synergy:
https://en.wikipedia.org/wiki/Synergy_(software)
...but someone else finding this question might be.

USB programming

I want to program a microcontroller (AVR) to control some leds through USB. It's just out of interest in how to build and program USB devices.
There are some AVR microcontrollers that support the USB protocol or I could implement the USB protocol in an another microcontroller myself, but I wonder what to use to write your own drivers on the computer.
My level in system programming: total noob (hence the question)
So what is the literature you people would advice to get good knowledge of the USB technology and how to write your own drivers and beyond?
P.S.: I know:
C (probably will need it here)
Java (probably won't need it here)
Python (hope can use it here)
assembler (hopefully won't need it here XD).
...
P.P.S: driver development differs for different OS's. I use Linux and Windows, so any material related to one or both of these systems is welcome.
Well, although you can develop and write your own USB driver, the beauty of USB is that you don't need to write your own driver. the USB Implementers Forum has defined class specifications for all the standard device classes. If you can make your device fit into a standard device class the driver has already been written for you!
If you truly want to become familiar with USB development, you should start by reviewing the USB approved class specification documents.
If you are into framework for AVR microcontrollers with hardware USB then take a look into LUFA, and if you are into AVRs with software USB then look into V-USB. They have both implemented many USB classes so you don't have to do it on your own - just use them.
That sounds like a great project! I'd suggest starting off with something a little simpler since you're - as you say - a "total n00b". I'm not sure what hardware you currently have (or have in mind) but what I would suggest for the total beginner is the STK500. It's a development board that's very well supported in both Linux and Windows and will give you the most flexibility. It comes with LEDs and switches built in for your projects, but you will need to get a microcontroller. And for that I recommend the ATMega32, a great multi-purpose IC that's also well supported and has lots of documentation on the web.
Once you get those I suggest you do your development on Linux using avr-gcc (make sure to also install avr-libc). If you're using Ubuntu it's easy to get all the packages you need:
% sudo apt-get install gcc-avr avr-libc avrdude
Those should get you up and running. I'd suggest Googling around for help writing your first programs but another good resource is the online materials for this class at Cornell.
That's enough to get your feet wet with AVR microcontrollers and the development tools. The sky is the limit at that point but since you said you want to get into USB I'd suggest using the excellent V-USB framework to have your ATMega32 act as a USB device. After that, as they say, the steps to flipping LEDs are a piece of cake :).
I wonder what to use to write your own
drivers on the computer
libusb (here, here and here)
wdk
WinDriver
For libusb variants info read this
You could us libusb. It's powerful and cross-platform.
But what you're trying to do is a rather simple control interface. You can sidestep most of the complexity by using HIDAPI, I think.
http://www.signal11.us/oss/hidapi/
HID devices often use generic drivers that come packaged into the OS. That way you don't actually have to write any drivers ever, you just make your device compliant with the generic driver and tailor the client software to it.
I think this is what's usually done in the hobbyist electronics field, which is what you're interested in here.
HIDAPI is even recommended for simple communications with HID devices in the libusb FAQ since its a bit more complicated to do it across platforms using libusb.
One good way to go is just to develop a HID device, since the driver is built in to most higher level OSes and pretty flexible for simple IO like you are talking about. Another good option is just using a USB RS232 device or software. I use PICs which have a number of nice devices with USB onboard.
I had built my own test bed based on the ARDUINO UNO and i was using the ionlabs programmer of type usbasp and it worked perfectly fine but it did not allow to convert the TTL back to Rs-232 and hence i couldn't use the features such as serial.print() and i had to install the ftdi cable which allowed me to do this.
The drivers were the libusb 1.xx working just fine.
If you want to program the AVR you can use the ARDUINO software bundle or the stino to upload the programs.
You need to know c(only basics).
I created a USB-keyboard adapter last year for my capstone. I did not do the host programming but used existing code that you can find on the web.But I did program the device side and for that I got a lot of help from this website Teensy Look into their "Code Library" which has code for Keyboard, Mouse and others. Also, the USB protocol handbook will always be useful and you should always consult it when you are doing stuff with USB.
I wonder whether your AVB acts as a host or device. I guess your board is a usb device and you need to light the leds on your board. So, it may be a good way to initialize your board as a HID device. To achieve this goal, you need a HID gadget software stack running on your board. References as follows:
gadget framework in uboot
HID specefication usb org
debug tools such as USB Protocol Analyzer
libusb running on Host PC to send packets
The Microsoft documentation area of the WDK (Windows Development Kit) is recently available on MSDN. There is a section on USB, though you would be best to read the earlier sections first, in particular the "Getting Started" areas. They assume you'll be using C as the programming language for driver development.
WDK Site
WDK - USB Section
For Linux, the Linux USB website should be able to point you in the right direction. In particular you'll want the Programming Guide for Linux USB Device Drivers.

Reading info from printer on USB port

In the days of parallel printers one used to be able to send a command on LPT1 and receive back standard info such as life count etc.
Now, with USB devices, have we lost that capability? Or is there still a way to read the info?
I assume your question is Windows centric. On some devices the manufacturer (like Epson and Star for example) provide utilities that let you access the device as a 'legacy serial' interface. It's still USB but the software gives you a virtual serial port you can talk to it with. I've been doing some digging trying to figure out what features are exposed by the low level drivers, but haven't had much luck there as Windows drivers really aren't my forte.
In the windows printers you get to select from a variety of ports. For parallel and serial you can open them as \.\LPT1 or \.\COM1 etc and get bi-directional behaviour that way. But for USB the ports are often USB001, and trying to open \.\USB001 for example doesn't seem to work. Such an approach might work, if you can figure out exactly what name to open. But that name will probably have a big ugly GUID in it if the information you see in winobj is anything to go by...
If you come up with any better answers please let me know!

How can I do bi-directional communication with a custom USB device?

I'm planning to build a USB device that has buttons that some software needs to respond to, and indicators that the software needs to control. I'm new to USB, so I'm looking for any pointers that will get me started.
When I did some USB development a while ago, I found the information at USB Central extremely valuable.
For low bandwidth requirements, you can use something like the FT232R which is a single-chip USB serial implementation. The FTDI drivers are readily available and make the device appear as a regular serial port to the host computer. This is orders of magnitude easier than rolling your own USB implementation (for either end!).
Kinda vague, but in the past I've done a little bit of USB development. The easiest stuff tends to be HID related device as the subset of USB used to commincate is very to implement on both sides. There are hardware devices which are essentially stubbed out to work with HID, you just customize some circuity and go.
The USB standard is actually quite readable. Though it might be a bit overkill if you just want to create a simple device. You could probably get something like this, which is basically an 8051 controller with a USB connector together with firmware and a DLL.
Checkout WinDriver, which is a commercial multiplatform tool what give you easy way to implement usb drivers in user mode, source code compatible between Linux and Windows.