1 (edited by winters 2018-07-25 23:39:25)

Topic: HidSharp not able to read the device data

Hi, I have a 2D scanner. The device is can be identified correctly, but by some reasons not able to get barcode value from the scanner. I will appreciate it very much if you could give some clues ...
I use HIDSharp20.
In the system it is identified as "HID Keyboard Device".
I use usb scanner YHD-M200

It uses device: "Honeywell Imaging & Mobility     HID POS C0A7AE (VID 3118, PID 2441, version 0.0)".

Output:

   (VID 5102, PID 3, version 0.0)
Dell Dell USB Keyboard ? (VID 16700, PID 8195, version 3.1)
Honeywell Imaging & Mobility     HID POS C0A7AE (VID 3118, PID 2441, version 0.0)
Honeywell Imaging & Mobility     HID Keyboard Emulation C0A7AE (VID 3118, PID 2441, version 0.0)
Honeywell Imaging & Mobility     REM C0A7AE (VID 3118, PID 2441, version 0.0)

Opening HID class device...
HID POS
Max Lengths:
  Input:   64
  Output:  64
  Feature: 2

The operating system name for this device is:
  \\?\hid#vid_0c2e&pid_0989&mi_01#7&24fa9ba&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}

Read timed out.
Read timed out.
Read timed out.
Read timed out.
Read timed out.
Read timed out.
Read timed out.

----------------------------------------------------------

using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;

namespace HidSharp.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            HidDeviceLoader loader = new HidDeviceLoader();
            Thread.Sleep(2000); // Give a bit of time so our timing below is more valid as a benchmark.

            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var deviceList = loader.GetDevices().ToArray();
            stopwatch.Stop();
            long deviceListTotalTime = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("Complete device list (took {0} ms to get {1} devices):",
                              deviceListTotalTime, deviceList.Length);
            foreach (HidDevice dev in deviceList)
            {
                Console.WriteLine(dev);
            }
            Console.WriteLine();

            Console.WriteLine("Opening HID class device...");


            var dtest_evice = loader.GetDevices(3118);
            var device = loader.GetDevices(3118).FirstOrDefault(d => d.ProductName == "HID POS");
            if (device == null) { Console.WriteLine("Failed to open device."); Environment.Exit(1); }
            Console.Write(device.ProductName);
            Console.Write(@"
Max Lengths:
  Input:   {0}
  Output:  {1}
  Feature: {2}

The operating system name for this device is:
  {3}

"
, device.MaxInputReportLength
, device.MaxOutputReportLength
, device.MaxFeatureReportLength
, device.DevicePath
);

            HidStream stream;
            if (!device.TryOpen(out stream)) { Console.WriteLine("Failed to open device."); Environment.Exit(2); }
            StringBuilder sb = new StringBuilder();
            using (stream)
            {
                int n = 0;
                while (true)
                {

                    var bytes = new byte[device.MaxInputReportLength];
                    int count = 0;
                   
                    try
                    {
                        count = stream.Read(bytes, 0, bytes.Length);
                                            }
                    catch (TimeoutException)
                    {
              //          Console.Write(count);
                        Console.WriteLine("Read timed out.");
                        continue;
                    }

                    if (count > 0)
                    {
                        var decoded = Encoding.UTF8.GetString(bytes);
                        if (decoded.IndexOf("\u0002\u0003]Q1\n\r\n\0") >= 0)
                        {
                            Console.WriteLine(sb.ToString());
                            sb.Length = 0;
                        }
                        else
                        {
                            sb.Append(decoded.Replace("\u00028]Q1", "").Replace("s\0\u0001", " "));
                        }
                        Console.WriteLine();
                        if (++n == 100)
                        {
                            break;
                        }
                    }
                }
            }

            Console.WriteLine("Press a key to exit...");
            Console.ReadKey();
        }
    }
}