Project: PC Robot
Project Description
A universal API for interfacing peripherals like motor controllers, sensors and
docking stations. Minimum platform requirements are a simple Netbook or PC
motherboard running a Windows running the .Net framework version 2.0. This
project will explore USB, Serial and Parallel PC interfaces; Control Algorithms
and Electronic Design of robot peripherals.
Windows USB Interfacing Using C#
As proliferated as the USB type of interface is, it is very difficult to find
information on programming around it. Most of the problem is understanding what
it actually is. My first inclination was to find a USB API and make it WriteLine
things like using a serial port API. We will explore using the serial port USB
interface in another section and it will serve as a good example of exactly what
USB is from both the electrical design and programming model perspectives.
In a simple form, a USB serial port adapter might be depicted as in Figure 1.
There is a lot going on here but the programmer needs only consider the serial
port and the application using it. An API will define the functions, some
parameters and perhaps structures for performing specific serial port
operations. The programmer will provide the protocol using the API so not
knowledge of USB is required other that those needed to connect aa USB serial
port to a PC and perhaps resolve some driver configuration.
The serial port device is connected to a PC through a USB cable including two
data wires and to power wires. Most of the sofistication of USB resides in the
physical layer and the onboard logic that turns a USB data transfer into
something useful like turning on the serail port's DTR signal.
If you cancel a 'Windows New Device Detected' dialog, the default Windows driver
the the device's class is installed. These drivers are mostly unmanaged device
drivers and there are often open developer .Net wrappers to make C# and VB
applications with. There is still some pioneering yet to do in all aspects of
USB, though.
When a USB device attaches to a Windows PC, a port detects this electrically and
then signals its parrent HUB through a direct handshake. The HUB in turn
interrupts the operating system and tells it what happened in detail and Windows
identifies the device drivers responsible for handling these things and offers
very detailed information. A driver sends a message to all subscribers of the
device, often called endpoints, and may perform some other action in response.
If a device doesn't have a registered device driver, Windows assignes a generic
one with some basic functionality if it supports the Windows USB requirements.
Windows has some default drivers for classes of devices like HID and usbprint
(usbhid,sys and usbprint.sys).
A USB HUB is just like a LAN HUB. USB connections are subject to all kinds of
abuse and therefore have built-in protection from Electro-Static Desturction
(ESD) and can tollerate frequest connections and interruptions.
USB is a small network and what you do with it has to tollerate a loss of
endpoint for an indefinate period of time. The best performance of a USB storage
device is realized in the way Windows handles USB block storage devices. The USB
memory device has a session with its device driver and Windows. To maximize
performance, much of your read-write activity happens in the PC's memory and is
written later when its more convienient for Windows and the USB storage device.
For this reason you should perform a dismount of your thumb frive instead of
just pulling the drive out.
USB communications is the transfer of data or control packages between
endpoints.
|