Programming a Laser Scanner on Motorola (Symbol) Data Collection Terminals in C#
I've long wanted to write a guide like this, but somehow never had the time, and finally wrote it, with a whole lot of work involved... Those who want to cram 1C (even on a terminal) using DataWedge (a utility for sending what the scanner reads to the keyboard buffer, specialized for TSD Symbol) can stop reading and do something else that they enjoy. I won't convert anyone to my faith :).
So, what will I demonstrate here? I will show a small example of how to use the scanning device on the data collection terminal (Symbol Motorola) in your application, tell you what you need to do this, and provide an example code.
Let's get started.
First thing you'll need is Visual Studio 2008 (not lower than Prof) - it has support for Smart Devices (simpler to develop for mobile devices).
Second thing you'll need is the SDK from Motorolla (it's called EMDK - Enterprise Mobility Developer Kit, the old version was called SMDK - Symbol Mobility Developer Kit), find the latest version on their website now it's EMDK for .NET v2.4, download, install. After installation, you can select in References - Symbol and Symbol.Barcode, they are what you need. You can simply add them through search in the project and that will be enough.
Last version of EMDK - necessary if you want your application to work on new devices (such as MC3190), but you should consider that the latest versions of libraries will not work on old devices with Win CE 4.2, for their programming you will have to choose an older SDK.
EMDK - allows you to do many things, including setting up the scanner, reading or not reading various types of barcodes and how to do it, but I don't see any particular sense in this for most needs, the default settings are sufficient. And if any specific settings are needed, then with each TSD Motorola (Symbol) comes a utility for setting up the scanner, it's easier to use it than writing your own and wasting precious time.
Third - create your own application that reads a barcode.
In the studio, create a 'Smart Device Project', add the Symbol and Symbol.Barcode libraries as before.
Put a text field on the form and a button (with it we will turn off the scanner and exit the application), turn on the scanner when the application loads.
Source code:
//Читает ШК SYMBOL.
private Symbol.Barcode.BarcodeReader barcode_reader = new Symbol.Barcode.BarcodeReader();
//Процедура работает при получении новых данных со считывателя.
void reader_ListChanged(object sender, ListChangedEventArgs e)
{
Symbol.Barcode.ReaderData nextReaderData = barcode_reader.ReaderData;
if (nextReaderData.Result == Symbol.Results.SUCCESS)
{
//Помещаем полученное значение в текстовое поле
textBox1.Text = nextReaderData.Text;
}
else
{
textBox1.Text = "Формат считанного Штрихового Кода - не распознан!";
//Проигрываем звук - ненайденного ШК
System.Media.SystemSounds.Exclamation.Play();
System.Media.SystemSounds.Asterisk.Play();
System.Media.SystemSounds.Exclamation.Play();
System.Media.SystemSounds.Asterisk.Play();
}
}
//При загрузке формы.
private void Form1_Load(object sender, EventArgs e)
{
//Создаем событие на чтение ШК сканером...
barcode_reader.ListChanged += new ListChangedEventHandler(reader_ListChanged);
barcode_reader.Start();
}
//Закрываем приложение.
private void button1_Click(object sender, EventArgs e)
{
//При закрытии не забыть остановить и очистить, иначе повиснет.
barcode_reader.Stop();
barcode_reader.Dispose();
this.Dispose();
Application.Exit();
}
!!! It's very important to stop the scanner and clear memory when closing the application.
On new devices, under Windows CE 6.0 especially, even a simple exit from the application Application.Exit() without this.Dispoce() can lead to device freezing.
That's all.
Download the source code example:
motorolasdktest.rar · 20 downloads
P.S. One more nuance, may be useful to someone. When creating applications for TSD (Motorola, I'm sure, but I don't guarantee for others), it's better to make a white font on a black background, experience has shown that there is a saving of battery power of about 25-30%.
- motorolasdktest.rar 250.3 KB 20 downloads
Comments (0)
No comments yet.