We write under TSD. Connecting a barcode scanner as a form component

  • Tutorial
It's no secret that industrial software for data collection terminals (TSD) is written to automate business processes, especially warehouse ones. Most of the tasks that need to be solved with the help of TSD are related to bar coding, since the barcode scanner is built into the device.
This article will discuss how to start writing programs for data collection terminals, and how to connect and use a barcode scanner.

My prototype Motorola MC3190 has a laser barcode scanner. (In the near future I plan to deal closely with Datalogic with an messenger).

If you are interested, you can familiarize yourself with the specification .

Windows CE is installed on the device, respectively, and it will be necessary to write for it. And if you have never tried writing under TSD, of course, you should start with Hello World. To run an application written in C # on this device, you need to install .NET 3.5 Compact on it. And also have Visual Studio 2008 on hand, since in all subsequent releases there is no Smart Device project option (small ones like to impose their new technologies, which, unfortunately, are not always compatible with earlier versions of their own operating system).

So, having created a simple application, you can try to launch it right away. If the device is connected to a computer, then the studio will immediately offer to launch directly on it, with the possibility of debugging, of course. After waiting a few minutes, you can see the launch of the form on the device.

Now you can proceed to the most interesting.

In order to use the object model already implemented in C #, Motorola has prepared a number of libraries. In fact, with the help of them you can create everything that we want. This miracle is called Symbol. In our case, Symbol.Barcode will be used. Unfortunately, at the moment, the official website of the symbol.com library redirects us to motorolasolutions.com, announcing that the technology is outdated. But I once made copies of all Reference with examples:


In the examples, those who are interested can certainly dig around, but I can immediately warn that there are articles in which everything is described much easier and more convenient, in my opinion, the best among them: kbss.ru/blog/dotnetcf/178.html . But, nevertheless, I believe that connecting a barcode scanner every time is not very convenient, especially if the application is planned to be multi-window. In addition, in some cases there may be problems with reading, when the focus returns to the parent window from the child.

Of all that can be found on the Internet, the main thing to realize is that the most convenient way to process barcodes is an event-based model:
1. The barcode scanner worked.
2. Recognized the barcode correctly.
3. We trigger the event of processing this barcode in our program, which has already been disassembled and is easy to read.

The form component is a pattern that allows you to add your control to the studio form designer. We will use this. And not only because it will simplify the development of forms, but also because in the future, the component can be modified so that it supports scanners not only from Motorola.

Then you need to describe the component class.

public partial class BarcodeReader : Component
        private Symbol.Barcode.BarcodeReader barcodeReader = null;
        public delegate void OnReadBarcodeReaderEventHandler(string Text);
        public event OnReadBarcodeReaderEventHandler OnRead;
        public BarcodeReader()
        public BarcodeReader(IContainer container)
        private void InitializeBarcodeReader()
            this.barcodeReader = new Symbol.Barcode.BarcodeReader();
            this.barcodeReader.ListChanged += new System.ComponentModel.ListChangedEventHandler(BarcodeReader_ListChanged);
        void BarcodeReader_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
            if (this.barcodeReader.ReaderData.Result == Symbol.Results.SUCCESS)

What you need to pay attention to:
1. Any event that is added to the component becomes available in the form constructor.
2. Based on the IContainer container, the form designer implements a mechanism for freeing memory, including unmanage objects. Accordingly, it’s a sin not to use it. Add the barcode reader object to the container, and the memory will be freed recursively when you close the form that contains the component described here.
How this happens can be understood by opening designer any of the forms created in the constructor and looking at overload:

        private System.ComponentModel.IContainer components = null;
        /// Clean up any resources being used.
        /// true if managed resources should be disposed; otherwise, false.
        protected override void Dispose(bool disposing)
            if (disposing && (components != null))

3. Slightly redefine the read event, saving ourselves from processing data read with errors.

Then it’s the small business: drag the component onto the form:

And add a barcode processing event: To make

sure that the following code is more than enough:

  private void barcodeReader1_OnRead(string Text)

It turned out somewhat messy, and a lot of screenshots. By repeating the above steps, you will learn three things at once:

1. Create and run in debug mode programs for data collection terminals.
2. Understand how to work with a barcode scanner.
3. Learn how to create form components.

I hope this article will help those who have just started to understand programming for TSD, and will make life easier for these people.

github example

Only registered users can participate in the survey. Please come in.

Do you write under TSD?

  • 24.5% Yes 79
  • 61.4% No 198
  • 13.9% I'm not a programmer at all 45

Also popular now: