diff --git a/HidSharp/HidSharp.csproj b/HidSharp/HidSharp.csproj
index 6df10eb..4f67091 100644
--- a/HidSharp/HidSharp.csproj
+++ b/HidSharp/HidSharp.csproj
@@ -17,4 +17,13 @@
Copyright 2010-2019 James Bellinger
+
+ HidSharTestyThingy
+ Exe
+ net8.0
+ hidsharp_list
+
+
+
+
diff --git a/HidSharp/Platform/Linux/LinuxHidDevice.cs b/HidSharp/Platform/Linux/LinuxHidDevice.cs
index d7dc664..efbc013 100644
--- a/HidSharp/Platform/Linux/LinuxHidDevice.cs
+++ b/HidSharp/Platform/Linux/LinuxHidDevice.cs
@@ -56,25 +56,104 @@ internal static LinuxHidDevice TryCreate(string path)
IntPtr device = NativeMethodsLibudev.Instance.udev_device_new_from_syspath(udev, d._path);
if (device != IntPtr.Zero)
{
+ string d_manufacturer = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(device, "manufacturer");
+ string d_productName = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(device, "product");
+ string d_serialNumber = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(device, "serial");
+ string d_idVendor = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(device, "idVendor");
+ string d_idProduct = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(device, "idProduct");
+ string d_bcdDevice = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(device, "bcdDevice");
+ Console.WriteLine();
+ string syspath = NativeMethodsLibudev.Instance.udev_device_get_syspath(device);
+ string devnode = NativeMethodsLibudev.Instance.udev_device_get_devnode(device);
+ Console.WriteLine("device " + devnode + " found device with " + d_manufacturer + d_productName + d_idVendor + d_idProduct);
try
{
- string devnode = NativeMethodsLibudev.Instance.udev_device_get_devnode(device);
if (devnode != null)
{
d._fileSystemName = devnode;
+ IntPtr parent = IntPtr.Zero;
+ string parent_subsystem = null;
//if (NativeMethodsLibudev.Instance.udev_device_get_is_initialized(device) > 0)
{
- IntPtr parent = NativeMethodsLibudev.Instance.udev_device_get_parent_with_subsystem_devtype(device, "usb", "usb_device");
- if (IntPtr.Zero != parent)
- {
- string manufacturer = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "manufacturer");
- string productName = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "product");
- string serialNumber = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "serial");
- string idVendor = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "idVendor");
- string idProduct = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "idProduct");
- string bcdDevice = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent, "bcdDevice");
+ /// show information for all parent devices
+ IntPtr p = device;
+ string devtype = "";
+ string subsystem = "";
+ string p_syspath = "";
+ string p_devnode = "";
+ while (p != IntPtr.Zero) {
+ Console.WriteLine("device " + devnode + " parent " + p + " getting parent of: " + p);
+ p = NativeMethodsLibudev.Instance.udev_device_get_parent(p);
+ devtype = NativeMethodsLibudev.Instance.udev_device_get_devtype(p);
+ subsystem = NativeMethodsLibudev.Instance.udev_device_get_subsystem(p);
+ p_syspath = NativeMethodsLibudev.Instance.udev_device_get_syspath(p);
+ p_devnode = NativeMethodsLibudev.Instance.udev_device_get_devnode(p);
+ // Console.WriteLine("device " + devnode + " parent " + p + " p_syspath is " + p_syspath);
+ // Console.WriteLine("device " + devnode + " parent " + p + " p_devnode is " + p_devnode);
+ Console.WriteLine("device " + devnode + " parent " + p + " subsystem/devtpye is " + subsystem + "/" + devtype);
+ // IntPtr entry = NativeMethodsLibudev.Instance.udev_device_get_properties_list_entry(p);
+ // while (entry != IntPtr.Zero) {
+ // string name = NativeMethodsLibudev.Instance.udev_list_entry_get_name(entry);
+ // string value = NativeMethodsLibudev.Instance.udev_list_entry_get_value(entry);
+ // entry = NativeMethodsLibudev.Instance.udev_list_entry_get_next(entry);
+ // Console.WriteLine("device " + devnode + " parent " + p + " properties " + name + " = " + value);
+ // }
+ }
+
+
+ Console.WriteLine("device " + devnode + " parent is " + parent + " with subsystem " + parent_subsystem);
+
+ // aquire a parent of the hid subsystem, which my pth-660 has when connected to my on my lenovo x13 via bluetooth
+ // maybe take the one that comes first when recursing into the parents
+ IntPtr parent_hid = NativeMethodsLibudev.Instance.udev_device_get_parent_with_subsystem(device, "hid");
+ IntPtr parent_usb = NativeMethodsLibudev.Instance.udev_device_get_parent_with_subsystem_devtype(device, "usb", "usb_device");
+
+ Console.WriteLine("device " + devnode + " parent_hid is " + parent_hid);
+ Console.WriteLine("device " + devnode + " parent_usb is " + parent_usb);
+ string manufacturer = "unknown";
+ string productName = "unknown";
+ string serialNumber = "unknown";
+ string idVendor = "0";
+ string idProduct = "0";
+ string bcdDevice = "0";
+
+ if (IntPtr.Zero != parent_usb) {
+ manufacturer = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent_usb, "manufacturer");
+ productName = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent_usb, "product");
+ serialNumber = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent_usb, "serial");
+ idVendor = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent_usb, "idVendor");
+ idProduct = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent_usb, "idProduct");
+ bcdDevice = NativeMethodsLibudev.Instance.udev_device_get_sysattr_value(parent_usb, "bcdDevice");
+ }
+ // add information to bluetooth devices
+ if (IntPtr.Zero != parent_hid) {
+ IntPtr entry2 = NativeMethodsLibudev.Instance.udev_device_get_properties_list_entry(parent_hid);
+ while (entry2 != IntPtr.Zero) {
+ string name = NativeMethodsLibudev.Instance.udev_list_entry_get_name(entry2);
+ string value = NativeMethodsLibudev.Instance.udev_list_entry_get_value(entry2);
+ entry2 = NativeMethodsLibudev.Instance.udev_list_entry_get_next(entry2);
+ Console.WriteLine("device " + devnode + " parent " + p + " properties " + name + " = " + value);
+ switch (name) {
+ case "HID_NAME":
+ if (productName == "unknown") {
+ productName = value;
+ }
+ break;
+ case "HID_ID":
+ string[] idParts = value.Split(":");
+ if (idVendor == "0") {
+ idVendor = idParts[1];
+ }
+ if (idProduct == "0") {
+ idProduct = idParts[2];
+ }
+ break;
+ }
+ }
+ }
+ if (IntPtr.Zero != parent_hid || IntPtr.Zero != parent_usb) {
int vid, pid, version;
if (NativeMethods.TryParseHex(idVendor, out vid) &&
NativeMethods.TryParseHex(idProduct, out pid) &&
diff --git a/HidSharp/Platform/Linux/NativeMethodsLibudev.cs b/HidSharp/Platform/Linux/NativeMethodsLibudev.cs
index 3759a38..f9b6b83 100644
--- a/HidSharp/Platform/Linux/NativeMethodsLibudev.cs
+++ b/HidSharp/Platform/Linux/NativeMethodsLibudev.cs
@@ -82,9 +82,13 @@ public abstract string FriendlyName
public abstract IntPtr udev_enumerate_get_list_entry(IntPtr enumerate);
+ public abstract IntPtr udev_list_entry_get_by_name(IntPtr entry, string name);
+
public abstract IntPtr udev_list_entry_get_next(IntPtr entry);
public abstract string udev_list_entry_get_name(IntPtr entry);
+
+ public abstract string udev_list_entry_get_value(IntPtr entry);
public abstract IntPtr udev_device_new_from_syspath(IntPtr udev, string syspath);
@@ -96,7 +100,18 @@ public abstract string FriendlyName
public abstract string udev_device_get_devpath(IntPtr device);
+ public abstract string udev_device_get_devtype(IntPtr device);
+
+ public abstract IntPtr udev_device_get_properties_list_entry(IntPtr entry);
+
+ public abstract string udev_device_get_syspath(IntPtr device);
+
+ public abstract string udev_device_get_subsystem(IntPtr device);
+
+ public abstract IntPtr udev_device_get_parent(IntPtr device);
+
public abstract IntPtr udev_device_get_parent_with_subsystem_devtype(IntPtr device, string subsystem, string devtype);
+ public abstract IntPtr udev_device_get_parent_with_subsystem(IntPtr device, string subsystem);
public abstract string udev_device_get_sysattr_value(IntPtr device, string sysattr);
diff --git a/HidSharp/Platform/Linux/NativeMethodsLibudev0.cs b/HidSharp/Platform/Linux/NativeMethodsLibudev0.cs
index b4167c4..c2597d7 100644
--- a/HidSharp/Platform/Linux/NativeMethodsLibudev0.cs
+++ b/HidSharp/Platform/Linux/NativeMethodsLibudev0.cs
@@ -138,6 +138,14 @@ public override IntPtr udev_enumerate_get_list_entry(IntPtr enumerate)
return native_udev_enumerate_get_list_entry(enumerate);
}
+ [DllImport(libudev, EntryPoint = "udev_list_entry_get_by_name")]
+ static extern IntPtr native_udev_list_entry_get_by_name(IntPtr entry,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name);
+ public override IntPtr udev_list_entry_get_by_name(IntPtr entry, string name)
+ {
+ return native_udev_list_entry_get_by_name(entry, name);
+ }
+
[DllImport(libudev, EntryPoint = "udev_list_entry_get_next")]
static extern IntPtr native_udev_list_entry_get_next(IntPtr entry);
public override IntPtr udev_list_entry_get_next(IntPtr entry)
@@ -153,6 +161,14 @@ public override string udev_list_entry_get_name(IntPtr entry)
return native_udev_list_entry_get_name(entry);
}
+ [DllImport(libudev, EntryPoint = "udev_list_entry_get_value")]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
+ static extern string native_udev_list_entry_get_value(IntPtr entry);
+ public override string udev_list_entry_get_value(IntPtr entry)
+ {
+ return native_udev_list_entry_get_value(entry);
+ }
+
[DllImport(libudev, EntryPoint = "udev_device_new_from_syspath")]
static extern IntPtr native_udev_device_new_from_syspath(IntPtr udev,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string syspath);
@@ -191,6 +207,44 @@ public override string udev_device_get_devpath(IntPtr device)
return native_udev_device_get_devpath(device);
}
+ [DllImport(libudev, EntryPoint = "udev_device_get_devtype")]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
+ static extern string native_udev_device_get_devtype(IntPtr device);
+ public override string udev_device_get_devtype(IntPtr device)
+ {
+ return native_udev_device_get_devtype(device);
+ }
+
+ [DllImport(libudev, EntryPoint = "udev_device_get_properties_list_entry")]
+ static extern IntPtr native_udev_device_get_properties_list_entry(IntPtr entry);
+ public override IntPtr udev_device_get_properties_list_entry(IntPtr entry)
+ {
+ return native_udev_device_get_properties_list_entry(entry);
+ }
+
+ [DllImport(libudev, EntryPoint = "udev_device_get_syspath")]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
+ static extern string native_udev_device_get_syspath(IntPtr device);
+ public override string udev_device_get_syspath(IntPtr device)
+ {
+ return native_udev_device_get_syspath(device);
+ }
+
+ [DllImport(libudev, EntryPoint = "udev_device_get_subsystem")]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
+ static extern string native_udev_device_get_subsystem(IntPtr device);
+ public override string udev_device_get_subsystem(IntPtr device)
+ {
+ return native_udev_device_get_subsystem(device);
+ }
+
+ [DllImport(libudev, EntryPoint = "udev_device_get_parent")]
+ static extern IntPtr native_udev_device_get_parent(IntPtr device);
+ public override IntPtr udev_device_get_parent(IntPtr device)
+ {
+ return native_udev_device_get_parent(device);
+ }
+
[DllImport(libudev, EntryPoint = "udev_device_get_parent_with_subsystem_devtype")]
static extern IntPtr native_udev_device_get_parent_with_subsystem_devtype(IntPtr device,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string subsystem,
@@ -200,6 +254,18 @@ public override IntPtr udev_device_get_parent_with_subsystem_devtype(IntPtr devi
return native_udev_device_get_parent_with_subsystem_devtype(device, subsystem, devtype);
}
+ [DllImport(libudev, EntryPoint = "udev_device_get_parent_with_subsystem_devtype")]
+ static extern IntPtr native_udev_device_get_parent_with_subsystem(IntPtr device,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string subsystem
+ // ,[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(System.IntPtr))] IntPtr devtype
+ );
+ public override IntPtr udev_device_get_parent_with_subsystem(IntPtr device, string subsystem)
+ {
+ return native_udev_device_get_parent_with_subsystem(device, subsystem
+ // , IntPtr.Zero
+ );
+ }
+
[DllImport(libudev, EntryPoint = "udev_device_get_sysattr_value")]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
static extern string native_udev_device_get_sysattr_value(IntPtr device,
diff --git a/HidSharp/Platform/Linux/NativeMethodsLibudev1.cs b/HidSharp/Platform/Linux/NativeMethodsLibudev1.cs
index 484db01..b2b7f06 100644
--- a/HidSharp/Platform/Linux/NativeMethodsLibudev1.cs
+++ b/HidSharp/Platform/Linux/NativeMethodsLibudev1.cs
@@ -138,6 +138,14 @@ public override IntPtr udev_enumerate_get_list_entry(IntPtr enumerate)
return native_udev_enumerate_get_list_entry(enumerate);
}
+ [DllImport(libudev, EntryPoint = "udev_list_entry_get_by_name")]
+ static extern IntPtr native_udev_list_entry_get_by_name(IntPtr entry,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name);
+ public override IntPtr udev_list_entry_get_by_name(IntPtr entry, string name)
+ {
+ return native_udev_list_entry_get_by_name(entry, name);
+ }
+
[DllImport(libudev, EntryPoint = "udev_list_entry_get_next")]
static extern IntPtr native_udev_list_entry_get_next(IntPtr entry);
public override IntPtr udev_list_entry_get_next(IntPtr entry)
@@ -153,6 +161,14 @@ public override string udev_list_entry_get_name(IntPtr entry)
return native_udev_list_entry_get_name(entry);
}
+ [DllImport(libudev, EntryPoint = "udev_list_entry_get_value")]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
+ static extern string native_udev_list_entry_get_value(IntPtr entry);
+ public override string udev_list_entry_get_value(IntPtr entry)
+ {
+ return native_udev_list_entry_get_value(entry);
+ }
+
[DllImport(libudev, EntryPoint = "udev_device_new_from_syspath")]
static extern IntPtr native_udev_device_new_from_syspath(IntPtr udev,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string syspath);
@@ -191,6 +207,44 @@ public override string udev_device_get_devpath(IntPtr device)
return native_udev_device_get_devpath(device);
}
+ [DllImport(libudev, EntryPoint = "udev_device_get_devtype")]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
+ static extern string native_udev_device_get_devtype(IntPtr device);
+ public override string udev_device_get_devtype(IntPtr device)
+ {
+ return native_udev_device_get_devtype(device);
+ }
+
+ [DllImport(libudev, EntryPoint = "udev_device_get_properties_list_entry")]
+ static extern IntPtr native_udev_device_get_properties_list_entry(IntPtr entry);
+ public override IntPtr udev_device_get_properties_list_entry(IntPtr entry)
+ {
+ return native_udev_device_get_properties_list_entry(entry);
+ }
+
+ [DllImport(libudev, EntryPoint = "udev_device_get_syspath")]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
+ static extern string native_udev_device_get_syspath(IntPtr device);
+ public override string udev_device_get_syspath(IntPtr device)
+ {
+ return native_udev_device_get_syspath(device);
+ }
+
+ [DllImport(libudev, EntryPoint = "udev_device_get_subsystem")]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
+ static extern string native_udev_device_get_subsystem(IntPtr device);
+ public override string udev_device_get_subsystem(IntPtr device)
+ {
+ return native_udev_device_get_subsystem(device);
+ }
+
+ [DllImport(libudev, EntryPoint = "udev_device_get_parent")]
+ static extern IntPtr native_udev_device_get_parent(IntPtr device);
+ public override IntPtr udev_device_get_parent(IntPtr device)
+ {
+ return native_udev_device_get_parent(device);
+ }
+
[DllImport(libudev, EntryPoint = "udev_device_get_parent_with_subsystem_devtype")]
static extern IntPtr native_udev_device_get_parent_with_subsystem_devtype(IntPtr device,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string subsystem,
@@ -200,6 +254,18 @@ public override IntPtr udev_device_get_parent_with_subsystem_devtype(IntPtr devi
return native_udev_device_get_parent_with_subsystem_devtype(device, subsystem, devtype);
}
+ [DllImport(libudev, EntryPoint = "udev_device_get_parent_with_subsystem_devtype")]
+ static extern IntPtr native_udev_device_get_parent_with_subsystem(IntPtr device,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string subsystem
+ // ,[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(System.IntPtr))] IntPtr devtype
+ );
+ public override IntPtr udev_device_get_parent_with_subsystem(IntPtr device, string subsystem)
+ {
+ return native_udev_device_get_parent_with_subsystem(device, subsystem
+ // , IntPtr.Zero
+ );
+ }
+
[DllImport(libudev, EntryPoint = "udev_device_get_sysattr_value")]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
static extern string native_udev_device_get_sysattr_value(IntPtr device,
diff --git a/HidSharp/hidsharp_list/Program.cs b/HidSharp/hidsharp_list/Program.cs
new file mode 100644
index 0000000..0b84283
--- /dev/null
+++ b/HidSharp/hidsharp_list/Program.cs
@@ -0,0 +1,16 @@
+using System;
+using HidSharp;
+using HidSharp.Platform.Linux;
+
+
+var devices = HidSharp.DeviceList.Local.GetHidDevices();
+
+Console.WriteLine();
+Console.WriteLine("showing `DeviceList.Local.GetHidDevices()`:");
+Console.WriteLine();
+
+foreach (var device in devices) {
+ Console.WriteLine(device);
+}
+
+Console.WriteLine();
diff --git a/README.md b/README.md
index 17adf10..4152f6f 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,2 @@
# HIDSharpCore
-This is a fork of [Zer's HIDSharp](https://www.zer7.com/software/hidsharp). This fork of the library has been converted to .NET Core with a couple of bugfixes.
\ No newline at end of file
+This is a fork of [Zer's HIDSharp](https://www.zer7.com/software/hidsharp). This fork of the library has been converted to .NET Core with a couple of bugfixes.