Click here to Skip to main content
15,881,424 members
Articles / Programming Languages / C#
Article

Barcode Scanning on Motorola, Intermec and Psion

3 May 2012CPOL2 min read 23.3K   12   2
Resco offers classes that create universal interface that can access barcode scanners of various devices. This means that one application will be able to scan barcodes from different devices.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

In the earlier days the logistics and warehouseing was much simpler than today. Each item was handpicked and moved to another location. People were using standard cashiers or just a pen and a piece of paper to keep the lists of inventories. Those days are just gone!

Today everything needs to be done quickly. Customer places order and items need to be shipped almost immediately. Goods arrive to warehouse and warehouse manager needs to know where to place them. He also needs to add them to his inventory. Barcodes can rapidly speed up the logistics of the company. You simply scan a single code and you will access various information that you need to make the decision.

Until now the developers needed to create separate application for each device. Now, Resco offers classes that create universal interface that can access barcode scanners of various devices. This means that one application will be able to scan barcodes from different devices. We support:

  • Symbol - Motorola
  • Intermec
  • Psion

All you need to do is to download SDK of device manufacturers. You can find them here:

Here is the sample code that will help you to handle the barcode scanning on any type of device:

C#
private TagReader m_tagReader = null;

//new TagReader instance for current DeviceType
m_tagReader = BarcodeMgr.CreateInstance();

//this event triggered when a barcode is read
m_tagReader.TagRead += new EventHandler<TagEventArgs>(m_tagReader_TagRead);

private void m_tagReader_TagRead(object sender, TagEventArgs e)
{
	//statement to call if the HandleBarCode method is in the same thread
	if (this.InvokeRequired)
	this.Invoke(new Action(m_tagReader_TagRead), sender, e);
	else
	HandleBarCode(e.Text);
}

private void HandleBarCode(string code)
{
	//TO DO: Here you can add a code for the barcode handling 
	uiTextBoxProductID.Text = code;
}

How to add another miscellaneous scanning devices

If you need to add another type of device that is not yet supported by our barcode scanning interface, you can simply follow these steps (Please note that just for an example, we demonstrated how to add Opticon device):

  1. Open the BarCodeMgr class.
  2. Add to the BarCodeReaderDeviceType enum new "Opticon" option.
  3. Add into the CreateInstance method new Opticon deviceType. It should look as follows:
C#
/// <summary>
/// Creates and initializes a new <see cref="TagReader"/> instance.
/// </summary>
public static TagReader CreateInstance()
{
	BarCodeReaderDeviceType deviceType = BarCodeReaderDeviceType.None;
	
	if (BarCodeUtil.IsSymbolDevice())
		deviceType = BarCodeReaderDeviceType.Symbol;
	else if (BarCodeUtil.IsIngenicoDevice())
		deviceType = BarCodeReaderDeviceType.Ingenico;
	else if (BarCodeUtil.IsPsionDevice())
		deviceType = BarCodeReaderDeviceType.Psion;
	
	// ******************** START Custom Code
	else if (BarCodeUtil.IsOpticonDevice())
		deviceType = BarCodeReaderDeviceType.Opticon;
	// ******************** END Custom Code
	
	else
		deviceType = BarCodeReaderDeviceType.Intermec;
	
	string className = null;
	switch(deviceType)
	{
	// ******************** START Custom Code
		case BarCodeReaderDeviceType.Opticon:
        	className = "UIOptionView.BarCodeReaderOpticon";
			break;
	// ******************** END Custom Code

		case BarCodeReaderDeviceType.Symbol:
			className = "UIOptionView.BarCodeReaderSymbol";
			break;
		
		case BarCodeReaderDeviceType.Intermec:
			className = "UIOptionView.BarCodeReaderIntermec";
			break;
		
		case BarCodeReaderDeviceType.Ingenico:
			className = "UIOptionView.BarCodeReaderIngenico";
			break;
		
		case BarCodeReaderDeviceType.Psion:
			className = "UIOptionView.BarCodeReaderPsion";
			break;
		
		default:
			case BarCodeReaderDeviceType.None:
			break;
	}

	// if no device detected return null
	if (string.IsNullOrEmpty(className))
		return null; //throw new NotSupportedException("BarCode Reader not supported on that device");
	
	// get device bar code reader
	#if DEBUG
	TagReader reader;
	try
	{
		reader = (TagReader)Activator.CreateInstance(Type.GetType(className));
	}
	catch
	{
		reader = new BarCodeReaderDebug();
	}
	reader.IsEnabled = true;
	#else
	var reader = (TagReader)Activator.CreateInstance(Type.GetType(className));
	reader.IsEnabled = true;
	#endif
	return reader;
}
  1. Add into the BarCodeUtil class new IsOpticonDevice method to get whether the device is Opticon.
  2. Now, you need to create your own BarCodeReaderOpticon class. This new class is inherited from the TagReader object.
  3. In this class, you need to override the IsEnabled property to get or set whether barcode reading is enabled.
  4. E.g. check the BarCodeReaderPsion.cs where you can find how to do that.
  5. Into the event, which fires when the device is reading a barcode, call the OnTagRead method.
  6. E.g. check the BarCodeReaderPsion.cs where you can find how to do that.

Barcode scanner sample will be accessible only for users with active subscription.

Product info: http://www.resco.net/developer/mobileformstoolkit/

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Unknown
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questiongood idea and a question Pin
Nicola Tesla22-Jun-17 11:58
Nicola Tesla22-Jun-17 11:58 
Questiongreat idea Pin
RescoDeveloper.Net3-Oct-12 23:56
RescoDeveloper.Net3-Oct-12 23:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.