Programming the Pocket PC OS for Embedded IR Applications
Total Page:16
File Type:pdf, Size:1020Kb
M AN926 Programming the Pocket PC OS for Embedded IR Applications Appendix A: “Example Ir Standard System Author: Joseph Snyder DA Description” describes the system and documents Microchip Technology Inc. the tool used to create this Pocket PC application program, while APPENDIX B: “PPC SOURCE CODE INTRODUCTION - IrDA DEMO.CPP” through Appendix C: “PPC Source Code - IrDA DemoDlg.cpp” is the PPC This application note details the tools, supporting Application Program source code. technologies and procedures for the development of infrared applications on Windows Mobile™ based Figure 1 shows an IrDA standard system, where a devices. Pocket PC PDA device is communicating with an embedded system. In this system, the Pocket PC A Pocket PC (PPC) application that interfaces with an (PPC) PDA operates as the Primary Device (Client) embedded system via IrCOMM is included in the and the embedded system operates as the Secondary Appendices of this application note. This source code Device (Server). The terms Client and Server are used ® demonstrates the use of the Windows Application in reference to Windows (PC and PPC) programming, ® Programming Interface (API) required for IrDA while Primary Device and Secondary Device are terms standard IR communication on Windows Mobile based used by the IrDA Standard. platforms. FIGURE 1: POCKET PC PDA - EMBEDDED SYSTEM BLOCK DIAGRAM Embedded System with IrDA® Port (Secondary Device/Server) Host Controller MCP215X Optical and Embedded or Transceiver Circuitry MCP2140 Circuitry Pocket PC Handheld Device with IrDA® Standard Port (Primary Device/Client) 2004 Microchip Technology Inc. DS00926A-page 1 AN926 Terminology • Primary Device: The IrDA standard device that queries for other devices. Below is a list of useful terms and their definitions: • Secondary Device: The IrDA standard device • Pocket PC: A Windows Mobile based handheld that waits to detect IR communication before device. performing any IR communication. • Windows CE™: Microsoft® operating system for • Host Controller: The controller in the embedded handheld devices. system that communicates to the MCP215X or • Microsoft ActiveSync®: Application enabling the MCP2140. creation of a partnership between a desktop • MCP215X: An IrCOMM protocol handler IC that computer and a mobile device. This application supports IR communication from 9600 baud to allows desktop debugging of Windows Mobile 115,200 baud. based applications. • MCP2140: A low-cost IrCOMM protocol handler • Host System: The computer with which a PPC IC that supports IR communication at 9600 baud. OS device performs an ActiveSync. The host • Protocol Stack: A set of network protocol layers system is also where development takes place. that work together. Figure 2 shows the IrDA Host systems are typically based on Windows, standard protocol stack. Macintosh® or Linux® operating systems. • IrCOMM (9-wire “cooked” service class): IrDA • Microsoft Foundation Class (MFC): Class standard specification for the protocol to replace library and framework for application development the serial cable (using flow control). on Windows based platforms. ® • Microsoft eMbedded Visual C++ : FIGURE 2: IrDA® STANDARD DATA - Development environment for the development of PROTOCOL STACKS Windows Mobile based applications using C++. Available for free download from Microsoft’s web IrTran-P IrObex IrLan IrComm (1) IrMC site at www.microsoft.com. • Microsoft eMbedded Visual Basic®: LM-IAS Tiny Transport Protocol (Tiny TP) Development environment for the development of Windows Mobile based applications using Visual IR Link Management - Mux (IrLMP) Basic. Available for free download from Microsoft’s web site at www.microsoft.com. IR Link Access Protocol (IrLAP) • Microsoft Visual Studio® .NET: Development environment for the development of Windows Asynchronous Synchronous Synchronous desktop and Mobile based applications using Serial IR (2, 3) Serial IR 4 PPM C++, Visual Basic, Visual C#® and the .NET (9600 -115200 b/s) (1.152 Mb/s) (4 Mb/s) framework. Available for purchase from Microsoft’s web site at www.microsoft.com. • Microsoft Software Development Kit (SDK): Documentation, samples, header files, libraries Supported by Optional IrDA® standard and tools needed to develop applications that run the MCP215X data protocols not on the Windows operating system. All Microsoft and MCP2140. supported by the MCP215X tools require the correct platform SDK to target and MCP2140. Windows Mobile based devices. • Microsoft eMbedded Visual Tools 3.0: Note 1: The MCP215X and MCP2140 Development environment for the development of implement the 9-wire “cooked” service Windows Mobile based applications, includes class serial replicator. Microsoft eMbedded Visual C++ 3.0, eMbedded 2: An optical transceiver is required. Visual Basic 3.0 and the required SDK for Pocket PC 2002. 3: The MCP2140 support 9600 baud IR communication only. DS00926A-page 2 2004 Microchip Technology Inc. AN926 INFRARED COMMUNICATIONS Pocket PC Tools The application built and discussed in this application Microsoft offers a wide range of development choices, note uses a high-level, infrared protocol called including the eMbedded Visual C++, eMbedded Visual IrCOMM. This protocol is designed to be a wire- Basic and Visual C# programming languages. There replacement technology. Infrared technology is an are currently three development environments avail- excellent choice for data collection for many reasons, able for Pocket PC development: eMbedded Visual including: C++, eMbedded Visual Basic and Visual Studio .NET. The platform and chosen API (Win32®, MFC, ATL, • Availability: Virtually every late-model PDA and .NET Compact Framework) determines the application laptop contains an IrDA standard port. tools and languages available for development (see • Cost: IrDA standard communications may be Table 2). added to a custom design very economically, as demonstrated in this application note. Both platforms, Pocket PC 2002 and Pocket PC 2003, can be targeted with one code base using eMbedded • Convenience and Compatibility: Working without Visual C++ 3.0 if the application being developed uses wires means no cables, gender-changers or any the documented Microsoft APIs. This application note other gadgets to allow two devices to communi- focuses on development of Pocket PC 2002 and 2003 cate. This is vital to the frequent traveler or applications using Microsoft's eMbedded Visual C++ technician in the field. and the Microsoft Foundation Library (MFC). For more information regarding the IrComm protocol, visit the IrDA organization’s web site at: POCKET PC 2002 http://www.irda.org. The eMbedded Visual Tools 3.0 package, available for free from Microsoft (www.microsoft.com), includes WINDOWS POCKET PC eMbedded Visual C++ 3.0, eMbedded Visual Basic 3.0 and the required software development kit (SDK). This DEVELOPMENT version supports the Pocket PC 2002 platform. The Windows Mobile based Pocket PC is a handheld device utilizing the Windows Pocket PC 2000/2002/ POCKET PC 2003 2003 platforms. The Pocket PC software platforms are Development of Pocket PC 2003 applications requires built on the Windows CE 3.0/4.0 operating systems (see eMbedded Visual C++ 4.0 or .NET tools. eMbedded Table 1). Pocket PC allows development of applications Visual C++ 4.0 is also available as a free download using the familiar Windows development tools and from Microsoft’s web site at www.microsoft.com. APIs. These APIs include support for the development of applications that can communicate with other devices TABLE 1: PLATFORM OPERATING ® utilizing wireless transmission, such as Wi-Fi , SYSTEMS Bluetooth™ and infrared. Pocket PC Platform Window CE Version 2000 2.0, 2.1, 2.11, 3.0 2002 3.0 and later 2003 4.0 and later TABLE 2: PLATFORM DEVELOPMENT TOOLS Development Tools eMbedded Visual Tools 3.0 eMbedded Visual eMbedded Visual eMbedded Visual Visual Studio .NET C++ 3.0 Basic 3.0 C++ 4.0 (C#, Visual Basic) Pocket PC 2002 X X — — Pocket PC 2003 — — X X API • MFC • eMbedded Visual •MFC • .NET Compact •ATL Basic •ATL Framework • Win32® • Win32® 2004 Microchip Technology Inc. DS00926A-page 3 AN926 TOOL INSTALLATION WINDOWS PROGRAMMING To insure interoperability between the development The Windows programming model is based on an tools and the ability to target multiple platforms, the event-driven architecture. Events can be generated development tools and SDKs should be installed on the through user interaction or some other event. Each development system in the recommended order. time the user interacts with the interface, an event is 1. Uninstall all existing tools and SDKs. generated and a message is placed in the operating 2. Install Microsoft ActiveSync 3.7. system's message queue to be dispatched to the 3. Install the eMbedded Visual Tools - 2002 application. A message handler in the application Edition, Pocket PC 2002 SDK and Smartphone handles the event by calling the appropriate function. 2002 SDK. Selecting the Connect button in the application 4. Install eMbedded Visual C++ 4.0 and Service generates an IDC_CONNECT message (see Figure 3). Pack 2. That message is placed in the Windows message 5. Optionally install Visual Studio .NET 2003. queue. The message is then retrieved, placed in the application's message loop and dispatched in the 6. Install the Pocket PC 2003 SDK. message map to the message handler, function 7. Optionally install the Smartphone 2003 SDK. OnBnClickedConnect() (see Example 1). FIGURE 3: APPLICATION EVENT DISPATCH Incoming Message IDC_CONNECT Message Queue