Infrared and Other Devices

< BACK  NEXT >
[oR]

The serial communications techniques described here can be used to communicate with any device that implements a suitable stream interface driver. The drivers installed on a Windows CE device are listed in the registry key \HKEY_LOCAL_MACHINE\Drivers\Active. This key contains a sub-key for each driver, and each driver is given a number (such as 01, 02, 03, and so on). The subkey contains the name of the driver (the "Name" value) and a "key" value. This "key" value contains the name of a registry key in HKEY_LOCAL_MACHINE that contains configuration data for the device. The key name for the serial communications port is usually "drivers\builtin\serial." This key contains information about the driver, including a "FriendlyName" value (for example, "Serial Cable on COM1:") and the DLL that implements the device (for example, "Serial.Dll"). From this information you can enumerate all the serial devices present on a Windows CE device, and determine the name that should be passed to CreateFile to open the device (for example, "COM1:").

All serial devices are accessed through calls to CreateFile, ReadFile, WriteFile, and CloseHandle. RS232 serial devices need timings and DCB settings to be configured, but other devices do not. For example, you do not need to set Baud rate or flow control settings since the driver handles transmission speed internally. The GetCommProperties function returns a COMMPROP structure for an open serial port, and this structure contains values such as the maximum Baud rate and size of the transmit and receive queues.

All devices allow parameters to be set through the DeviceIoControl function. This generic function allows data to be written to and obtained from the device driver. The IO control function is specified using an IoCtl code specific to a particular driver. Generally, you do not need to call DeviceIoControl directly, but you may find your device does publish IoCtr codes that need to be called.

Information on the infrared port is contained in the registry key HKEY_LOCAL_MACHINE\Drivers\Builtin\IrCOMM. The infrared port is normally mapped to a virtual communications port, for example "COM4". The "Index" value in the Drivers\Builtin\IrCOMM key specifies the port number (for example, 4). Once the communications port has been determined, the infrared port can be opened using CreateFile for serial communications. Before the WriteFile and ReadFile functions are called, a call to EscapeCommFunction must be made to enable serial communications for the infrared port. This changes the infrared port from operating in "raw" mode to "IrComm" mode.

 EscapeCommFunction(hIRPort, SETIR); 

Once you have finished you should call EscapeCommFunction with CLRIR to return the infrared port back to raw mode.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net