Skip to content

Commit b36bc61

Browse files
authored
PR #13987 from AviaAv: enable config for context on C#
2 parents 0c4a04c + 485062d commit b36bc61

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

wrappers/csharp/Intel.RealSense/Context.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public Context()
5252
onDevicesChangedCallback = new rs2_devices_changed_callback(OnDevicesChangedInternal);
5353
}
5454

55+
/// <summary>
56+
/// Initializes a new instance of the <see cref="Context"/> class with json_settings.
57+
///
58+
/// </summary>
59+
public Context(string json_settings)
60+
{
61+
object error;
62+
63+
handle = NativeMethods.rs2_create_context_ex(ApiVersion, json_settings, out error);
64+
onDevicesChangedCallback = new rs2_devices_changed_callback(OnDevicesChangedInternal);
65+
}
66+
5567
/// <summary>
5668
/// Gets the safe handle
5769
/// </summary>

wrappers/csharp/Intel.RealSense/NativeMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ internal static MemCpyDelegate GetMethod()
527527
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
528528
internal static extern ContextHandle rs2_create_context(int api_version, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ErrorMarshaler))] out object error);
529529

530+
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
531+
internal static extern ContextHandle rs2_create_context_ex(int api_version, [MarshalAs(UnmanagedType.LPStr)] string json_settings, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ErrorMarshaler))] out object error);
532+
530533
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
531534
internal static extern void rs2_delete_context(ContextHandle context);
532535

wrappers/csharp/tutorial/capture/Window.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public CaptureWindow()
5454
using (var ctx = new Context())
5555
{
5656
var devices = ctx.QueryDevices();
57+
Console.WriteLine("There are {0} connected RealSense devices.", devices.Count);
58+
if (devices.Count == 0) return;
5759
var dev = devices[0];
5860

5961
Console.WriteLine("\nUsing device 0, an {0}", dev.Info[CameraInfo.Name]);

0 commit comments

Comments
 (0)