Motorola CoreScanner Driver Wrapper
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Linq;
5 using System.Reflection;
6 using Motorola.Snapi;
10 
11 namespace Motorola.Examples
12 {
13  static class Program
14  {
15  private static List<IMotorolaBarcodeScanner> _scanners;
16  private static string _lastScanned;
17 
18  static void Main()
19  {
20  //First open an instance of the CoreScanner driver.
21  BarcodeScannerManager.Instance.Open();
22  //Register for events.
23  BarcodeScannerManager.Instance.RegisterForEvents(
24  EventType.Barcode,
25  EventType.Pnp,
26  EventType.Image,
27  EventType.Other,
28  EventType.Rmd
29  );
30  //If you need to unregister
31  BarcodeScannerManager.Instance.UnRegisterForEvents(
32  EventType.Barcode,
33  EventType.Pnp,
34  EventType.Image,
35  EventType.Other,
36  EventType.Rmd
37  );
38  //The events you are currently registered to will be listed in RegisteredEvents.
39  if (BarcodeScannerManager.Instance.RegisteredEvents.Contains(EventType.Image))
40  {
41  //Do things
42  };
43 
44  //Turn off keyboard emulation
45  BarcodeScannerManager.Instance.Keyboard.EnableEmulation = false;
46 
47  //Get a List<IMotorolaBarcodeScanner> containing each connected scanner.
48  _scanners = BarcodeScannerManager.Instance.GetDevices();
49 
50  //Loop through scanners and set their host mode to SNAPI with imaging enabled.
51  foreach (var scanner in _scanners)
52  {
53  scanner.SetHostMode(HostMode.USB_SNAPI_Imaging);
54  }
55 
56  //Add a handler for barcode scans.
57  BarcodeScannerManager.Instance.DataReceived += OnDataReceived;
58 
59  Console.WriteLine("Ready to scan.. (Enter to quit)");
60  Console.ReadLine();
61  }
62 
63  //Outputs barcode data to the console and overwrites _lastScanned.
64  private static void OnDataReceived(object sender, BarcodeScanEventArgs e)
65  {
66  _lastScanned = e.Data;
67  Console.WriteLine("Barcode type: " + e.BarcodeType.GetDescription());
68  Console.WriteLine("Data: " + e.Data);
69  }
70 
71  //Gets the description out of an Enum
72  public static string GetDescription(this Enum value)
73  {
74  FieldInfo fi = value.GetType().GetField(value.ToString());
75 
76  DescriptionAttribute[] attributes =
77  (DescriptionAttribute[])fi.GetCustomAttributes(
78  typeof(DescriptionAttribute),
79  false);
80 
81  if (attributes != null &&
82  attributes.Length > 0)
83  return attributes[0].Description;
84  else
85  return value.ToString();
86  }
87  }
88 }
Definition: BarcodeOrientation.cs:7
Definition: BarcodeScanEventArgs.cs:9