i m developing a windows application where i need to read the data f开发者_运维百科rom scanners...i know about kyeboards wedge scanners that is to focus on textbox...but this for single user if i want to work with multiple scanners then how do i read??
You can use Microsoft POS for .NET provides .NET applications with simple and consistent interfaces for communicating with well over thirty Point of Service (POS) peripheral devices. The list of devices includes barcode scanners, magnetic stripe readers (MSR), Line Displays, PIN Pads, RFID readers, Biometric readers, receipt printers, cash drawers, and many others. POS for .NET is Microsoft’s implementation of the industry’s Unified Point of Service (UPOS) standard. POS for .NET makes it easy for both Independent Software Vendors and Independent Hardware Vendors to support a broad range of peripherals using Microsoft .NET. In addition, Microsoft POS for .NET provides many advantages to the ISV and end customer above and beyond Unified POS
Microsoft Point of Service for .NET is available as a free download from Microsoft.
The Microsoft.PointOfService
assembly defines programming interface contracts between POS applications and service objects used to interface and control the many devices supported by POS for .NET. Add a reference to this assembly to the project:
Right-click on “References” in the solution explorer, and click “Add Reference…”
In the dialog box that pops up, select the “Browse” tab
Select the reference “Microsoft.PointOfService.dll” file by navigating to the folder "%ProgramFiles%\Microsoft Point Of Service\SDK” where it is contained Click “OK” to add the reference.
then add using
statement to your class like this
using Microsoft.PointOfService;
using System.Collections;
then you can write your methods like this:
private void ActivateScanner(DeviceInfo selectedScanner)
{
//Verify that the selectedScanner is not null
// and that it is not the same scanner already selected
if (selectedScanner != null && !selectedScanner.IsDeviceInfoOf(activeScanner))
{
// Configure the new scanner
DeactivateScanner();
// Activate the new scanner
UpdateEventHistory(string.Format(Activate Scanner: {0}",
selectedScanner.ServiceObjectName));
try
{
activeScanner = (Scanner)explorer.CreateInstance(selectedScanner);
activeScanner.Open();
activeScanner.Claim(1000);
activeScanner.DeviceEnabled = true;
activeScanner.DataEvent += newDataEventHandler(activeScanner_DataEvent);
activeScanner.ErrorEvent += new DeviceErrorEventHandler(
activeScanner_ErrorEvent);
activeScanner.DecodeData = true;
activeScanner.DataEventEnabled = true;
}
catch (PosControlException)
{
// Log error and set the active scanner to none
UpdateEventHistory(string.Format(Activation Failed: {0}",
selectedScanner.ServiceObjectName));
activeScanner = null;
}
}
N.B. You can find a well written tutorial on POS for .NET here
hope this helps :)
If scanners act as HID-device, what means that they just send symbols as they were typed on keyboard, then you won't be able to understand, from what scanner has this symbol came from. Moreover you even won't be able to understand whether user typed anything on keyboard or scanner sent some symbol to you, it just appears.
Almost every barcode scanner has it's own protocol, commonly it's quite simple and it allows to communicate via Serial port. You just have to implement that protocol. Sometimes several scanners (from different vendors) use same protocol, in that case it would be easier to support them.
Some barcode scanners support different modes of communicating with host, i.e. they can communicate via serial port (that is the preferred way in your case), or they can act as HID-device (what is not suitable for your case), and there some other options. Modes can be changed programmatically, or by using special barcodes shipped with barcode manual. Refer to your barcode manual to clarify it.
depends on the scanner and its API. If it just emulates a keyboard, you're going to have a hard time. Try to check the API to see if it's supports opening a stream, maybe like a serial port or something. This way, you can open each scanner separately and read from each as necessary.
Let's hope the scanners you have can be opened as separate input streams.
精彩评论