31.2. Device Emulation

With so many mobile devices on the market, it is not always economical for you to go out and purchase a new device in order to develop your application. Luckily, Microsoft has released a series of device emulators for each version of Windows Mobile. This allows you to compare functionality across different versions of the platform and even between emulators with different screen sizes and orientation.

31.2.1. Device Emulator Manager

In the previous version of Visual Studio, working with the device emulator was quite painful. If you didn't have your computer set up exactly right, Visual Studio would refuse to talk to the emulator. Unlike debugging your application on a real device via the WMDC (or ActiveSync), debugging on an emulator used its own communication layer, which was unreliable. This was addressed with the inclusion of the Device Emulator Manager.

The Device Emulator Manager gives you much better control over the state of emulators installed on your computer. Figure 31-9 shows the Device Emulator Manager with the Windows Mobile 5.0 Pocket PC Emulator running, which is evident from the play symbol next to the emulator.

Figure 31.9. Figure 31-9

When you run your application from Visual Studio and elect to use an emulator, the Device Emulator Manager (DEM) is also started. If you try to close the DEM using the close button it will actually minimize itself into the system tray, because it is useful to have open while you work with the emulators.

31.2.2. Connecting

If an emulator is not currently active (that is, it appears without an icon beside it), you can start it by selecting Connect from the right-click context menu for that item in the tree. Once the emulator has been started, Visual Studio 2008 can use that emulator to debug your application.

After connecting to a device, the DEM can be used to shut down, reset, or even clear the saved state of the device. Clearing the saved state restores the device to the default state and may require Visual Studio to reinstall the .NET Compact Framework before you debug your application again (this depends on which emulator you are using and what version of the .NET Compact Framework you are targeting). This might be necessary if you get the emulator into an invalid state.

31.2.3. Cradling

The only remaining difference between running your application on a real device versus on the emulator is the communication layer involved. As mentioned previously, real devices use the WMDC to connect to the desktop. The communication layer provided by the WMDC is not only used by Visual Studio 2008 to debug your application, but it can also be the primary channel through which you synchronize data.

The ideal scenario is to have Visual Studio 2008 debug the emulator via the same communication layer. This has been achieved using the Device Emulator Manager to effectively cradle the emulator. From the right-click context menu for a running emulator, you can elect to cradle the device. This launches the WMDC, which may prompt you to set up a partnership between the emulator and the host computer — the same way you would for a real device. You can either set this up (if you are going to be doing a lot of debugging using the emulator) or just select the guest partnership.

Remember that once you have cradled the emulator, it is as if it were a real device at the end of the WMDC communication layer. As such, when you select which device you want to debug on, you need to select the Windows Mobile device, rather than any of the emulators. Using this technique, the interaction between Visual Studio 2008 and the emulator will mirror what you would get with a real device.

The Windows Mobile Device Center allows you to connect over a range of protocols including COM ports, Bluetooth, InfraRed, and DMA. The latter was introduced to improve performance when debugging applications — you need to select this communication method when debugging applications via the WMDC to an emulator.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.254.118