/// <summary>
		/// The EnumerateDevices function enumerates all found devices and fills the input DeviceInfo array with obtained devices’ information. 
		/// </summary>
		/// <param name="DeviceInfoArray">Reference to a EMADeviceInfo array supplied by the user.</param>
		/// <param name="foundDevices">Returns the total number of devices found.</param>
		/// <returns>If the total number of devices found is greater than maxDevices, this function only fills up to maxDevices devices’ information to the EMADeviceInfo array. When this function succeeds, it returns S_OK. Otherwise it returns one of the following custom HRESULT error codes: <br></br><br></br> OutOfMemory <br></br> HidError <br></br> InvalidParameter</returns>
		/// <remarks>
		/// The EnumerateDevice function enumerates eMagin devices based on their USB Vendor ID only. <br></br><br></br> The maximum number of devices that can be connected is 16. <br></br><br></br> The C++ equivalent of this function is static.
		/// </remarks>

		public static Error EnumerateDevices ( DeviceInfo [ ] DeviceInfoArray , ref int foundDevices ) 
        { 
            DeviceInfos deviceInfos = new DeviceInfos ( ) ; 
            int arrayLength = DeviceInfoArray.GetLength ( 0 ) ; 
            if ( arrayLength  > 4 ) 
                arrayLength = 4 ; 
            Error error = ( Error ) S_EnumerateDevices ( deviceInfos , arrayLength , ref foundDevices ) ; 
            if ( Error.Ok == error ) 
            { 
                if ( ( foundDevices > 0 ) && ( arrayLength > 0 ) ) 
                    DeviceInfoArray [ 0 ] = deviceInfos.DeviceInfo_00 ; 
                if ( ( foundDevices > 1 ) && ( arrayLength > 1 ) ) 
                    DeviceInfoArray [ 1 ] = deviceInfos.DeviceInfo_01 ; 
                if ( ( foundDevices > 2 ) && ( arrayLength > 2 ) ) 
                    DeviceInfoArray [ 2 ] = deviceInfos.DeviceInfo_02 ; 
                if ( ( foundDevices > 3 ) && ( arrayLength > 3 ) ) 
                    DeviceInfoArray [ 3 ] = deviceInfos.DeviceInfo_03 ; 
            } 
            return error ; 
        } 
 /// <summary>
 /// Constructor for the Device Class.  Opens the device described in the DeviceInfo members, specifying behavior flags.
 /// </summary>
 /// <param name="deviceInfo">The DeviceInfo parameter, usually returned by EnumerateDevices, allows applications to specify which device should be opened.</param>
 /// <param name="flags">A member or a combination of members of the Flags enumerated type, used to enforce specific behaviors. </param>        
 public Device ( DeviceInfo deviceInfo , Flags flags )
 { 
     if ( 0 != handle ) 
     {
         Close ( handle ) ; 
         handle = 0 ; 
     }
     lock ( this )
     {
         handle = OpenEx ( deviceInfo , ( uint ) flags );
         GetDeviceInformation ( );
     } 
 } 
		/// <summary>
		/// The GetDeviceInfo function retrieves information for the current device and fills the input DeviceInfo array with obtained current device’s information.
		/// </summary>
		/// <param name="deviceInfo">to a EMADeviceInfo structure supplied by the user.</param>
		/// <returns>When this function succeeds, it returns S_OK. Otherwise it returns one of the following custom HRESULT error codes: <br></br><br></br> BadHandle</returns>
		public Error GetDeviceInfo ( DeviceInfo deviceInfo )
        {
            lock ( this )
            {

                if ( 0 != handle )
                    return ( Error ) GetDeviceInfo ( handle , deviceInfo );
                else
                    return Error.BadHandle;
            }
        } 
		/// <summary>
		/// Constructor for the Device Class.  Opens the device described in the DeviceInfo members.
		/// </summary>
		/// <param name="deviceInfo">The DeviceInfo parameter, usually returned by EnumerateDevices, allows applications to specify which device should be opened.</param>
        public Device ( DeviceInfo deviceInfo )
        { 
            if ( 0 != handle ) 
            {
                Close ( handle ) ; 
                handle = 0 ; 
            }
            lock ( this )
            {
                handle = Open ( deviceInfo );
                GetDeviceInformation ( );
            } 
        } 
 private void GetDeviceInformation ( ) 
 { 
     if ( 0 != handle ) 
     {
         deviceInformation = new DeviceInfo ( ) ; 
         Error e = GetDeviceInfo ( deviceInformation ) ; 
         if ( Error.Ok != e ) 
         { 
             deviceInformation = null ; 
             Close ( handle ) ; 
             handle = 0 ; 
         } 
     } 
 } 
 static extern uint OpenEx ( DeviceInfo deviceInfo , uint flags  ) ;
 static extern uint Open ( DeviceInfo deviceInfo ) ;
        private void HeadsetSetup()
        {
            DeviceInfo[] infosArray = new DeviceInfo[10];
            int found = 0;
            Device.EnumerateDevices(infosArray, ref found);
            headset = new Device(Flags.NoHeadTracking);
            tracker = new Device(Flags.None);

            DeviceData data = new DeviceData();
            headset.PollHeadTrackerRawData(data);
            Error e = Device.LastError;
            if (headset.Opened)
            {
                bool test1 = headset.CanDoHeadTracking;
                bool test2 = tracker.CanDoHeadTracking;
                // get device information
                headset.EnableStereoVision(true);
                // Turn on the headset if it was sleeping
                headset.KeepAlive();
            }
            else
            {
                headset.Dispose();
                headset = null;
            }

        }