diff --git a/src/HidApi.Net/Device.cs b/src/HidApi.Net/Device.cs index 6f80521..3423f38 100644 --- a/src/HidApi.Net/Device.cs +++ b/src/HidApi.Net/Device.cs @@ -65,6 +65,25 @@ public void Write(ReadOnlySpan data) HidException.Throw(handle); } + /// + /// Returns an input report. + /// + /// Max length of the expected data. The value can be greater than the actual report. + /// timeout in milliseconds. -1 for blocking mode. + /// The received data of the HID device. If the timeout is exceeded an empty result is returned. + /// Raised if maxlength is smaller than 0 + /// Raised on failure + public ReadOnlySpan ReadTimeout(int maxLength, int milliseconds) + { + if (maxLength < 0) + throw new ArgumentOutOfRangeException(nameof(maxLength), maxLength, "Please provide a positive value"); + + var buffer = new Span(new byte[maxLength]); + var bytesRead = ReadTimeout(buffer, milliseconds); + + return buffer[..bytesRead]; + } + /// /// Returns an input report. /// @@ -82,6 +101,24 @@ public int ReadTimeout(Span buffer, int milliseconds) return result; } + /// + /// Returns an input report. + /// + /// Max length of the expected data. The value can be greater than the actual report. + /// The received data of the HID device. If non-blocking mode is enabled and no data is available an empty result will be returned. + /// Raised if maxlength is smaller than 0 + /// Raised on failure + public ReadOnlySpan Read(int maxLength) + { + if (maxLength < 0) + throw new ArgumentOutOfRangeException(nameof(maxLength), maxLength, "Please provide a positive value"); + + var buffer = new Span(new byte[maxLength]); + var bytesRead = Read(buffer); + + return buffer[..bytesRead]; + } + /// /// Returns an input report. /// diff --git a/src/HidApi.Net/HidApi.Net.csproj b/src/HidApi.Net/HidApi.Net.csproj index 930582b..2d6a284 100644 --- a/src/HidApi.Net/HidApi.Net.csproj +++ b/src/HidApi.Net/HidApi.Net.csproj @@ -1,6 +1,6 @@ - 2.0.0 + 1.1.0 HidApi true