none
Error accessing WinRT desktop sensors in C++

    Question

  • When I attempt to access WinRT sensor data (such as gyroscope or accelerometer data) through polling with GetCurrentReading, the program stalls for several seconds then returns a SensorGetDataCollectionV2:ReadFileWithTimeoutInMs failed! error.

    I have tried to search for this error online and have been unable to find any results or anyone who has encountered this same error.

    I am testing these sensors on a Surface Book with Windows 10, I have posted a simple C++ code example below which loads a default gyroscope and then polls the gyroscope with GetCurrentReading, the program stalls on GetCurrentReading and then returns a null GyrometerReading.

    #include <iostream>
    #using <Windows.winmd>
    using namespace Windows::Devices::Sensors;
    #using <Platform.winmd>
    using namespace Platform;
    #include <Windows.h>
    #include <tchar.h>
    
    [MTAThread]
    int _tmain(int argc, _TCHAR* argv[])
    {
        CoInitialize(nullptr);
    
        Gyrometer^  gyrometer = Gyrometer::GetDefault();
        if (gyrometer)
        {
            GyrometerReading^ gyrometerReading = gyrometer->GetCurrentReading();
            if (gyrometerReading != nullptr)
            {
                std::cout << "Gyroscope x " << gyrometerReading->AngularVelocityX << std::endl;
                std::cout << "Gyroscope y " << gyrometerReading->AngularVelocityY << std::endl;
                std::cout << "Gyroscope z " << gyrometerReading->AngularVelocityZ << std::endl;
            }
            else
            {
                // the gyrometer reading is always null
                std::cout << "Failed to obtain gyroscope reading" << std::endl;
            }
        }
        else
        {
            std::cout << "Failed to load gyroscope" << std::endl;
        }
    
        return 0;
    }
    Saturday, April 23, 2016 5:39 AM