views:

358

answers:

2

I have a barcode scanner from Metro Technologies and I am using Microsoft POS to detect the input from the scanner. It is connected to my system using USB port. But the scanner is not getting identified by the POS.

public Form1()
{
InitializeComponent();
explorer = new PosExplorer(this);
explorer.DeviceAddedEvent += new
DeviceChangedEventHandler(explorer_DeviceAddedEvent);
}


void explorer_DeviceAddedEvent(object sender, DeviceChangedEventArgs e)
{
if (e.Device.Type == "Scanner")
{
scanner = (Scanner)explorer.CreateInstance(e.Device);
scanner.Open();
scanner.Claim(1000);
scanner.DeviceEnabled = true;
scanner.DataEvent += new
DataEventHandler(activeScanner_DataEvent);
scanner.DataEventEnabled = true;
scanner.DecodeData = true;
}
}

void activeScanner_DataEvent(object sender, DataEventArgs e)
{
UpdateEventHistory("Data Event");
ASCIIEncoding encoder = new ASCIIEncoding();
try
{
// Display the ASCII encoded label text
txtbScanDataLabel.Text =
encoder.GetString(activeScanner.ScanDataLabel);
// Display the encoding type
txtbScanDataType.Text = activeScanner.ScanDataType.ToString();

// re-enable the data event for subsequent scans
activeScanner.DataEventEnabled = true;
}
catch (PosControlException)
{
// Log any errors
UpdateEventHistory("DataEvent Operation Failed");
}
}
A: 

I'm not familiar with the scanner you are using, but with all that I've worked with before you generally want to make sure that the scanner itself is configured for the correct mode/settings/etc. Usually this is done by going through a configuration sequence that's in the manual where you'll scan various barcodes that program the device.

If nothing else you can rule out an issue with the hardware config as opposed to your code.

Does the explorer_DeviceAddedEvent ever fire?

Where are scanner and activeScanner initialized?

[EDIT]

Check the scanner itself or the docs that came with it for a Hardware ID (HID), try adding the following line to your code.

[HardwareId(@"this is where the HID goes")]

See if that gets you any further...see here for more info, you can provide the HID or add that info in an XML config file

curtisk
The event explorer_DeviceAddedEvent is not firing. So it is never reaching the code where the scanner object is created.Does the scanner needs to be configured in a specific way for it to work with Microsoft POS?
Ragha J
post the rest of code please, even the using statements
curtisk
Posted the entire code below
Ragha J
A: 

Here is the entire code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.PointOfService;
using System.Collections;

namespace MicrosoftPOSScannerSample
{
    public partial class Form1 : Form
    {
        private PosExplorer explorer;
     private Scanner scanner;

        public Form1()
        {
            InitializeComponent();
            explorer = new PosExplorer(this);
            explorer.DeviceAddedEvent += new DeviceChangedEventHandler(explorer_DeviceAddedEvent);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
     }

     private void UpdateEventHistory(string newEvent)
        {
            txtbEventHistory.Text = newEvent + System.Environment.NewLine + txtbEventHistory.Text;
        }

        void explorer_DeviceAddedEvent(object sender, DeviceChangedEventArgs e)
        {
            if (e.Device.Type == "Scanner")
            {
                scanner = (Scanner)explorer.CreateInstance(e.Device);
                scanner.Open();
                scanner.Claim(1000);
                scanner.DeviceEnabled = true;
                scanner.DataEvent += new DataEventHandler(scanner_DataEvent);
                scanner.DataEventEnabled = true;
                scanner.DecodeData = true;
            }
        }

     void scanner_DataEvent(object sender, DataEventArgs e)
        {
            UpdateEventHistory("Data Event");
            ASCIIEncoding encoder = new ASCIIEncoding();
            try
            {
                // Display the ASCII encoded label text
                txtbScanDataLabel.Text = encoder.GetString(scanner.ScanDataLabel);
                // Display the encoding type
                txtbScanDataType.Text = scanner.ScanDataType.ToString();

                // re-enable the data event for subsequent scans
                scanner.DataEventEnabled = true;
            }
            catch (PosControlException)
            {
                // Log any errors
                UpdateEventHistory("DataEvent Operation Failed");
            }
        }

    }
}
Ragha J
updated main answer with more info to try
curtisk