📜 ⬆️ ⬇️

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

It is not a secret for anyone 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 the TSD are related to barcoding, 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 experimental model Motorola MC3190 has a laser barcode scanner. (In the near future I plan to do a tight Datalogic c imager).

For those interested, you can familiarize yourself with the specification .

The device has Windows CE installed, respectively, and it will be necessary to write for it. And if you have never tried to write under the 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 the Smart Device project version is missing (small-scale ones like to impose their new technologies, which, unfortunately, are not always compatible with earlier versions of their operating system).



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




Now you can get down 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 whatever we want. This miracle is called Symbol. In our case, Symbol.Barcode will be used. Unfortunately, at the moment, the official site of the symbol.com library redirects us to motorolasolutions.com, reporting that the technology is outdated. But I once made copies of all Reference with examples:

cloud.mail.ru/public/6716403f96ac%2FSymbolReference.7z
cloud.mail.ru/public/c48120476007%2FSymbolExample.7z

In the examples, those who are interested can, of course, rummage, but I can immediately warn you that there are articles describing everything much easier and more convenient, in my opinion, the best among them: kbss.ru/blog/dotnetcf/178.html . But, nevertheless, I believe that connecting the barcode scanner is not very convenient every time, especially if the application is planned to be multi-windowed. 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 handle bar codes is a model built on the events:
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 convenient for perception.

The form component is a pattern that allows you to add your control to the form designer of the studio. 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 further developed so that it supports scanners not only from Motorol `s.



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() { InitializeComponent(); InitializeBarcodeReader(); } public BarcodeReader(IContainer container) { container.Add(this); InitializeComponent(); InitializeBarcodeReader(); } private void InitializeBarcodeReader() { this.barcodeReader = new Symbol.Barcode.BarcodeReader(); this.barcodeReader.ListChanged += new System.ComponentModel.ListChangedEventHandler(BarcodeReader_ListChanged); this.barcodeReader.Start(); this.components.Add(this.barcodeReader); } void BarcodeReader_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e) { if (this.barcodeReader.ReaderData.Result == Symbol.Results.SUCCESS) { OnRead(this.barcodeReader.ReaderData.Text); } } } 


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

  private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } 

//
3. We slightly redefine the read event, freeing ourselves from processing the data read with errors.

Then it’s easy to do: 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) { MessageBox.Show(Text); } 


It turned out a bit messy, and a lot of screenshots. 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 begun to deal with programming under the TSD, and will somewhat simplify the lives of these people.

github example

Source: https://habr.com/ru/post/235869/


All Articles