Click here to Skip to main content
Click here to Skip to main content

Windows Mobile App Development Part 2: Device Emulator and Device Emulator Manager

By , , 30 Oct 2009
Rate this:
Please Sign up or sign in to vote.

Introduction

If you are a Windows Mobile Application Developer, you probably have heard or have already used the Device Emulator. This is a priceless tool to test your applications on a variety of different Windows Mobile devices with all kinds of different form factors, without the need to have access to a large range of physical devices.

This article provides information to use the Device Emulator to test your applications, and how to configure the Device Emulator to control the behavior of the tool. This article also provides information on how to make use of the Device Emulator in combination with the Cellular Emulator to allow you to test phone calls and sending and receiving of text messages. Finally, this article also contains a section on how to make use of the Device Emulator Manager programmatically to control different emulators from inside a desktop application.

Different Versions of the Device Emulator

Device Emulator 1.0 shipped with Visual Studio 2005. This emulator allows you to run and test your applications without the need to have access to a real Windows Mobile device. Since Device Emulator is a true ARM emulator, it will run exactly the same executables that also run on real devices. Building upon Device Emulator 1.0, but extending its functionality and performance, Device Emulator 2.0 shipped with the Windows Mobile 6 SDKs. As part of the Windows Mobile 6 SDK installation process, Device Emulator 2.0 automatically replaced Device Emulator 1.0. This means that all of your Windows Mobile Smart Device projects that you developed with Visual Studio 2005 will use Device Emulator 2.0 once it has been installed. Even if you are not targeting Windows Mobile 6 devices and are still using Visual Studio 2005 for device development, it makes sense to install at least one of the Windows Mobile 6 SDKs to take advantage of Device Emulator 2.0. Not only will your code execute faster on Device Emulator 2.0, it also gives you lots of new features like extended configuration options to emulate particular hardware settings, and the possibility to test wireless communication connections.

Device Emulator 3.0 is the latest version of Device Emulator. It ships with Visual Studio 2008, and again automatically replaces any previous versions of Device Emulator that was installed on your development machine as part of the Visual Studio 2008 installation process. Device Emulator 3.0 offers the same performance improvements as Device Emulator 2.0. Using the Device Emulator Manager’s exposed COM Interfaces, it is also possible to control emulators programmatically, for instance, to automate the process of starting and cradling emulators or to programmatically alter emulator configurations.

Using the Device Emulator inside Visual Studio 2008

There are a number of ways to make use of Device Emulator from within Visual Studio 2008. To start working with Device Emulator, you can simply select one of your installed emulator images that match the SDK for which your application was built as the Target Platform inside Visual Studio 2008, and just start debugging your application. Prior to running your application on the selected Device Emulator, the application will be built, and the Device Emulator will be started if it was not already running, and it will connect to Visual Studio 2008. After the application is deployed, optionally, together with the right version of the .NET Compact Framework as well as with the SQL Server CE runtime, it will start automatically on the Device Emulator.

MOB4DEVS02/mob02fig1.jpg

Figure 1 - Windows Mobile application running in Device Emulator

Setting the Device Emulator Properties

In many situations, you probably want to use different hardware settings when testing your Windows Mobile applications. For those scenarios, the Device Emulator allows you to emulate a number of different peripherals. For instance, you can specify a particular battery charge level to test your application under low battery conditions in a very easy way. You can also bind a virtual network adapter to a physical network adapter that is available on your development machine, and you can map virtual COM ports of the Device Emulator to physical COM ports. Another option you have is to share a folder between your development machine and the Device Emulator using the Device Emulator properties. The shared folder will appear as a Storage Card inside the Device Emulator. Making use of folder sharing allows you to transfer files back and forth between the Device Emulator and your development machine.

You can display the Emulator properties dialog box from inside the Device Emulator by clicking Configure on the Device Emulator File menu.

You can display the same dialog from inside Visual Studio 2008 by clicking Options on the Visual Studio 2008 Tools menu, expanding the Device Tools in the Options dialog box, and then clicking on Devices. In the Devices box, you can then select an emulator and click on Properties. The Emulator Properties dialog box can now be activated by clicking on Emulator Options.

MOB4DEVS02/mob02fig2.jpg

Figure 2 - Configuring Emulator Properties

Using the Device Emulator in combination with the Cellular Emulator

There are many situations where you might want to test cellular connectivity in combination with your own applications. For instance, your application might have functionality to make phone calls, or maybe your application can intercept SMS messages to take some action upon. In scenarios like the one described, the Device Emulator is very useful, because it allows you to test cellular connectivity without the need to have a physical cellular connection. Working together with the Device Emulator, the Cellular Emulator can be used to emulate cellular connections. Cellular Emulator ships with Device Emulator 2.0 and higher. You can start Cellular Emulator by navigating to Start/All Programs / Windows Mobile 6 SDK / Tools / Cellular Emulator in the Start menu.

Before you can use the Device Emulator in combination with the Cellular Emulator, you have to map the Serial port 0 of the Device Emulator to the serial port that is shown in the status bar of the Cellular Emulator. In figure 3, you can see how Serial port 0 is mapped in the Emulator Properties screen to COM3 to establish a connection to the Cellular Emulator. After mapping the serial port, you have to reset the Device Emulator before you can make use of the Cellular Emulator’s functionality.

MOB4DEVS02/mob02fig3.jpg

Figure 3 - Connecting the Cellular Emulator to the Device Emulator

Amongst others, you can:

  • Make phone calls from the Device Emulator
  • Receive phone calls on the Device Emulator
  • Use a GPRS connection inside the Device Emulator to call out to a network
  • Send and receive SMS or text messages
  • Select between 2G and 3G networks
  • Analyze low level modem commands

Setting up a connection through the Cellular Emulator

As soon as the Device Emulator and the Cellular Emulator are connected, you can use the Cellular Emulator to test a lot of functionality regarding cellular connectivity. You can immediately make phone calls to and from the Device Emulator and send SMS messages to and from the Device Emulator. You can also setup a data connection to connect to a network through GPRS. In order to do so, you have to setup and configure the data connection on the Device Emulator. More information about setting up the Device Emulator to make use of a data connection can be found here: http://msdn.microsoft.com/en-us/library/bb158505.aspx.

In figure 4, you can see several data connections being active between the Device Emulator and the Cellular Emulator. In the background on the Device Emulator, you see a running instance of Internet Explorer that displays a particular website. The information is retrieved through a GPRS connection, as is shown in the status bar of the Cellular Emulator, where you can see that the GPRS is connected. The Cellular Emulator simply emulates a GPRS connection by making use of the network connection on the host machine.

In figure 4, you can also see that the Cellular Emulator’s Call Manager is used to make a phone call to the Device Emulator. In the Phone Number edit box, you can simply specify a phone number and click on the Dial button. Immediately, you will see a notification inside the Device Emulator with an incoming phone call. You can see that the phone number inside the Device Emulator corresponds with the phone number that was dialed from inside the Cellular Emulator.

MOB4DEVS02/mob02fig4.jpg

Figure 4 - Device Emulator and Cellular Emulator in action

Sending and receiving SMS messages

An important feature of the Cellular Emulator is the possibility to send SMS messages to the Device Emulator and to receive SMS messages from the Device Emulator. Simply receiving SMS messages on the Device Emulator is not that exciting. Once an SMS message is received, the user will be notified and the SMS message will be stored in the Inbox inside the Device Emulator. However, you can also capture SMS messages inside your own application. This allows for lots of interesting scenarios where you can control an application that is running on a Windows Mobile device remotely. It is up to the application to either intercept SMS messages and use them exclusively, or to intercept SMS messages and afterwards send them on to the Inbox on the device.

Especially in those situations where you are intercepting SMS messages to control your own application, you probably want to do a lot of testing, meaning you need to send many different SMS messages to your device. The combination of the Device Emulator and the Cellular Emulator is priceless for these kinds of test scenarios, since you don’t need a physical network or a costly plan with a telecom operator to test the entire application. Since this article is limited to explaining the Device Emulator itself, we will not go into details on how to intercept SMS messages programmatically. If you want to know more about this topic, you can take a look at the MSDN documentation.

In figure 5, you can see an example of an application that captures SMS messages that start with the string “Control Message”. Each time SMS messages are received on the Device Emulator with a sample application called SMS Capture running, these messages are intercepted by the application. The application shows the body text of the SMS message in a text box, and also sets the Text property of a LinkLabel control to the phone number of the sender of the SMS message, allowing the user to make a phone call to the sender of the message by simply clicking on the displayed phone number.

MOB4DEVS02/mob02fig5.jpg

Figure 5 - Capturing SMS Messages Inside an Application

Controlling the Device Emulator with Device Emulator Manager

Visual Studio 2008 contains a tool called Device Emulator Manager that can be used to control all Device Emulators that are installed on a development machine. You can start the Device Emulator Manager from inside Visual Studio by selecting Device Emulator Manager from the Tools menu. Device Emulator Manager displays a list of all installed Device Emulators in a tree view, and allows you, amongst others, to connect to a Device Emulator, to cradle it, to uncradle it, and to shutdown a Device Emulator. The ability to cradle a Device Emulator is very useful, because it allows the Device Emulator to connect to a development machine through ActiveSync (on Windows XP) or through the Windows Mobile Device Center (on Windows Vista). Once cradled, it allows the Device Emulator to synchronize content, to call out to the Internet, to install applications on the Device Emulator from the development machine using a CAB file, and so on.

Note: You must have ActiveSync or the Windows Mobile Device Center installed to be able to cradle a Device Emulator. You must also make sure that you allow connections through DMA (Direct Memory Access). You can take a look at the MSDN Documentation to learn more about cradling a Device Emulator.

MOB4DEVS02/mob02fig6.jpg

Figure 6 - Device Emulator Manger - Cradling a Device Emulator

In Figure 6, you can see a Windows Mobile 6.1 Professional Emulator with a square screen that was started using the Device Emulator Manager. After starting the emulator, the Device Emulator Manager was also used to cradle it. Controlling emulators from inside the Device Emulator Manager can be done by either right clicking on one of the emulators that are displayed in the tree view that shows all installed emulators, or by selecting an entry from the Actions menu on an already running emulator. Once you cradle the Device Emulator, you will see either ActiveSync or the Windows Mobile Device Center becoming active to establish a partnership with the Device Emulator.

Saving Device Emulator configurations for later use

With the Device Emulator Manager, it is possible to save your own particular configurations for any type of Device Emulator. Using your own configurations, you can, for instance, create an additional Device Emulator that always automatically starts with a battery level of 50% and with a storage card configured which points to a particular folder on your development machine. To begin creating your own emulator configuration, select one of the already installed emulators from inside the Device Emulator Manager, right-click on it, and select Connect. Once the emulator is running, you can change its configuration, after which you can save this particular configuration from inside the Device Emulator Manager by again right-clicking it and selecting Save As. The newly created emulator configuration appears as a brand new emulator inside the Device Emulator Manager. It is displayed in the tree view of the Device Emulator Manager under the My Device Emulators node. Creating a new emulator configuration only means that a new device emulator configuration file is created and stored, since the newly created emulator configuration is already based upon a particular emulator image. Therefore, creating new emulator configurations does not take much storage space on your hard drive.

MOB4DEVS02/mob02fig7.jpg

Figure 7 - Device Emulator Configurations

In figure 7, you see an example of a device emulator configuration with a storage card defined that points to C:\Users\Public\Documents on the development machine and that emulates running on battery power with the battery charged for 50%. Each time this particular Device Emulator is started, it has these initial settings.

Using the Device Emulator to test different security configurations

When you are using Device Emulator to test your Windows Mobile applications, you will typically not have any difficulties deploying and running them, assuming you have a working connection between Visual Studio 2008 and the Device Emulator. The Device Emulator acts like a perfect Windows Mobile device with no security enabled. Depending on the security settings on the physical Windows Mobile target devices, you might have restricted access to the device. Using Visual Studio 2008, you can configure the Device Emulator to work in a particular security configuration. A description of different security configurations that can be implemented for Windows Mobile devices is beyond the scope of this article. If you want to find more information about device security configurations, you can take a look at the MSDN documentation. Setting a particular security configuration on the Device Emulator is fairly simple and straightforward.

Once you have started a particular Device Emulator, you can retrieve its current security setting by going to the Tools menu of Visual Studio 2008 and selecting Device Security Manager. This results in displaying the Device Security Manager inside the working area of Visual Studio 2008. With the Device Security Manager, you can view the current security settings of the running Device Emulator and you can also view the installed certificates.

Note: You can also use the Device Security Manager to interrogate physical Windows Mobile devices.

To deploy a new security configuration to Device Emulator, you should take the following steps:

  1. Select the Security Configuration tab inside Device Security Manager
  2. Select a particular configuration from the list titled Security configuration
  3. Deploy the selected configuration to the Device Emulator by clicking the Deploy to Device tab inside the Device Security Manager

MOB4DEVS02/mob02fig8.jpg

Figure 8 - Device Security Manager in Combination with the Device Emulator

Automating the Device Emulator Manager

The Device Emulator Manager functionality is exposed as a series of COM objects that can be used to create a desktop application to control the Device Emulator Manager programmatically. This means that you can, for instance, write a desktop application in C# that can start and cradle a particular Device Emulator. Take the following steps to create a desktop application that makes use of the Device Emulator functionality:

  1. Use Visual Studio 2008 to create a Visual C# Windows application
  2. Add a reference to the Microsoft.DeviceEmulatorManager.Interop.9.0 assembly

    Note: Even though you might be running a later version of Device Emulator, the needed assembly will still be found in the \Program Files\Microsoft Device Emulator\1.0\Microsoft.DeviceEmulatorManager.Interop.9.0.dll folder because each new version of the Device Emulator is an in-place upgrade of a previous version of the Device Emulator.

  3. To add code to display all data stores containing emulator images on your development machine in a tree view control, you can, for instance, use this code snippet in your main form’s Load event handler to interrogate the IDeviceEmulatorManager interface:
    string categoryName; 
    TreeNode categoryNode; 
    IDeviceEmulatorManager emulatorManager = new DeviceEmulatorManagerClass(); 
    
    emulatorManager.Reset(); 
    try 
    { 
        while (true) 
        { 
             categoryName = emulatorManager.get_Name();
             categoryNode = new TreeNode(categoryName);
             ListDeviceEmulatorSDKs(emulatorManager, categoryNode);
             tvEmulators.Nodes.Add(categoryNode);
             emulatorManager.MoveNext(); 
        } 
    } 
    catch (COMException ex) 
    { 
        if (ex.ErrorCode != END_OF_DATA)
             throw ex;
    }
  4. In a similar way, you can retrieve all installed emulator families (represented by SDKs by creating a similar while loop, using the IEnumManagerSDKs interface.
  5. After retrieving all the emulator families, you can, in yet another similar way, retrieve all particular emulator images belonging to an SDK in another while loop, using the IEnumVMIDs interface.
  6. Once you have access to a particular Device Emulator, you can call methods to control that emulator, for instance, by calling its Connect, Cradle, Uncradle, and Shutdown methods on the IDeviceEmulatorManagerVMID interface.

More information on the automation possibilities of the Device Emulator Manager can be found in this article.

Related Articles in this Series

Additional resources and references

Please visit www.myrampup.com for more information.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Authors

mstruys
Instructor / Trainer Alten-PTS
Netherlands Netherlands
Maarten Struys is an experienced software developer. He has been working with all Microsoft Windows Operating Systems for over 20 years both developing native applications and, since 2000, developing managed applications. He is a well known speaker at international conferences like Tech•Ed, MEDC, and Mobile Connections. Maarten created a large number of How-Do-I videos for MSDN around device development. In the past, he frequently presented MSDN Webcasts around application development for Windows Mobile devices. Earlier this year, Maarten created the RampUp program for Windows Mobile Developers. For information about how to use .NET in the embedded world, see Maarten's Web site at http://www.dotnetfordevices.com.

dougturn
Microsoft
United States United States
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140421.2 | Last Updated 30 Oct 2009
Article Copyright 2009 by mstruys, dougturn
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid