Latest SDK v2.0.7 - Help find any example or instructions of using c# wrapper

Hello @shmlex and @victorsbd,

Here you can find sample code:

Some notes about using of C# wrapper:

  1. Use binaries from SDK for VS 2015. In other case you’ll have issues. See Issues with initialization and deinitialization of C# wrapper -- SOLVED for details. In the above sample project all required binaries are already included.

  2. Call Astra.Context.Initialize() to initialize library before use. And don’t forget to call Astra.Context.Terminate() before exit from application (without this call application will crash on exit). See App.xaml.cs in the sample code.

  3. To start working with sensor, call Astra.StreamSet.Open(). If you want to work with multiple sensors, then call Astra.StreamSet.Open("device/sensorN"), where N is zero-based index of sensor. See MainWindow.xaml.cs in the sample code.

  4. Then, using this opened streamSet create stream reader by calling streamSet.CreateReader(). See constructor in SensorViewModel.cs in the sample code.

  5. To work with depth stream, use streamReader.GetStream<Astra.DepthStream>(). To work with color stream, use streamReader.GetStream<Astra.ColorStream>(). Etc. See constructor in SensorViewModel.cs file in the sample code.

  6. Set required mode for depth (and/or) color stream using AvailableModes property and SetMode(mode) method. See SetDepthMode() and TrySetColorMode() methods in SensorViewModel.cs file in the sample code.

  7. Be aware that not all modes returned by AvailableModes are actually supported! This issue was reported here: Can't get 60 fps - #3 by andrew

  8. To start streaming of data call Start() method for appropriate steam.

  9. To receive frames from stream(s) you have to organize loop (it is better to do it in some background thread to keep responsibility of your UI). In this loop call streamReader.TryOpenFrame() and then use out frame to access data. Don’t forget to free frame by calling frame.Dispose() or by using using (frame) clause. See BackgroundProcessingLoop() method in SensorViewModel.cs file in the sample code.

  10. Alternatively, you can call Astra.Context.Update() method in this loop and subscribe to streamReader.FrameReady event. But it is not so convenient in case of working with multiple sensors.

  11. Don’t forget to dispose streamSet and streamReader when you stop working with sensor. See Dispose() method in SensorViewModel.cs file in the sample code.

Have fun!

1 Like