61 lines
3.1 KiB
Markdown
61 lines
3.1 KiB
Markdown
---
|
|
source_files:
|
|
- Common/DTS.Common.IConnection/USBConnection/HIDUSBConnection/HIDUSBConnection.cs
|
|
generated_at: "2026-04-17T15:42:39.330640+00:00"
|
|
model: "zai-org/GLM-5-FP8"
|
|
schema_version: 1
|
|
sha256: "7d6d1a6f53e67671"
|
|
---
|
|
|
|
# HIDUSBConnection Documentation
|
|
|
|
## 1. Purpose
|
|
|
|
`HIDUSBConnection` implements the `IConnection` interface to provide asynchronous communication with USB Human Interface Device (HID) hardware. It targets specific DTS devices identified by Vendor ID `0x1CB9` and Product ID `0x0003`. The class wraps Windows HID API calls for device discovery, connection management, and bidirectional data transfer using input/output reports.
|
|
|
|
---
|
|
|
|
## 2. Public Interface
|
|
|
|
### Constants
|
|
|
|
| Name | Value | Description |
|
|
|------|-------|-------------|
|
|
| `HIDSLICE_PID` | `0x0003` | Product ID for target HID device |
|
|
| `DTS_VID` | `0x1CB9` | Vendor ID for DTS devices |
|
|
|
|
### Properties
|
|
|
|
| Signature | Description |
|
|
|-----------|-------------|
|
|
| `bool Connected { get; }` | Returns current connection state |
|
|
| `string ConnectString { get; }` | Returns the device path name set via `Create()` |
|
|
| `System.Net.Sockets.SocketFlags Flags { get; set; }` | Socket flags property (purpose unclear in HID context) |
|
|
|
|
### Events
|
|
|
|
| Signature | Description |
|
|
|-----------|-------------|
|
|
| `event EventHandler OnDisconnected` | Event raised when device disconnects (defined but never invoked in source) |
|
|
|
|
### Methods
|
|
|
|
| Signature | Description |
|
|
|-----------|-------------|
|
|
| `void Create(string ConnectString)` | Stores device path in `Device_Name` |
|
|
| `void Dispose()` | Public disposal method implementing IDisposable pattern |
|
|
| `IAsyncResult BeginConnect(AsyncCallback cb, object state)` | Queues async connect operation via ThreadPool |
|
|
| `void EndConnect(IAsyncResult ar)` | Opens handles to device, retrieves capabilities, initializes buffers |
|
|
| `static string GetFirstConnectString()` | Enumerates HID devices to find first matching VID/PID; returns device path or empty string |
|
|
| `IAsyncResult BeginDisconnect(bool reuseSocket, AsyncCallback cb, Object state)` | Queues async disconnect operation |
|
|
| `void EndDisconnect(IAsyncResult asyncResult)` | Closes `_HIDHandle`, `_ReadHandle`, `_WriteHandle`; sets `_Connected = false` |
|
|
| `IAsyncResult BeginSend(byte[] buffer, int offset, int size, AsyncCallback cb, object state)` | Queues async send operation; validates handles first |
|
|
| `int EndSend(IAsyncResult ar)` | Writes data to device via HID output reports; returns total bytes sent |
|
|
| `IAsyncResult BeginReceive(byte[] buffer, int offset, int size, AsyncCallback cb, object state)` | Queues async receive operation; validates handles first |
|
|
| `int EndReceive(IAsyncResult ar)` | Reads HID input report; copies to buffer (skipping first byte); returns bytes read or 0 on failure |
|
|
| `double GetCurrentDownloadRate()` | Returns `0D` (stub) |
|
|
| `double GetCurrentUploadRate()` | Returns `0D` (stub) |
|
|
| `string GetConnectionData()` | Returns empty string (stub) |
|
|
| `void Bind(int port)` | Throws `NotSupportedException` |
|
|
| `void Listen(int backlog)` | Throws `NotSupportedException` |
|
|
| `IAsyncResult BeginAccept(AsyncCallback callback, Object state)` |