Having a USB tête-à-tête with your embedded device
Even in the days of the Internet of Things sometimes you still need to access and control your embedded device from a local connection. Maybe you don't want to do some critical configuration or data exchange over the network for security reasons, or you need a special maintenance interface for your device. In this article, I will share some thoughts of how you could talk to your embedded device over USB.
Before starting, let me quickly clarify some terminology: In the article I will talk about USB "host" and "client”. The "host" is your computer which is connected to the embedded device and the "client" is your embedded device itself. Furthermore, I also talk about options using Windows CE only. Linux provides similar possibilities as well.
The prebuilt Toradex Windows CE Images all come with a bunch of USB connection options built in:
- Mass storage device: The USB client acts like a USB flash drive.
- RNDIS Device: The USB Client acts like a network adapter.
- Serial Device: The USB Client acts as virtual CoM port.
The Mass storage driver has its strengths if you only need to transfer files from or to your embedded device. You are quite limited in controlling the whole process, as users see the embedded device as a normal disk mounted on their computer. Further the embedded device can only access the files after the USB cable is unplugged.
The RNDIS probably does not behave as non-technical users would expect a USB device to behave. It could be confusing seeing the red lights of the firewall going on when plugging in the USB cable. The third option, the Serial Device, for me sounds like the most generic solution for many use cases. You have the full control over the communication with your embedded device without having the unexpected side effects of the previous solutions.
Let us focus on Serial Device setup and see what needs to be done to communicate over a USB serial connection. As there is already a lot of “out-of-the-box” support on the host as well as on the client, the effort is quite low. Let me describe roughly step by step what needs to be done:
On the Client Side (Toradex Module):
- Disable the ActiveSync connection which otherwise occupies the serial connection. Get more details on the Toradex Developer Site.
- Configure the registry on the Toradex WinCE image to let your USB device appear as a customized product – by default, the host will show up as a Microsoft USB Sync device. You should change these settings when you start selling your product but you don’t need to change them from the beginning. See all the registry configuration options on the MSDN website.
- Write an application that interacts with the commands and data being sent over the virtual CoM port. You find some code snippets on our developer page. After calling CreateFile() you can read and write as you would do with any other file handle.
On the Host Side: On the host we use WinUSB to communicate with our embedded device.
- If you have configured your own vendor ID and product ID in step 2 on the client side, you also need to build your custom INF file, that matches with the idVendor and idProduct. Get more information on how to build a custom WinUSB driver on MSDN.
- Write an application controlling and communicating with your device. There is a sample project available for the host side on the Toradex developer Website.
As you see the USB serial driver setup is a straightforward solution. You don't have to care about kernel level driver development, everything can be handled in the application layer.
If you have any feedback or any additional question, please leave a comment or get in contact with our support.
Leave a comment
Your email ID will be kept confidential. Required fields are marked *
* Your comment will be reviewed and then added. Thank you.