Hi.
My company makes use of Motorola scanners to scan barcodes into the system through a C# application. A driver (Symbol COM Port Emulation Driver v 1.8.5) has been installed on the computers to make the scanner behave as simple COM Port Emulation and when the barcode is scanned, we are able to capture the text serially through the serialPort_DataReceived event.
The application works fine on Windows XP and but does not work on Windows 7 64 bits as the Symbol COM Port Emulation Driver is not compatible. I have contacted Motorola for support and the response was to send all our devices to upgrade the firmware. Now this is a bit difficult as we have about 100 scanners in production.
I am looking for ways to modify the C# application to read the data and process the string serially. I have been trying to implement the way described at this link: http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/
but it is quite complicated. So I looked for another simple way (http://csharp.simpleserial.com) but here also I get an issue. The problem is though I am able to scan the barcode in the textbox, the serialPort1_DataReceived event is not trigerring.
Can you please advise if I am missing something?
Thanks and Regards,
kirtee

public partial class Form1 : Form
    {
        // Add this variable 
        string RxString;
        StringBuilder stringBuilder;

        public Form1()
        {
            InitializeComponent();
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            serialPort1.PortName = "COM1";
            serialPort1.BaudRate = 9600;

            serialPort1.Open();
            if (serialPort1.IsOpen)
            {
                buttonStart.Enabled = false;
                buttonStop.Enabled = true;
                textBox1.ReadOnly = false;
            }

            stringBuilder = new StringBuilder();
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
            {
                serialPort1.Close();
                buttonStart.Enabled = true;
                buttonStop.Enabled = false;
                textBox1.ReadOnly = true;
            }

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (serialPort1.IsOpen) serialPort1.Close();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            // If the port is closed, don't try to send a character.
            if (!serialPort1.IsOpen) return;

            // If the port is Open, declare a char[] array with one element.
            char[] buff = new char[1];

            // Load element 0 with the key character.
            buff[0] = e.KeyChar;

            // Send the one character buffer.
            serialPort1.Write(buff[0].ToString());

            //serialPort1_DataReceived(sender, e.KeyChar);

            // Set the KeyPress event as handled so the character won't
            // display locally. If you want it to display, omit the next line.
            //e.Handled = true;
        }

        private void DisplayText(object sender, EventArgs e)
        {
            textBox1.AppendText(RxString);
        }

        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            RxString = serialPort1.ReadExisting();
            this.Invoke(new EventHandler(DisplayText));
        }

Unfortunately, there's nothing communicating over your COM1 port. However, you might be able to get a list of the com ports available on your machine and then select the correct one for your device.

SerialPort.GetPortNames will return a list of com ports to you. But you might need to do some registry queries to get the right com port by the vendor and device id.

Otherwise, you will have to treat your scanner as a Keyboard emulator (probably the default mode) and make sure that the relevant text boxes are focussed when a scan takes place.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.