Click here to Skip to main content
13,894,085 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 14 Apr 2014
Licenced CPOL

Getting a RealSense of My Status

, 14 Apr 2014
Rate this:
Please Sign up or sign in to vote.
Getting a RealSense of my status

Long time readers will have realized that I have been spending a lot of time with the technology that was formally known as Perceptual Computing (PerC). You may also know that this technology is now known as RealSense and that it will be rolling out to a device near you soon. What you might not know is that I’m currently writing a course on this technology for Pluralsight. As part of writing this course, I’ve been creating a few little wrapper utilities that will make your life easier when developing apps with the SDK.

In this post, I’m going to show you a handy little method for working with API methods. Pretty much every RealSense API method returns a status code to indicate whether or not it was successful. Now, it can get pretty tedious writing code that looks like this:

pxcmStatus status = Session.CreateImpl<PXCMVoiceRecognition>
  (PXCMVoiceRecognition.CUID, out voiceRecognition);
if (status < pxcmStatus.pxcmStatus.PXCM_STATUS_NO_ERROR)
  throw new InvalidStatusException("Could not create session");
status = _voiceRecognition.QueryProfile(out pInfo);
if (status < pxcmStatus.pxcmStatus.PXCM_STATUS_NO_ERROR)
  throw new InvalidStatusException("Could not query profile");

As you can imagine, the more calls you make, the more status checks you have to do. Well, I like to log information about what I’m attempting to do and what I have successfully managed to do, so this simple method really helps to write information about the methods being invoked, and to throw an exception if things go wrong.

public void PipelineInvoke(Func<pxcmStatus> pipelineMethod, string loggingInfo = "")
  if (!string.IsNullOrWhiteSpace(loggingInfo))
    Debug.WriteLine("Start " + loggingInfo);
  pxcmStatus status = pipelineMethod();
  if (status < pxcmStatus.PXCM_STATUS_NO_ERROR)
    throw new InvalidStatusException(loggingInfo, status);
  if (!string.IsNullOrWhiteSpace(loggingInfo))
    Debug.WriteLine("Finished " + loggingInfo);

This makes it easier to work with the API and gives us code that looks like this:

PipelineInvoke(() => 
  out _voiceRecognition), "creating voice recognition module");

And this is what InvalidStatusException looks like:

public class InvalidStatusException : Exception
  public InvalidStatusException(string alertMessage, pxcmStatus status)
    Message = alertMessage;
    Status = status;
  public string Message { get; private set; }
  public pxcmStatus Status { get; private set; }

Over the course of the next couple of months, I’ll share more posts with you showing the little tricks and techniques that I use to make working with the RealSense SDK a real joy.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Pete O'Hanlon
United Kingdom United Kingdom
A developer for over 30 years, I've been lucky enough to write articles and applications for Code Project as well as the Intel Ultimate Coder - Going Perceptual challenge. I live in the North East of England with 2 wonderful daughters and a wonderful wife.

I am not the Stig, but I do wish I had Lotus Tuned Suspension.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190306.1 | Last Updated 15 Apr 2014
Article Copyright 2014 by Pete O'Hanlon
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid