Updated README.md
This commit is contained in:
parent
1b20217def
commit
effcea8b4d
|
@ -5,6 +5,9 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
namespace EonaCat.HID.Analyzer
|
namespace EonaCat.HID.Analyzer
|
||||||
{
|
{
|
||||||
|
// This file is part of the EonaCat project(s) which is released under the Apache License.
|
||||||
|
// See the LICENSE file or go to https://EonaCat.com/license for full license details.
|
||||||
|
|
||||||
internal partial class AboutBox : Form
|
internal partial class AboutBox : Form
|
||||||
{
|
{
|
||||||
public AboutBox()
|
public AboutBox()
|
||||||
|
|
|
@ -13,6 +13,9 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
namespace EonaCat.HID.Analyzer
|
namespace EonaCat.HID.Analyzer
|
||||||
{
|
{
|
||||||
|
// This file is part of the EonaCat project(s) which is released under the Apache License.
|
||||||
|
// See the LICENSE file or go to https://EonaCat.com/license for full license details.
|
||||||
|
|
||||||
public partial class MainForm : Form
|
public partial class MainForm : Form
|
||||||
{
|
{
|
||||||
IHidManager _deviceManager;
|
IHidManager _deviceManager;
|
||||||
|
|
|
@ -3,6 +3,8 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
namespace EonaCat.HID.Analyzer
|
namespace EonaCat.HID.Analyzer
|
||||||
{
|
{
|
||||||
|
// This file is part of the EonaCat project(s) which is released under the Apache License.
|
||||||
|
// See the LICENSE file or go to https://EonaCat.com/license for full license details.
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -4,6 +4,9 @@ using System.Globalization;
|
||||||
|
|
||||||
namespace EonaCat.HID.Example
|
namespace EonaCat.HID.Example
|
||||||
{
|
{
|
||||||
|
// This file is part of the EonaCat project(s) which is released under the Apache License.
|
||||||
|
// See the LICENSE file or go to https://EonaCat.com/license for full license details.
|
||||||
|
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
static IHidManager _deviceManager;
|
static IHidManager _deviceManager;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<Copyright>Copyright 2024 EonaCat (Jeroen Saey)</Copyright>
|
<Copyright>Copyright 2024 EonaCat (Jeroen Saey)</Copyright>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<PackageId>EonaCat.HID</PackageId>
|
<PackageId>EonaCat.HID</PackageId>
|
||||||
<Version>1.0.3</Version>
|
<Version>1.0.4</Version>
|
||||||
<Title>EonaCat.HID</Title>
|
<Title>EonaCat.HID</Title>
|
||||||
<Authors>EonaCat (Jeroen Saey)</Authors>
|
<Authors>EonaCat (Jeroen Saey)</Authors>
|
||||||
<Description>HID Devices</Description>
|
<Description>HID Devices</Description>
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace EonaCat.HID.Models
|
namespace EonaCat.HID.Models
|
||||||
{
|
{
|
||||||
|
// This file is part of the EonaCat project(s) which is released under the Apache License.
|
||||||
|
// See the LICENSE file or go to https://EonaCat.com/license for full license details.
|
||||||
public class HidReport
|
public class HidReport
|
||||||
{
|
{
|
||||||
public byte ReportId { get; }
|
public byte ReportId { get; }
|
||||||
|
|
32
README.md
32
README.md
|
@ -6,11 +6,17 @@ Works on Windows, Linux and macOS.
|
||||||
Example Code:
|
Example Code:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
using EonaCat.HID.EventArguments;
|
using EonaCat.HID;
|
||||||
using EonaCat.HID.Helpers;
|
using EonaCat.HID.Models;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
class Program
|
namespace EonaCat.HID.Example
|
||||||
{
|
{
|
||||||
|
// This file is part of the EonaCat project(s) which is released under the Apache License.
|
||||||
|
// See the LICENSE file or go to https://EonaCat.com/license for full license details.
|
||||||
|
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
static IHidManager _deviceManager;
|
static IHidManager _deviceManager;
|
||||||
static IHid _device;
|
static IHid _device;
|
||||||
static IEnumerable<IHid> _deviceList;
|
static IEnumerable<IHid> _deviceList;
|
||||||
|
@ -52,7 +58,7 @@ class Program
|
||||||
|
|
||||||
_device.OnDataReceived += (s, e) =>
|
_device.OnDataReceived += (s, e) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Rx Data: {BitConverter.ToString(e.Data)}");
|
Console.WriteLine($"Rx Data: {BitConverter.ToString(e.Report.Data)}");
|
||||||
};
|
};
|
||||||
|
|
||||||
_device.OnError += (s, e) =>
|
_device.OnError += (s, e) =>
|
||||||
|
@ -63,19 +69,18 @@ class Program
|
||||||
_device.Open();
|
_device.Open();
|
||||||
Console.WriteLine($"Connected to {_device.ProductName}");
|
Console.WriteLine($"Connected to {_device.ProductName}");
|
||||||
|
|
||||||
await _device.StartListeningAsync();
|
await _device.StartListeningAsync(default);
|
||||||
|
|
||||||
Console.WriteLine("Listening... Press [Enter] to send test output report.");
|
Console.WriteLine("Listening... Press [Enter] to send test output report.");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
|
||||||
// Example: Send output report
|
// Example: Send output report using HidReport
|
||||||
var data = ByteHelper.HexStringToByteArray("01-02-03");
|
var data = ByteHelper.HexStringToByteArray("01-02-03");
|
||||||
byte[] outputReport = new byte[data.Length + 1];
|
var reportId = (byte)0x00; // Report ID
|
||||||
outputReport[0] = 0x00; // Report ID
|
var outputReport = new HidReport(reportId, data);
|
||||||
Array.Copy(data, 0, outputReport, 1, data.Length);
|
|
||||||
|
|
||||||
await _device.WriteOutputReportAsync(outputReport);
|
await _device.WriteOutputReportAsync(outputReport);
|
||||||
Console.WriteLine($"Sent output report: {BitConverter.ToString(outputReport)}");
|
Console.WriteLine($"Sent output report: Report ID: {reportId}, Data: {BitConverter.ToString(data)}");
|
||||||
|
|
||||||
Console.WriteLine("Press [Enter] to exit...");
|
Console.WriteLine("Press [Enter] to exit...");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
@ -99,10 +104,10 @@ class Program
|
||||||
Console.WriteLine($"[{i++}] {dev.ProductName} | VID:PID = {dev.VendorId:X4}:{dev.ProductId:X4}");
|
Console.WriteLine($"[{i++}] {dev.ProductName} | VID:PID = {dev.VendorId:X4}:{dev.ProductId:X4}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ByteHelper
|
public static class ByteHelper
|
||||||
{
|
{
|
||||||
public static byte[] HexStringToByteArray(string hex)
|
public static byte[] HexStringToByteArray(string hex)
|
||||||
{
|
{
|
||||||
return hex
|
return hex
|
||||||
|
@ -115,5 +120,6 @@ public static class ByteHelper
|
||||||
.Select(g => byte.Parse($"{g.First().c}{g.Last().c}", NumberStyles.HexNumber))
|
.Select(g => byte.Parse($"{g.First().c}{g.Last().c}", NumberStyles.HexNumber))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
Loading…
Reference in New Issue