AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 07.04.2009, 08:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,640 / 848 (80) +++++++
Регистрация: 28.10.2006
Dynamics Mobile: How to code your own barcode enabled tasklets (Motorola and Intermec devices)
Источник: http://blogs.msdn.com/dynamicsmobile...c-devices.aspx
==============

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.

  1. Prerequisites: Microsoft Visual Studio 2008 SP1 (Professional edition or above), Microsoft Dynamics Mobile – Device Components with Device SDK feature installed
  2. We are going to create one VS solution with two projects based on Microsoft Dynamics Mobile 1.5 platform. The main purpose of the Rolepad project called BarcodeScannerSample15 is an easy deployment of all necessary binaries configuration files. The barcode scanning logic is being coded in the separated tasklet project called BarcodeScanner.
  3. Open Visual Studio 2008 (Professional edition or above).
  4. Create a Rolepad project called BarcodeScannerSample15: File > New > Project… > Project types > Visual C# > Dynamics Mobile > Rolepad project for Windows Mobile 6 (or Windows Mobile 5 if you wish).
  5. Add a new tasklet project called BarcodeScanner to the BarcodeScannerSample15 solution: Right-click on BarcodeScannerSample15 solution > Add > New Project… > Project types > Visual C# > Dynamics Mobile > Tasklet project for Windows Mobile 6 (or 5).
  6. BarcodeScanner assembly should be deployed automatically when deploying BarcodeScannerSample15 project: Add reference of the BarcodeScanner project to the BarcodeScannerSample15 project.
  7. Add following references to the BarcodeScannerSample15 project:
    1. Microsoft.Dynamics.Mobile.Components Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.Symbol (Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.SymbolIntermec) Microsoft.Dynamics.Mobile.Components.Tasklets.Menu
  8. The scanning itself is a manufacturer-specific operation, so manufacturer-specific assemblies will be needed. You have to download and extract the following assemblies: Symbol and Symbol.Barcode for Motorola (Symbol) devices and Intermec.DataCollection.CF2 for Intermec. Read the article Where to get barcode drivers to figure out where and how to get these.
  9. Open Windows Explorer and locate BarcodeScannerSample15 project folder, create BinaryReferences subfolder and copy extracted assemblies under this folder. Reference these binaries from the BarcodeScannerSample15 project.
  10. The core of barcode reader functionality provided by Microsoft Dynamics Framework is located in Microsoft.Dynamics.Mobile.Runtime assembly. Add following reference to the BarcodeScanner (tasklet) project:
    1. Microsoft.Dynamics.Mobile.Framework.Runtime
  11. Open BarcodeScannerTasklet.cs and add following using statements:
    1. using Microsoft.Dynamics.Mobile.Framework.Entities; using Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning; using Microsoft.Dynamics.Mobile.Components.Services;
  12. We will need a BarcodeReader object to perform the actual scanning. This object will be created by BarcodeScanningService defined in the App.config file. The service assures that a correct version of BarcodeReader object will be newed-up.
  13. Add BarcodeReader private field called barcodeReader.
    1. BarcodeReader barcodeReader;
  14. Add BarcodeScanningService public property called BarcodeScanningService and decorate it with [RolePadService] attribute.
    1. [RolePadService] public BarcodeScanningService BarcodeScanningService { get; set; }
  15. Edit OnStarted method. You must ask BarcodeScanningService to create particular BarcodeReader object and implement two event handlers with self-explaining names. This code will be called only once within the tasklet lifetime.
    1. protected override void OnStarted() { base.OnActivated();   barcodeReader = BarcodeScanningService.GetReader(this);   barcodeReader.Scanned += new EventHandler(barcodeReader_Scanned); barcodeReader.Error += new EventHandler(barcodeReader_Error); }
  16. Override OnActivate method. The scanner must be opened (enabled). This code can be called repeatedly when entering already started tasklet.
    1. protected override void OnActivated() { base.OnActivated();   barcodeReader.Open(); }
  17. Override OnDeactivated method. The scanner will be closed (disabled). Counterpart of the OnActivate method – can be called repeatedly.
    1. protected override void OnDeactivated () { base. OnDeactivated ();   barcodeReader.Close(); }
  18. Override OnClosing method. Closing the system resources and bit of cleaning.
    1. protected override void OnClosing(ExitResult exitResult) { base.OnClosing(exitResult);   barcodeReader.Error -= barcodeReader_Error; barcodeReader.Scanned -= barcodeReader_Scanned;   barcodeReader.Dispose(); }
  19. Add barcodeReader_Error event handler.
    1. 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); }
  20. Add barcodeReader_Scanned event handler. In case the scanning was successful tasklet view class is going to present the scanned data. Some barcode readers return multiple lines of the scanned information. Typically we need to know only the first one – that is why we pass 0 index of e.Data array to the view.
    1. void barcodeReader_Scanned(object sender, ScannedDataEventArgs e) { if (e != null && e.Data != null && e.Data.Length > 0) view.ShowScannedBarcode(e.Data[0]); }
  21. You are done with the tasklet itself but we have to extend its view.
  22. Double-click BarcodeScannerView.cs and add one TextBox control called txtScannedBarcodes.
  23. Make txtScannedBarcodes control ReadOnly, Multiline and change its size to your convenience.
  24. Open IBarcodeScannerView.cs and add extend the interface by:
    1. void ShowScannedBarcode(string barcode);
  25. Right-click BarcodeScannerView.cs and select View Code.
  26. Implement IBarcodeScannerView by the following code:
    1. public void ShowScannedBarcode(string barcode) { this.txtScannedBarcodes.Text += barcode + Environment.NewLine; }
  27. You should be able to build BarcodeScanner tasklet project by now so let us finish the BarcodeScannerSample15 project.
  28. Modify app.config by adding of the following code at the beginning of the node. The simple configuration informs Framework that it should create BarcodeScanningService of an appropriate type. Please notice that you must comment out/in the correct section for Intermec devices:
    1. Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.Symbol.ScannerDevice, Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.Symbol   <span style="color: #008000"> Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.Intermec.ScannerDevice, Microsoft.Dynamics.Mobile.Components.Services.BarcodeScanning.Intermec -->
  29. Modify UserRole.xml – replace its whole content by the following code. It is a very simple orchestration with two tasklets: Menu tasklet provided by the Framework as an invitation screen and our newly created BarcodeScanner tasklet.
    1. </span span style="color: #ff0000"version/spanspan style="color: #0000ff"="1.0"/span span style="color: #ff0000"encoding/spanspan style="color: #0000ff"="utf-8"/span ?span style="color: #0000ff">  
  30. You should be able to build the whole solution at this moment.
  31. Double check that BarcodeScannerSample15 is your startup project. If it is not the case then right-click on BarcodeScannerSample15 project node and select “Set as StartUp Project”.
  32. Right-click Properties subfolder of BarcodeScannerSample15 project and select Open.
  33. Go to Devices and select your target device.
  34. Connect the device and press F5.
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.



Источник: http://blogs.msdn.com/dynamicsmobile...c-devices.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 03.06.2014, 06:34   #2  
imageat is offline
imageat
Участник
 
1 / 10 (1) +
Регистрация: 03.06.2014
i like the feature of this barcode sanner, i have an excel. do you .net barcode scanner support scan barcode from excel. if so that would be wonderful.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Dynamics Mobile: Where To Get Barcode Drivers Blog bot DAX Blogs 0 21.01.2009 23:05
Dynamics Mobile: Barcode Scanning With Microsoft Dynamics Mobile Blog bot DAX Blogs 0 21.01.2009 23:05
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 13:57.