1

Topic: HidSharp issue - debian/windows

Hi,

thanks for a great platform. I have a C# program which I want to use on a windows and linux platform.
It get data from a HID-device by sending a series of bytes and then receiving data back.
It works great on windows 10, but I am having some issues on linux.
Below you see the communication. I send 6 bytes (00-00-00-00-01-58) (hex values) and get data back ... but only on windows, not on linux.
I have set up the permission in the .rules and I have managed to get some communication with the HID, so I am pretty sure it is not a permission issue.

I am using the latest version hidsharp,  2.0.1 from nuget.

Any ideas?

thanks,


Christian

--- executed on win10 pc ---
28/04/2018 15.54.36 - Device found: HidSharp.Platform.Windows.WinHidDevice
28/04/2018 15.54.41 - 00-00-00-00-01-58
28/04/2018 15.54.41 - 00-41-42-43-3C-04-02-31-48-7C-5C-5E-26-7C-7C-75-4E-46-4A-37-52-7C-42-61-79-65-72-36-32-31-30-5E-30-31-2E-31-32-5C-30-31-2E-30-34-5C-32-35-2E-32-35-5C-30-31-2E-30-30-2E-41-5E-36-32-31-33-2D-31-30
28/04/2018 15.54.41 - 00-41-42-43-3C-30-31-36-38-37-5E-30-30-30-30-2D-5E-42-47-31-30-30-31-36-38-37-42-7C-41-3D-30-5E-43-3D-32-32-5E-47-3D-64-61-2C-65-6E-5C-61-72-5C-7A-68-5C-68-72-5C-63-73-5C-64-61-5C-6E-6C-5C-66-69
.......

--- executed on raspberry pi zero with debian (stretch) on mono (all updated) ---
28/04/2018 15:53:09 - Device found: HidSharp.Platform.Linux.LinuxHidDevice
28/04/2018 15:53:14 - 00-00-00-00-01-58
28/04/2018 15:53:24 - Error: timeout

2 (edited by cfaag 2018-04-28 23:24:54)

Re: HidSharp issue - debian/windows

further information:

I use the following void to send data. It seems that the asyncresult.iscompleted never get set to "true". (on Linux)

       public void SendBytes(byte[] message)
        {
            HidStream hidStream;

            if (Device != null && Device.TryOpen(out hidStream))
            {
                hidStream.ReadTimeout = 10000; 
                using (hidStream)
                {
                    hidStream.Write(message);
                    IAsyncResult ar = null;
                 
                    while (true)
                    {
                        if (ar == null)
                        {
                           
                            ar = hidStream.BeginRead(inputReportBuffer, 0, inputReportBuffer.Length, null, null);
                        }
                        if (ar != null)
                        {
                           
                            if (ar.IsCompleted)
                            {
                                int byteCount = hidStream.EndRead(ar);
                                ar = null;

                                if (byteCount > 0)
                                {
                                    var bytes = inputReportBuffer.Take(byteCount).ToArray();
                                   
                                    DataReceived?.Invoke(this, bytes);
                                }
                            }
                            else
                            {
                                ar.AsyncWaitHandle.WaitOne(1000);
                            }
                        }

                        if (DoneReceived)
                        {
                            break;
                        }
                    }
                }
            }
            return;

        }

3 (edited by cfaag 2018-04-29 00:43:27)

Re: HidSharp issue - debian/windows

a suspicion: Could it be an encoding issue?

I am sending '0-0-0-1-X' as bytes.

4

Re: HidSharp issue - debian/windows

You are sending on Report ID 0, indicating the device does not use Report IDs. So the output report is fixed-length.

What does GetMaxOutputReportLength() return? Make sure all of your packets are that length.

5 (edited by cfaag 2018-04-30 10:11:13)

Re: HidSharp issue - debian/windows

Hi Zer,

I have taken the info (as in your example) for the device on windows and on Linux below.

All packets from the device response is always 65 in length. The GetMaxOutputReportLength is in this line: Max Lengths: Input 65, Output 65, Feature 0

Linux:

Complete device list (took 781 ms to get 1 devices):
/sys/devices/platform/soc/20980000.usb/usb1/1-1/1-1:1.0/0003:1A79:6210.0001/hidraw/hidraw0
Bayer HealthCare LLC Contour Link USB Device 0000000001001687 (VID 6777, PID 25104, version 1.0)
Max Lengths: Input 65, Output 65, Feature 0
Serial Ports: Unknown on this platform.
Report Descriptor:
  06 40 FF 09 01 A1 01 06 FF FF 19 00 29 7F 15 00 25 7F 75 08 95 40 81 02 06 FF FF 19 00 29 7F 15 00 25 7F 75 08 95 40 91 02 C0 (42 bytes)
  UsagePage 65344
  Usage 1
  Collection 1
    UsagePage 65535
    UsageMinimum 0
    UsageMaximum 127
    LogicalMinimum 0
    LogicalMaximum 127
    ReportSize 8
    ReportCount 64
    Input 2
    UsagePage 65535
    UsageMinimum 0
    UsageMaximum 127
    LogicalMinimum 0
    LogicalMaximum 127
    ReportSize 8
    ReportCount 64
    Output 2
  EndCollection 0
Usage: FF400001 4282384385
Input: ReportID=0, Length=65, Items=1
  64 Elements x 8 Bits, Units: None, Expected Usage Type: 0, Flags: Variable, Usages: FFFF0000 4294901760, FFFF0001 4294901761, FFFF0002 4294901762, FFFF0003 4294901763, FFFF0004 4294901764, FFFF0005 4294901765, FFFF0006 4294901766, FFFF0007 4294901767, FFFF0008 4294901768, FFFF0009 4294901769, FFFF000A 4294901770, FFFF000B 4294901771, FFFF000C 4294901772, FFFF000D 4294901773, FFFF000E 4294901774, FFFF000F 4294901775, FFFF0010 4294901776, FFFF0011 4294901777, FFFF0012 4294901778, FFFF0013 4294901779, FFFF0014 4294901780, FFFF0015 4294901781, FFFF0016 4294901782, FFFF0017 4294901783, FFFF0018 4294901784, FFFF0019 4294901785, FFFF001A 4294901786, FFFF001B 4294901787, FFFF001C 4294901788, FFFF001D 4294901789, FFFF001E 4294901790, FFFF001F 4294901791, FFFF0020 4294901792, FFFF0021 4294901793, FFFF0022 4294901794, FFFF0023 4294901795, FFFF0024 4294901796, FFFF0025 4294901797, FFFF0026 4294901798, FFFF0027 4294901799, FFFF0028 4294901800, FFFF0029 4294901801, FFFF002A 4294901802, FFFF002B 4294901803, FFFF002C 4294901804, FFFF002D 4294901805, FFFF002E 4294901806, FFFF002F 4294901807, FFFF0030 4294901808, FFFF0031 4294901809, FFFF0032 4294901810, FFFF0033 4294901811, FFFF0034 4294901812, FFFF0035 4294901813, FFFF0036 4294901814, FFFF0037 4294901815, FFFF0038 4294901816, FFFF0039 4294901817, FFFF003A 4294901818, FFFF003B 4294901819, FFFF003C 4294901820, FFFF003D 4294901821, FFFF003E 4294901822, FFFF003F 4294901823, FFFF0040 4294901824, FFFF0041 4294901825, FFFF0042 4294901826, FFFF0043 4294901827, FFFF0044 4294901828, FFFF0045 4294901829, FFFF0046 4294901830, FFFF0047 4294901831, FFFF0048 4294901832, FFFF0049 4294901833, FFFF004A 4294901834, FFFF004B 4294901835, FFFF004C 4294901836, FFFF004D 4294901837, FFFF004E 4294901838, FFFF004F 4294901839, FFFF0050 4294901840, FFFF0051 4294901841, FFFF0052 4294901842, FFFF0053 4294901843, FFFF0054 4294901844, FFFF0055 4294901845, FFFF0056 4294901846, FFFF0057 4294901847, FFFF0058 4294901848, FFFF0059 4294901849, FFFF005A 4294901850, FFFF005B 4294901851, FFFF005C 4294901852, FFFF005D 4294901853, FFFF005E 4294901854, FFFF005F 4294901855, FFFF0060 4294901856, FFFF0061 4294901857, FFFF0062 4294901858, FFFF0063 4294901859, FFFF0064 4294901860, FFFF0065 4294901861, FFFF0066 4294901862, FFFF0067 4294901863, FFFF0068 4294901864, FFFF0069 4294901865, FFFF006A 4294901866, FFFF006B 4294901867, FFFF006C 4294901868, FFFF006D 4294901869, FFFF006E 4294901870, FFFF006F 4294901871, FFFF0070 4294901872, FFFF0071 4294901873, FFFF0072 4294901874, FFFF0073 4294901875, FFFF0074 4294901876, FFFF0075 4294901877, FFFF0076 4294901878, FFFF0077 4294901879, FFFF0078 4294901880, FFFF0079 4294901881, FFFF007A 4294901882, FFFF007B 4294901883, FFFF007C 4294901884, FFFF007D 4294901885, FFFF007E 4294901886, FFFF007F 4294901887
Output: ReportID=0, Length=65, Items=1
  64 Elements x 8 Bits, Units: None, Expected Usage Type: 0, Flags: Variable, Usages: FFFF0000 4294901760, FFFF0001 4294901761, FFFF0002 4294901762, FFFF0003 4294901763, FFFF0004 4294901764, FFFF0005 4294901765, FFFF0006 4294901766, FFFF0007 4294901767, FFFF0008 4294901768, FFFF0009 4294901769, FFFF000A 4294901770, FFFF000B 4294901771, FFFF000C 4294901772, FFFF000D 4294901773, FFFF000E 4294901774, FFFF000F 4294901775, FFFF0010 4294901776, FFFF0011 4294901777, FFFF0012 4294901778, FFFF0013 4294901779, FFFF0014 4294901780, FFFF0015 4294901781, FFFF0016 4294901782, FFFF0017 4294901783, FFFF0018 4294901784, FFFF0019 4294901785, FFFF001A 4294901786, FFFF001B 4294901787, FFFF001C 4294901788, FFFF001D 4294901789, FFFF001E 4294901790, FFFF001F 4294901791, FFFF0020 4294901792, FFFF0021 4294901793, FFFF0022 4294901794, FFFF0023 4294901795, FFFF0024 4294901796, FFFF0025 4294901797, FFFF0026 4294901798, FFFF0027 4294901799, FFFF0028 4294901800, FFFF0029 4294901801, FFFF002A 4294901802, FFFF002B 4294901803, FFFF002C 4294901804, FFFF002D 4294901805, FFFF002E 4294901806, FFFF002F 4294901807, FFFF0030 4294901808, FFFF0031 4294901809, FFFF0032 4294901810, FFFF0033 4294901811, FFFF0034 4294901812, FFFF0035 4294901813, FFFF0036 4294901814, FFFF0037 4294901815, FFFF0038 4294901816, FFFF0039 4294901817, FFFF003A 4294901818, FFFF003B 4294901819, FFFF003C 4294901820, FFFF003D 4294901821, FFFF003E 4294901822, FFFF003F 4294901823, FFFF0040 4294901824, FFFF0041 4294901825, FFFF0042 4294901826, FFFF0043 4294901827, FFFF0044 4294901828, FFFF0045 4294901829, FFFF0046 4294901830, FFFF0047 4294901831, FFFF0048 4294901832, FFFF0049 4294901833, FFFF004A 4294901834, FFFF004B 4294901835, FFFF004C 4294901836, FFFF004D 4294901837, FFFF004E 4294901838, FFFF004F 4294901839, FFFF0050 4294901840, FFFF0051 4294901841, FFFF0052 4294901842, FFFF0053 4294901843, FFFF0054 4294901844, FFFF0055 4294901845, FFFF0056 4294901846, FFFF0057 4294901847, FFFF0058 4294901848, FFFF0059 4294901849, FFFF005A 4294901850, FFFF005B 4294901851, FFFF005C 4294901852, FFFF005D 4294901853, FFFF005E 4294901854, FFFF005F 4294901855, FFFF0060 4294901856, FFFF0061 4294901857, FFFF0062 4294901858, FFFF0063 4294901859, FFFF0064 4294901860, FFFF0065 4294901861, FFFF0066 4294901862, FFFF0067 4294901863, FFFF0068 4294901864, FFFF0069 4294901865, FFFF006A 4294901866, FFFF006B 4294901867, FFFF006C 4294901868, FFFF006D 4294901869, FFFF006E 4294901870, FFFF006F 4294901871, FFFF0070 4294901872, FFFF0071 4294901873, FFFF0072 4294901874, FFFF0073 4294901875, FFFF0074 4294901876, FFFF0075 4294901877, FFFF0076 4294901878, FFFF0077 4294901879, FFFF0078 4294901880, FFFF0079 4294901881, FFFF007A 4294901882, FFFF007B 4294901883, FFFF007C 4294901884, FFFF007D 4294901885, FFFF007E 4294901886, FFFF007F 4294901887
Opening device for 20 seconds...
encoding: Unicode (UTF-8)


Windows

Complete device list (took 229 ms to get 1 devices):
\\?\hid#vid_1a79&pid_6210#6&21757738&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
Bayer HealthCare LLC Contour Link USB Device 0000000001001687 (VID 6777, PID 25104, version 1.0)
Max Lengths: Input 65, Output 65, Feature 0
Serial Ports:
Report Descriptor:
  06 40 FF 09 01 A1 01 15 00 25 01 35 00 45 01 65 00 55 00 75 01 96 00 02 81 03 91 03 C1 00 (30 bytes)
  UsagePage 65344
  Usage 1
  Collection 1
    LogicalMinimum 0
    LogicalMaximum 1
    PhysicalMinimum 0
    PhysicalMaximum 1
    Unit 0
    UnitExponent 0
    ReportSize 1
    ReportCount 512
    Input 3
    Output 3
  EndCollection 0
Usage: FF400001 4282384385
Input: ReportID=0, Length=65, Items=1
  512 Elements x 1 Bits, Units: None, Expected Usage Type: 0, Flags: Constant, Variable, Usages:
Output: ReportID=0, Length=65, Items=1
  512 Elements x 1 Bits, Units: None, Expected Usage Type: 0, Flags: Constant, Variable, Usages:
Opening device for 20 seconds...
encoding: Western European (Windows)

6 (edited by cfaag 2018-04-30 10:00:05)

Re: HidSharp issue - debian/windows

just tried to "fill" the send message with 0's to make the message length 65. No luck. (but it works on windows)

30/04/2018 17:02:32 - Device found: Contour Link USB Device
30/04/2018 17:02:33 - Device found2: HidSharp.Platform.Linux.LinuxHidDevice
30/04/2018 17:02:38 - Getting CNL deviceInformation
30/04/2018 17:02:39 - writing: 00-00-00-00-01-58-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00

7

Re: HidSharp issue - debian/windows

Hmm. Is this the device?

https://smile.amazon.com/Contour-Next-W … +next+link

Thinking I could just order one and try it to debug. The Linux hidraw API is straightforward, so this will likely be a quite obvious bug. Is the protocol documented (or is the byte sequence you mentioned earlier sufficient to get a response in all cases)?

Thanks!

James

8 (edited by cfaag 2018-05-01 22:58:19)

Re: HidSharp issue - debian/windows

hi James,

thank you so much for your help. The link is not the correct version of the device. It should be version 2.4 (the protocol is very different). The protocol is not official documented but the Nightscout community have figured it out (see here for info about nightscout wiki: https://en.wikipedia.org/wiki/Nightscout). So I can send you the full protocol, but the X-message should be sufficient to verify it works.

Maybe it is easier to walk me through how you debug on Linux than you buying the device.

You are more than welcome to write directly to my email if you want to take the conversation off-forum.

Thanks
Christian

ps later today I am going to try it on a raspberry pi 3, just make sure it is not a hardware thing on the zero.

9

Re: HidSharp issue - debian/windows

I think I found the problem. I had not noticed the difference in read() versus write() in the Linux hidraw API specification when Report IDs are not used.

I've posted a test version at:
https://www.zer7.com/HidSharp.dll

Let me know if it works! If so I'll make an update.

10

Re: HidSharp issue - debian/windows

BINGO!!!!!

It works!

Thank you so much. I will let you know my progress in the project.

Thank you again for the great support.

Best regards
Christian

Log now:
pi@raspberrypi:~/CGM $ mono CGM.Console.exe
05/05/2018 22:00:50 - Device found: Contour Link USB Device
05/05/2018 22:00:50 - Device found2: HidSharp.Platform.Linux.LinuxHidDevice
05/05/2018 22:00:56 - Getting CNL deviceInformation
05/05/2018 22:00:56 - 00-00-00-00-01-58
05/05/2018 22:00:57 - Write to hidstream: 00-00-00-00-01-58
05/05/2018 22:00:57 - 00-41-42-43-3C-04-02-31-48-7C-5C-5E-26-7C-7C-6D-30-4E-43-75-34-7C-42-61-79-65-72-36-32-31-30-5E-30-31-2E-31-32-5C-30-31-2E-30-34-5C-32-35-2E-32-35-5C-30-31-2E-30-30-2E-41-5E-36-32-31-33-2D-31-30
05/05/2018 22:00:57 - 00-41-42-43-3C-30-31-36-38-37-5E-30-30-30-30-2D-5E-42-47-31-30-30-31-36-38-37-42-7C-41-3D-30-5E-43-3D-32-32-5E-47-3D-64-61-2C-65-6E-5C-61-72-5C-7A-68-5C-68-72-5C-63-73-5C-64-61-5C-6E-6C-5C-66-69

11

Re: HidSharp issue - debian/windows

Great! Let me know how it goes.

I've posted HIDSharp 2.0.2 on my site and NuGet.

By the way, be sure to pad the output report to the correct length. (65 bytes total -- 1 for the Report ID (always 0 on that device), and 64 for the data.) HID is packetized so it won't save bandwidth not to do it, and I don't want to inadvertently break your code if a bug fix makes "happens to work" no longer be the case.

Have a good weekend smile

James