RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Make Bluetooth Work for You: Build a Sample Chat Application  : Page 3

Learn how to write applications that work over Bluetooth short-range networks, using the .NET Compact Framework. Extend the sample chat application in this story to build any kind of Bluetooth applications you'd like.

Figure 4: Make a Connection. Use the Bluetooth Manger on the Pocket PC device connected to your development machine to make it recognize another Bluetooth device.

Testing the Application
To test the application, you need to install the sample application on both Pocket PCs. The easiest way to do this is to connect one of the Pocket PCs to your development machine and use Visual Studio .NET 2003 to deploy the application on the device. Then press F5 to automatically copy the application onto the device.

The next step is to copy the application onto the other Pocket PC. There are two steps involved here. First, you need to generate a CAB file for the application so that it can be copied and installed on the target Pocket PC. Second, you need to install the .NET Compact Framework on it (this only needs to be done once).

Figure 5: Generate a CAB. This button generates a CAB file for your application.

But before you can do either task, you need to establish a Bluetooth connection between the two Pocket PCs using the Bluetooth Manager to create a bond between them (see Figure 4.

Now that the two devices recognize each other, you can go about sending the CAB file and the framework to the remote device. To generate a CAB file for your application, click on the "Build Cab File" button in Visual Studio .NET 2003 (see Figure 5):

Figure 6: Pick a CAB. Visual Studio.NET will automatically generate CAB files for all platforms supported by the Compact Framework.

When the CAB file is generated, you can locate it in the "Cab\Debug" folder of your application. Visual Studio .NET 2003 will generate the CAB files for the various platforms that are supported by the .NET Compact Framework (see Figure 6. Make sure to identify the right one for your platform.

To copy the CAB file to your Pocket PC, connect your Pocket PC to your machine and use Microsoft ActiveSync's Explore option. Drag and drop the CAB file onto the desired directory (see Figure 7).

Figure 7: Use ActiveSynch. Copy the CAB file to your device using ActiveSync.

Once the CAB file is copied to the device, you can use Bluetooth to send the CAB file to the other Pocket PC, as shown in Figure 8.

The next step is to copy the .NET Compact Framework to the Pocket PC. You can find the CAB file for the .NET Compact Framework in the following directory on your development machine (with Visual Studio .NET 2003 installed):
C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE\wce300

Figure 8: Send the CAB Across. Use the Bluetooth Manager again to transfer the CAB file from one device to the other.

Choose the appropriate platform for your Pocket PC (see Figure 9). For example, my second Pocket PC is an iPaq 3630, so I chose the "arm" platform as it runs on an ARM processor. (To find out the type of processor your Pocket PC is running on, go to Start—>Settings and tap on the System tab, and click on the About icon. Under the "Processor" category, you should see the processor type. Both my Pocket PCs runs on the ARM SA1110 processor.)

Copy the "netcf.core.ppc3.arm" file (or the appropriate one for your device) to the Pocket PC via ActiveSync. Again, use Bluetooth to send the file from one device to the other.

Figure 10: Install on the Second Device. Install the .NET CF and the sample application.

On the other Pocket PC, you can now install the .NET Compact Framework and the application by tapping on the two CAB files (see Figure 10). The order of installation is important—install the .NET CF first.

Once the application is installed, you should find a BluetoothChat application icon in the Programs folder (see Figure 11).

Figure 11: Launch the App. Locate the icon for the chat application in the Programs folder.

Before you load the application, make sure that you have a Bluetooth bond between the two Pocket PCs. Tap on the Settings—>Connect menu item to establish a serial connection. The other Pocket PC will receive an authorization request for the use of the serial port. Click on Accept to start chatting!

Figure 12: Chat Away. The two screens show the dialog between the two Pocket PCs using the sample chat application in this article.

In this article, you have seen how to you can program Bluetooth applications using serial communication programming. The initial release of the .NET Compact Framework is not expected to contain classes for Bluetooth communications. However, expect to see Bluetooth managed classes and APIs appearing in Windows CE .NET and the next release of the .NET Compact Framework.

Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date