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

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.

Windows 8 Icons: Segoe UI Symbol

Whatz up guyz... In this post i am going to tell you about "Windows 8 Icons" . If you ever used a windows 8 app, you know that there are so many standard Icons. Actually we do not want to add images for each button, simply we can use the character map for obtain the icons.Go to the character map and select the font as "Segoe UI Symbol" .Then you will see lot of standard symbols in the character map.

SQLite Database for Windows 8 App : Adding existing SQLite DB file

Hi Guys ... This Post is about adding an existing SQLite database file to the Windows Metro App project. As I think "using SQLite" is the best way to create local database for Windows Rt applications.Actually SQLite is very easy to learn but I really think if Microsoft SQL Server CE supports windows rt applications it will more fun. .Isnt it ?. :)