Skip to main content

Barcode Reader for Motorola MC3000 Device (Windows Mobile 6)

You can simply click the button and read the barcode.
Create the User interface as you wish and add following codes to the scan button and Scanning.cs class.


Add following code to the button

Code:
      private void scanBtn_Click(object sender, EventArgs e)
        {      
           Scanning.ToggleTrigger();             
        }

Create a class name call Scanning.cs and add following codes

Code:
using System;
using System.Windows.Forms;

namespace ProjectName
{
    /// <summary>
    /// The Scanning class provides static methods to allow reuse of the same 
    /// Reader and ReaderData objects on multiple forms.
    /// </summary>
    public class Scanning
    {
        private static Symbol.Barcode.Reader _MyReader = null;
        private static Symbol.Barcode.ReaderData _MyReaderData = null;
        private static System.EventHandler _MyEventHandler = null;

        /// <summary>
        /// MyReaderData property provides access to the ReaderData 
        /// </summary>
        public static Symbol.Barcode.ReaderData MyReaderData
        {
            get { return _MyReader.GetNextReaderData(); }
        }

        /// <summary>
        /// Upon completion of a scan a ReadNotify event will be fired. 
        /// _MyEventHandler specifies the delegate that will handle this notification
        /// and MyEventHandler property provides access to _MyEventHandler.
        /// Each form that uses the Scanning class will have it's own delegate.
        /// The form will be responsible for setting this Event Handler to it's delegate.
        /// </summary>
        public static System.EventHandler MyEventHandler
        {
            get { return _MyEventHandler; }
            set { _MyEventHandler = value; }
        }

        /// <summary>
        /// Initialize the reader.
        /// </summary>
        public static bool InitReader()
        {
            // If reader is already present then fail initialize
            if (Scanning._MyReader != null)
            {
                return false;
            }

            try
            {

                if (Symbol.Barcode.Device.AvailableDevices.Length > 1)
                {
                    MessageBox.Show("Connected with More than one Reader");

                }

                else
                {
                    // Create new reader, first available reader will be used.
                    Scanning._MyReader = new Symbol.BarcodeReader();

                }

                // Create reader data
                Scanning._MyReaderData = new Symbol.BarcodeReaderData(
                    Symbol.Barcode.ReaderDataTypes.Text,
                    Symbol.Barcode.ReaderDataLengths.MaximumLabel);

                // Enable reader, with wait cursor
                Scanning._MyReader.Actions.Enable();

                Scanning._MyReader.Parameters.Feedback.Success.BeepTime = 0;
                Scanning._MyReader.Parameters.Feedback.Success.WaveFile = "\\windows\\alarm3.wav";
            }

            catch (Symbol.ExceptionsOperationFailureException ex)
            {
                MessageBox.Show("InitReader\n" +
                    "Operation Failure\n" + ex.Message +
                    "\n" +
                    "Result = " + (Symbol.Results)((uint)ex.Result)
                    );
            }
            catch (Symbol.ExceptionsInvalidRequestException ex)
            {
                MessageBox.Show("InitReader\n" +
                    "Invalid Request\n" +
                    ex.Message);
            }
            catch (Symbol.ExceptionsInvalidIndexerException ex)
            {
                MessageBox.Show("InitReader\n" +
                    "Invalid Indexer\n" +
                    ex.Message);
            };

            return true;
        }

        /// <summary>
        /// Stop reading and disable/close reader
        /// </summary>
        public static void TermReader()
        {
            // If we have a reader
            if (Scanning._MyReader != null)
            {
                try
                {
                    // Disable the reader
                    Scanning._MyReader.Actions.Disable();

                    // Free it up
                    Scanning._MyReader.Dispose();

                    // Indicate we no longer have one
                    Scanning._MyReader = null;
                }

                catch (Symbol.ExceptionsOperationFailureException ex)
                {
                    MessageBox.Show("TermReader\n" +
                    "Operation Failure\n" + ex.Message +
                    "\n" +
                    "Result = " + (Symbol.Results)((uint)ex.Result)
                    );
                }
                catch (Symbol.ExceptionsInvalidRequestException ex)
                {
                    MessageBox.Show("TermReader\n" +
                        "Invalid Request\n" +
                        ex.Message);
                }
                catch (Symbol.ExceptionsInvalidIndexerException ex)
                {
                    MessageBox.Show("TermReader\n" +
                        "Invalid Indexer\n" +
                        ex.Message);
                };
            }

            // If we have a reader data
            if (Scanning._MyReaderData != null)
            {

                try
                {
                    // Free it up
                    Scanning._MyReaderData.Dispose();

                    // Indicate we no longer have one
                    Scanning._MyReaderData = null;
                }

                catch (Symbol.ExceptionsOperationFailureException ex)
                {
                    MessageBox.Show("TermReader\n" +
                    "Operation Failure\n" + ex.Message +
                    "\n" +
                    "Result = " + (Symbol.Results)((uint)ex.Result)
                    );
                }
                catch (Symbol.ExceptionsInvalidRequestException ex)
                {
                    MessageBox.Show("TermReader\n" +
                        "Invalid Request\n" +
                        ex.Message);
                }
                catch (Symbol.ExceptionsInvalidIndexerException ex)
                {
                    MessageBox.Show("TermReader\n" +
                        "Invalid Indexer\n" +
                        ex.Message);
                };
            }
        }

        /// <summary>
        /// Start a read on the reader
        /// </summary>
        public static void StartRead()
        {
            // If we have both a reader and a reader data
            if ((Scanning._MyReader != null) &&
                (Scanning._MyReaderData != null))
            {

                try
                {
                    // Submit a read
                    Scanning._MyReader.ReadNotify += Scanning._MyEventHandler;

                    // Prevent duplicate reads
                    if (!Scanning._MyReaderData.IsPending)
                        Scanning._MyReader.Actions.Read(Scanning._MyReaderData);
                }

                catch (Symbol.ExceptionsOperationFailureException ex)
                {
                    MessageBox.Show("StartRead\n" +
                    "Operation Failure\n" + ex.Message +
                    "\n" +
                    "Result = " + (Symbol.Results)((uint)ex.Result)
                    );

                    if ((Symbol.Results)(ex.Result) == Symbol.Results.E_SCN_READINCOMPATIBLE)
                    {
                        // If the failure is E_SCN_READINCOMPATIBLE, exit the application.
                        MessageBox.Show("The application will now exit.");
                        TermReader();
                        Application.Exit();
                    }
                }
                catch (Symbol.ExceptionsInvalidRequestException ex)
                {
                    MessageBox.Show("StartRead\n" +
                        "Invalid Request\n" +
                        ex.Message);
                }
                catch (Symbol.ExceptionsInvalidIndexerException ex)
                {
                    MessageBox.Show("StartRead\n" +
                        "Invalid Indexer\n" +
                        ex.Message);
                };
            }
        }

        /// <summary>
        /// Stop all reads on the reader
        /// </summary>
        public static void StopRead()
        {
            // If we have a reader
            if (Scanning._MyReader != null)
            {
                try
                {
                    // Flush (Cancel all pending reads)
                    Scanning._MyReader.ReadNotify -= Scanning._MyEventHandler;
                    Scanning._MyReader.Actions.Flush();
                }

                catch (Symbol.ExceptionsOperationFailureException ex)
                {
                    MessageBox.Show("StopRead\n" +
                    "Operation Failure\n" + ex.Message +
                    "\n" +
                    "Result = " + (Symbol.Results)((uint)ex.Result)
                    );
                }
                catch (Symbol.ExceptionsInvalidRequestException ex)
                {
                    MessageBox.Show("StopRead\n" +
                        "Invalid Request\n" +
                        ex.Message);
                }
                catch (Symbol.ExceptionsInvalidIndexerException ex)
                {
                    MessageBox.Show("StopRead\n" +
                        "Invalid Indexer\n" +
                        ex.Message);
                };
            }
        }

        public static void ToggleTrigger()
        {
            InitReader();

            if (Scanning._MyReader == null)
            {
                MessageBox.Show("Barcode Reader Can Not Read");
                
            }
            Scanning._MyReader.Actions.ToggleSoftTrigger();
            Scanning.StartRead();

        }

    }
}

Motorola (formerly Symbol): You need two assemblies called Symbol and Symbol.Barcode
  • Go to Motorola EMDK for .NET v2.0 (EMDK stands for Enterprise Mobility Developer Kit formerly known as SMDK - Symbol Mobility Developer Kit) and download EMDK-M-020005-Up2.zip.
  • Unzip and locate the following CAB file: symbol.all.arm.cab (typically in .\SDK\Smart Devices\wce500\armv4i folder).
  • Install the CAB file on any Windows Mobile device or emulator, and locate Symbol.dll and Symbol.Barcode.dll on that device under \Windows
  • Copy Symbol.dll and Symbol.Barcode.dll to your PC for future use.
 Go through these steps then you can run the application and read the barcodes ..

Thank you..

Comments

Unknown said…
Where have you assigned the value to the textbox.
You can assign value within the ScanBtn_click event..
like
this.textbox.Focus();

Popular posts from this blog

Imagine Cup 2014

Hi guys .. Get ready for imagine cup 2014 In NewZealand .In the next few days imagine cup 2013 finals will happen in Russia. So It is time to wear your thinking hat.You have one year to develop your marvelous ideas.  The Microsoft Imagine Cup is the world’s most prestigious student technology competition, bringing together student innovators from all over the world. If you have a great idea for a new app, bring it to life through Imagine Cup. Over the past 10 years, more than 1.65 million students from 190 countries have participated in the Imagine Cup. 

Visual Studio 2013 New Editor Features

In Visual Studio 2013, we have introduced new features that boost productivity and save time when working inside the Editor. Some of these are new features and some are the most popular extensions from  Productivity Power Tools . These features are a result of the feedback you gave us through  User Voice  requests, forum posts and Connect bugs. The MVP community also helped us pick some of these experiences. Our primary focus for the Editor in this version is to keep the developer in context as much as possible. This blog post describes capabilities that bring information to your fingertips and allow you to do as much as possible without leaving your place in code.

C# Character Escape Sequences

Character combinations consisting of a backslash ( \ ) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences. An escape sequence is regarded as a single character and is therefore valid as a character constant.