This is an installment of Barcode Scanning With Microsoft Dynamics Mobile series.
This article is targeted at developers who want to start using the barcode scanner capabilities of Microsoft Dynamics Mobile 1.5 framework. It supports Motorola (formerly Symbol) and Intermec devices. After you have read this article and followed its tutorial part you will be able to implement your own tasklets with barcode scanning capabilities. It might seem a long way on first glance but once done you will realize that the heart of the functionality is doable in just a few steps.
The following tutorial describes all steps necessary to create a simple Rolepad based application which enables barcode scanning on Motorola (Symbol) and Intermec devices. The process is the same for both device classes – there are only two differences: The first one is proprietary .NET CF scanning assemblies which you must download and reference within your project and the second one is the corresponding section in the App.config file. Tutorial is written for Symbol, differences are highlighted for Intermec.
Microsoft.Dynamics.Mobile.Components
Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.Symbol
(Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.SymbolIntermec)
Microsoft.Dynamics.Mobile.Components.Tasklets.Menu
Microsoft.Dynamics.Mobile.Framework.Runtime
using Microsoft.Dynamics.Mobile.Framework.Entities;
using Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning;
using Microsoft.Dynamics.Mobile.Components.Services;
BarcodeReader barcodeReader;
[RolePadService]
public BarcodeScanningService BarcodeScanningService { get; set; }
protected override void OnStarted()
{
base.OnActivated();
barcodeReader = BarcodeScanningService.GetReader(this);
barcodeReader.Scanned += new EventHandler<ScannedDataEventArgs>(barcodeReader_Scanned);
barcodeReader.Error += new EventHandler<ErrorEventArgs>(barcodeReader_Error);
}
protected override void OnActivated()
barcodeReader.Open();
protected override void OnDeactivated ()
base. OnDeactivated ();
barcodeReader.Close();
protected override void OnClosing(ExitResult exitResult)
base.OnClosing(exitResult);
barcodeReader.Error -= barcodeReader_Error;
barcodeReader.Scanned -= barcodeReader_Scanned;
barcodeReader.Dispose();
void barcodeReader_Error(object sender, ErrorEventArgs e)
if (e != null && e.Exception != null)
Container.Alert("Exception ocured while using barcode scanner:\n" + e.Exception.Message);
void barcodeReader_Scanned(object sender, ScannedDataEventArgs e)
if (e != null && e.Data != null && e.Data.Length > 0)
view.ShowScannedBarcode(e.Data[0]);
void ShowScannedBarcode(string barcode);
public void ShowScannedBarcode(string barcode)
this.txtScannedBarcodes.Text += barcode + Environment.NewLine;
<!-- Required for Barcode scanning on Symbol devices-->
<add type="Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanningService, Microsoft.Dynamics.Mobile.Framework.Runtime">
<configuration xmlns="http://schemas.microsoft.com/Dynamics/Mobile/2008/11/Services/BarcodeScanning/Configuration">
<scannerType>Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.Symbol.ScannerDevice, Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.Symbol</scannerType>
</configuration>
</add>
<!-- Required for Barcode scanning on Intermec devices-->
<!--<add type="Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanningService, Microsoft.Dynamics.Mobile.Framework.Runtime">
<scannerType>Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.Intermec.ScannerDevice, Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.Intermec</scannerType>
</add>-->
<?xml version="1.0" encoding="utf-8" ?>
<userRole minimize="false" xmlns="http://schemas.microsoft.com/Dynamics/Mobile/2008/11/Flow">
<orchestrations>
<orchestration name="startup">
<tasklets>
<!-- Main Menu (Menu) -->
<tasklet name="MenuTasklet" icon="Graphics\Dynamics_small.png" text=" Barcode Scanner Sample" context="Tasklet header;26" type="Microsoft.Dynamics.Mobile.Components.Tasklets.MenuTasklet, Microsoft.Dynamics.Mobile.Components.Tasklets.Menu">
<actions>
<group name="BackAndCancel" type="Flat" priority="98">
<exitOrchestration name="Close" text="Close" />
</group>
<group name="MenuItems" priority="50" type="Flat">
<open text="Barcode" icon="Graphics\Barcode_large.png" priority="49" tasklet="BarcodeScanner" />
</actions>
</tasklet>
<!-- /Main menu (Menu) -->
<!-- This is a demo tasklet which shows how to implement barcode scanning functionality. -->
<tasklet name="BarcodeScanner" icon="Graphics\Barcode_small.png" type="BarcodeScanner.BarcodeScannerTasklet, BarcodeScanner" >
<exitTasklet text="Close" />
</tasklets>
</orchestration>
</orchestrations>
</userRole>
Do not forget to check MSDN documentation: BarcodeScanningService Class
By the way: The complete source code can be downloaded – see the bottom of this article. However I am sure you are glad you went through the whole example by yourself - it is the best way how to learn the stuff.
Please notice that the downloadable code is more complex and much better commented than the example you created based on the tutorial above. The difference is mainly given by more extensive error handling in the downloadable code. The tutorial code should be used for tutoring/learning only, the downloadable example on the other hand rather as a skeleton for building real applications based on 1.5 version of the Framework.
Download source code here: BarcodeScannerSample15.zip
This code will run first after you copy barcode drivers into the .\BarcodeScannerSample15\BinaryReferences folder.