Skip to content

Commit 51acc4c

Browse files
authored
UsbStream now accepts GUID with device interface class (#2)
1 parent 718f01b commit 51acc4c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

System.Device.UsbStream/UsbStream.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ public sealed class UsbStream : System.IO.Stream
3333
/// <exception cref="PlatformNotSupportedException">This is not support in .NET nanoFramework.</exception>
3434
public override long Position { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); }
3535

36-
internal UsbStream(string name)
36+
internal UsbStream(
37+
Guid classId,
38+
string name)
3739
{
38-
_streamIndex = NativeOpen(name);
40+
// need to convert GUID to proper format to help processing at native end
41+
_streamIndex = NativeOpen(
42+
$"{{{classId}}}",
43+
name);
3944

4045
_disposed = false;
4146
}
@@ -106,7 +111,7 @@ public override void Write(byte[] buffer, int offset, int count)
106111
private extern void NativeClose();
107112

108113
[MethodImpl(MethodImplOptions.InternalCall)]
109-
private extern int NativeOpen(string name);
114+
private extern int NativeOpen(string classId, string name);
110115

111116
[MethodImpl(MethodImplOptions.InternalCall)]
112117
private extern void NativeWrite(byte[] buffer, int offset, int count);

UsbClient/UsbClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ public class UsbClient
1111
/// <summary>
1212
/// Creates an USB Stream from a WinUSB device that will use the specified name as the device description.
1313
/// </summary>
14+
/// <param name="classId"><see cref="Guid"/> for the device class that will be used by WinUSB device.</param>
1415
/// <param name="name">Name to be used as device description.</param>
1516
/// <returns>A new UsbStream that was created with the specified name.</returns>
16-
public static UsbStream CreateUsbStream(string name)
17+
public static UsbStream CreateUsbStream(
18+
Guid classId,
19+
string name)
1720
{
18-
return new UsbStream(name);
21+
return new UsbStream(
22+
classId,
23+
name);
1924
}
2025
}
2126
}

0 commit comments

Comments
 (0)