In Part-4 of this Windows Embedded Compact 7 (Compact 7) getting started series, we will work through the steps to develop a Compact 7 application in managed code, using C#.
The Compact 7 getting started series consist of 9 different articles, covering the following subjects:
2. Development Environment & Tools.
3. Develop a Compact 7 OS Design.
4. Develop Managed Code Application for Compact 7.
5. Develop Native Code Application for Compact 7.
6. Develop SQL Compact Database Application for Compact 7.
7. Develop Silverlight for Windows Embedded Application for Compact 7.
8. Debug and Remote Tools.
9. Deploy OS Runtime to Target Device for Distribution.
For more information about this series, visit:
To work through the exercises in this guide, we need to have the following:
· Successfully compiled a Compact 7 OS image and deploy the image to a target device, to support managed code application, which include the following components:
o CAB File Installer/Uninstaller
o .NET Compact Framework 3.5
o Core Connectivity framework files
· Generated an SDK from the same OS design that produced the OS runtime image for the target device.
· Installed the MyCompact7_SDK to the development PC.
· Both the development PC and the target device are connected to the same LAN.
Target Device: eBox-3300MX
The exercise in this guide is created using an eBox-3300MX as the target device. Refer to the following URL for more information about the eBox-3300MX:
Alternative Target Device: Virtual PC
The main objective for this getting started series is to provide simple and easy to understand information, with step-by-step illustration where possible, to help developer new to Compact 7 to become familiar with the development environment and tools quickly.
To avoid confusion and deliver easy to follow contents, a simple “Hello-world” application is used to show the steps to develop a managed code application for Compact 7.
Create a Smart Device Managed Code Application
Work through the following steps to create a managed code application for Compact 7:
1. From the VS2008 File menu, select New and click on Project to bring up the new project wizard, as shown in Figure 1.
2. On the left pane, expand the Other Languages\Visual C# node and select Smart Device as project type.
3. On the right pane, select the Smart Device Project template.
4. Enter CSharp4Compact7 as the project name.
5. Enter C:\Lab.Compact7 as the location for the project.
You can choose a different folder for the project other than C:\Lab.Compact7.
6. Click OK to continue and bring up the Add New Smart Device Project screen, as shown in Figure 2.
7. From the Target platform selection, select MyCompact7_SDK.
The MyCompact7_SDK is generated from the OS design from Part-3 of the Compact 7 getting started series, using an eBox-3300MX as the target device.
If you are using an alternative target device, select the SDK for your device.
8. From the .NET Compact Framework versions selection, select .NET Compact Framework 3.5.
9. From the Templates selection, select Device Application.
10. Click OK to complete the steps to create a new smart device application project.
After the new project wizard step is completed, the initial CSharp4Compact7 application project workspace is created in the following folder:
The initial application project is created with a blank form, Form1.cs, and a blank module, Program.cs, as shown in Figure 3.
Modify the Application User Interface
In this section, we will modify the user interface (UI) and add some codes to the application project, as follow:
· The mainMenu1 control is not needed for this exercise, right mouse click on the mainMenu1 and select Delete to remove this control, as shown in Figure 4.
· Resize Form1 to a smaller size, 300 x 200, to better fit the target device’s display resolution and change the form’s caption, as follow:
o Right mouse click on Form1 and select Properties to bring up the Properties pane for Form1. From the Form1 property pane, change the Size property to “300, 200”, as shown in Figure 5.
o From the Properties pane, change the Text property to “Compact 7 Application”, as shown in Figure 6.
· Add one textbox and two button controls to Form1, as follow:
o From the VS2008 View menu, click on Toolbox to bring up the Toolbox tab, as shown in Figure 7.
o From the Toolbox tab, double click on Button to place a button control on Form1.
o Change button1 control’s caption to “Start”.
o Double click on Button again to place a 2nd button control on Form1.
o Change button2 control’s caption to “Stop”.
o Double click on TextBox to place a textbox control on Form1.
o Resize and position the button and textbox controls on Form1, as shown in Figure 8.
Add Codes to the Application
Work through the following steps to add codes to the application:
· From the VS2008 IDE, navigate to the Form1’s design view (graphical view) and double on the Start button to bring up the code editing windows, with the button1_Click event handling code showing, as shown in Figure 9.
· Add the following codes to the button1_Click event handling:
keeprunning = true;
while (keeprunning == true)
// Show a hello message, pause 1 second
// Show next hello message in different color
textBox1.ForeColor = System.Drawing.Color.Red;
textBox1.Text = "1st Hello!";
Thread.Sleep(1000); // Wait 1 second
textBox1.ForeColor = System.Drawing.Color.Blue;
textBox1.Text = "2nd Hello!";
textBox1.ForeColor = System.Drawing.Color.Green;
textBox1.Text = "3rd Hello!";
· From the code editing window, scroll to the top and add the following line of code, as shown in Figure 10:
protected bool keeprunning = false;
· From the VS2008 IDE, navigate to the Form1’s design view (graphical view) and double click on the Stop button to bring up the code editing windows, with the button2_Click event handling code showing.
· Add the following codes to the button2_Click event handling, as shown in Figure 11.
keeprunning = false;
Compile and Build the Application
From the VS2008 Build menu, click on Build Solution to compile and build the application.
If the build process ends with error, it’s likely caused by typo. Carefully repeat the steps and review the codes to correct the typo and build again.
To download the application to the target device, we need to establish connectivity between the VS2008 IDE and the target device, using Core Connectivity framework (CoreCon).
To establish CoreCon connectivity between the VS2008 IDE and the target device, we need the following:
· Include the necessary CoreCon files to the OS runtime image.
· The target device’s IP address.
· The ConmanClient.exe and CMAccept.exe executable launched on the target device.
For information about CoreCon connectivity, refer to the following application note:
Core Connectivity (CoreCon) for Compact 7 Application Development
Establish Connectivity to the Target Device
From the VS2008 IDE, with the managed code application project active, work through the following steps to establish connectivity to the Compact 7 target device:
1. From the VS2008 IDE, click on the Device Options icon to bring up the Options screen.
(You can accomplish the same by selecting Tools à Options from the VS2008 menu.)
2. Select Device Tools\Devices from the left pane.
3. On the right, select the SDK associated with the target device. For this exercise, select MyCompact7_SDK.
4. Click on Properties to bring up the Device Properties screen.
5. Click on Configure to bring up the Configure TCP/IP Transport screen.
6. Select the “Use specific IP address” option, enter the target device’s IP address and click OK to continue.
7. Click OK to close the Device Properties screen.
8. Click OK to close the Options screen.
9. From the VS2008 IDE, click on the “Connect to Device” icon, to establish connectivity to the Compact 7 target device.
(You can accomplish the same by select Tools à Connect to Device from the VS2008 menu.)
For information about establishing CoreCon connectivity, refer to the following application note:
Deploy Managed Code Application to the Target Device
With CoreCon connectivity established between the VS2008 IDE and target device, work through the following steps to deploy application to the target device:
1. From the VS2008 Debug menu, click on Start Debugging to bring up the Deploy CSharp4Compact7 screen, as shown in Figure 12.
2. Click Deploy to download the application to the device.
At this point, the following error message is raised, as shown in Figure 13. Click Yes to continue and download the application to the target device.
3. This error message is caused by one of the project settings and does not impact the application’s function. Stop the application and work through the following steps to remedy this error:
o From the VS2008 Project menu, click on CSharp4Compact7 Properties to bring up the project properties tab, as shown in Figure 14.
o From the CSharp4Compact7 project properties tab, click on the Devices tab and uncheck the “Deploy the latest version of the .NET Compact Framework (including Service Packs)” option.
o After the “Deploy the latest version of the .NET Compact Framework (including Service Packs)” option is unchecked, the error message will not show when deploying application to the target device.
4. From the VS2008 Debug menu, click on Start Debugging to deploy the application to the target device again. Now, the application is able to deploy to the target device without error.
With the managed code application deployed to the Compact 7 target device, we can set break point and step through the code, line by line, as the code executes on the target device.
Work through the following steps to set break point and debug the application on the device:
1. With the CSharp4Compact7 application deployed from the VS2008 IDE to the target device, from CSharp4Compact7 application screen (on the device’s desktop), click on the Start button (button1 control).
As the code in the button1_click event executes, it goes through a loop to display the “1st Hello!”, “2nd Hello!” and “3rd Hello!” messages one after another continuously, with one second pause between each message, as shown in Figure 15.
2. We can set break point and halt the application as it runs on the device, as follow:
· From the VS2008 IDE, click on the Form1.cs tab and navigate to the code within button1_Click event.
On the left side of the source code view tab for Form1.cs, click on the blank column to place a break point on the following line of code, as shown in Figure 16.
txtBox1.Text = “2nd Hello!”;
The line of code at the breakpoint is highlighted in red color.
· As the code execution reaches the breakpoint, it halts at the line of code where the breakpoint is set and highlight the code in yellow.
· At this point, we can press F11 on the development PC to step through one line of code. Or, press F5 to resume the program.
· As the code reaches the breakpoint again, it will halts as before.
· Click on the breakpoint to remove the breakpoint and press F5 to resume the program.
· We can repeat the above steps, set another breakpoint to halt execution on a different line of code, step through the code.
As part of a typical application development project, we spend a lot more time debugging the code to resolve problems and optimize the code. An efficient debugging environment can significantly shorten debugging time, increase productivity and ultimately lowering the overall development cost.
Trackback from Samuel PhungIn Part-6 of this Compact 7 getting started series, we will show the steps to develop SQL Compact database application for embedded device. ...
View this page in another language: