void OutNetRTMP4TSStream::SignalAttachedToInStream() {
	if (_pInStream == NULL)
		return;
	if (_inboundStreamIsRTP && GetCapabilities() != NULL) {
		_videoCodecSent = (GetCapabilities()->videoCodecId != CODEC_VIDEO_AVC);
	}
	BaseOutNetRTMPStream::SignalAttachedToInStream();
}
Exemple #2
0
uint32_t BaseInStream::GetInputAudioTimescale() {
	StreamCapabilities *pCapabilities = NULL;
	AudioCodecInfo *pCodecInfo = NULL;
	if (((pCapabilities = GetCapabilities()) == NULL)
			|| ((pCodecInfo = pCapabilities->GetAudioCodec()) == NULL))
		return 1;
	return pCodecInfo->_samplingRate;
}
Exemple #3
0
	bool IsKeyboard()
	{

		DIDEVCAPS info;
		info.dwSize = sizeof(info);
		HRESULT hr = GetCapabilities(&info);
		return (info.dwDevType & 0xff) == DI8DEVTYPE_KEYBOARD;
	}
Exemple #4
0
STDMETHODIMP CBaseMuxerFilter::CheckCapabilities(DWORD* pCapabilities)
{
	CheckPointer(pCapabilities, E_POINTER);
	if(*pCapabilities == 0) return S_OK;
	DWORD caps;
	GetCapabilities(&caps);
	caps &= *pCapabilities;
	return caps == 0 ? E_FAIL : caps == *pCapabilities ? S_OK : S_FALSE;
}
Exemple #5
0
STDMETHODIMP CBaseSplitterFilter::CheckCapabilities(DWORD* pCapabilities)
{
	CheckPointer(pCapabilities, E_POINTER);
	if(*pCapabilities == 0) return S_OK;
	DWORD caps;
	GetCapabilities(&caps);
	if((caps&*pCapabilities) == 0) return E_FAIL;
	if(caps == *pCapabilities) return S_OK;
	return S_FALSE;
}
STDMETHODIMP CAVIOutputPin::CheckCapabilities(DWORD * pCapabilities)
{
	DWORD dwActual;
	GetCapabilities(&dwActual);
	if (*pCapabilities & (~dwActual))
	{
		return S_FALSE;
	}
	return S_OK;
}
Exemple #7
0
STDMETHODIMP CStreamDriveThruFilter::CheckCapabilities(DWORD* pCapabilities)
{
	CheckPointer(pCapabilities, E_POINTER);

	if(*pCapabilities == 0) return S_OK;

	DWORD caps;
	GetCapabilities(&caps);

	DWORD caps2 = caps & *pCapabilities;

	return caps2 == 0 ? E_FAIL : caps2 == *pCapabilities ? S_OK : S_FALSE;
}
void BaseOutStream::GetStats(Variant &info, uint32_t namespaceId) {
	BaseStream::GetStats(info, namespaceId);
	if (_pInStream != NULL) {
		info["inStreamUniqueId"] = (((uint64_t) namespaceId) << 32) | _pInStream->GetUniqueId();
	} else {
		info["inStreamUniqueId"] = Variant();
	}
	StreamCapabilities *pCapabilities = GetCapabilities();
	if (pCapabilities != NULL)
		info["bandwidth"] = (uint32_t) pCapabilities->bandwidthHint;
	else
		info["bandwidth"] = (uint32_t) 0;
}
bool InFileRTMPStream::Initialize(Metadata &metadata, TimerType timerType,
		uint32_t granularity) {
	//1. Base init
	if (!BaseInFileStream::Initialize(metadata, timerType, granularity)) {
		FATAL("Unable to initialize stream");
		return false;
	}

	//2. Get stream capabilities
	StreamCapabilities *pCapabilities = GetCapabilities();
	if (pCapabilities == NULL) {
		FATAL("Invalid stream capabilities");
		return false;
	}

	pCapabilities->SetRTMPMetadata(_completeMetadata.publicMetadata());

	//3. Create the video builder
	uint64_t videoCodec = pCapabilities->GetVideoCodecType();
	if ((videoCodec != 0)
			&& (videoCodec != CODEC_VIDEO_UNKNOWN)
			&& (videoCodec != CODEC_VIDEO_H264)
			&& (videoCodec != CODEC_VIDEO_PASS_THROUGH)) {
		FATAL("Invalid video stream capabilities: %s", STR(tagToString(videoCodec)));
		return false;
	}
	if (videoCodec == CODEC_VIDEO_H264) {
		_pVideoBuilder = new AVCBuilder();
	} else if (videoCodec == CODEC_VIDEO_PASS_THROUGH) {
		_pVideoBuilder = new PassThroughBuilder();
	}

	//4. Create the audio builder
	uint64_t audioCodec = pCapabilities->GetAudioCodecType();
	if ((audioCodec != 0)
			&& (audioCodec != CODEC_AUDIO_UNKNOWN)
			&& (audioCodec != CODEC_AUDIO_AAC)
			&& (audioCodec != CODEC_AUDIO_MP3)
			&& (audioCodec != CODEC_AUDIO_PASS_THROUGH)) {
		FATAL("Invalid audio stream capabilities: %s", STR(tagToString(audioCodec)));
		return false;
	}
	if (audioCodec == CODEC_AUDIO_AAC) {
		_pAudioBuilder = new AACBuilder();
	} else if (audioCodec == CODEC_AUDIO_MP3) {
		_pAudioBuilder = new MP3Builder();
	} else if (audioCodec == CODEC_AUDIO_PASS_THROUGH) {
		_pAudioBuilder = new PassThroughBuilder();
	}
	return true;
}
Exemple #10
0
//-----------------------------------------------------------------------
void GraphicsContextGL4::SetConstantBuffer(int index, std::shared_ptr<NativeBuffer> const& constantBufferIn)
{
    POMDOG_ASSERT(index >= 0);
    POMDOG_ASSERT(constantBufferIn);

#if defined(DEBUG) && !defined(NDEBUG)
    static const auto capabilities = GetCapabilities();
    POMDOG_ASSERT(index < static_cast<int>(capabilities.ConstantBufferSlotCount));
#endif

    auto constantBuffer = std::dynamic_pointer_cast<ConstantBufferGL4>(constantBufferIn);

    POMDOG_ASSERT(constantBuffer);
    ApplyConstantBuffer(index, *constantBuffer);
}
Exemple #11
0
STDMETHODIMP CAMRSplitter::CheckCapabilities(DWORD* pCapabilities)
{
	CheckPointer(pCapabilities, E_POINTER);
	if (*pCapabilities == 0) {
		return S_OK;
	}

	DWORD caps;
	GetCapabilities(&caps);
	if ((caps&*pCapabilities) == 0) {
		return E_FAIL;
	}
	
	return caps == *pCapabilities ? S_OK : S_FALSE;
}
Exemple #12
0
STDMETHODIMP OggDemuxFilter::CheckCapabilities(DWORD *pCapabilities)
{
    HRESULT result = S_OK;

    DWORD dwActual;
    GetCapabilities(&dwActual);
    if (*pCapabilities & (~dwActual))
    {
        result = S_FALSE;
    }

    LOG(logDEBUG3) << "IMediaSeeking::CheckCapabilities(" << *pCapabilities << ") -> 0x" << std::hex << result;

    return result;
}
Exemple #13
0
STDMETHODIMP CBaseGraph::CheckCapabilities(DWORD* pCapabilities)
{
    CheckPointer(pCapabilities, E_POINTER);

    if (*pCapabilities == 0) {
        return S_OK;
    }

    DWORD caps;
    GetCapabilities(&caps);

    DWORD caps2 = caps & *pCapabilities;

    return caps2 == 0 ? E_FAIL : caps2 == *pCapabilities ? S_OK : S_FALSE;
}
Exemple #14
0
bool InFileRTMPStream::Initialize(int32_t clientSideBufferLength, bool hasTimer) {
	//1. Base init
	INFO("clientSideBufferLength %d", clientSideBufferLength);
	if (!BaseInFileStream::Initialize(clientSideBufferLength, hasTimer)) {
		FATAL("Unable to initialize stream");
		return false;
	}

	//2. Get stream capabilities
	StreamCapabilities *pCapabilities = GetCapabilities();
	if (pCapabilities == NULL) {
		FATAL("Invalid stream capabilities");
		return false;
	}

	//3. Create the video builder
	if ((pCapabilities->videoCodecId != 0)
			&& (pCapabilities->videoCodecId != CODEC_VIDEO_UNKNOWN)
			&& (pCapabilities->videoCodecId != CODEC_VIDEO_AVC)
			&& (pCapabilities->videoCodecId != CODEC_VIDEO_PASS_THROUGH)) {
		FATAL("Invalid video stream capabilities: %s", STR(tagToString(pCapabilities->videoCodecId)));
		return false;
	}
	if (pCapabilities->videoCodecId == CODEC_VIDEO_AVC) {
		_pVideoBuilder = new AVCBuilder();
	} else if (pCapabilities->videoCodecId == CODEC_VIDEO_PASS_THROUGH) {
		_pVideoBuilder = new PassThroughBuilder();
	}

	//4. Create the audio builder
	if ((pCapabilities->audioCodecId != 0)
			&& (pCapabilities->audioCodecId != CODEC_AUDIO_UNKNOWN)
			&& (pCapabilities->audioCodecId != CODEC_AUDIO_AAC)
			&& (pCapabilities->audioCodecId != CODEC_AUDIO_MP3)
			&& (pCapabilities->audioCodecId != CODEC_AUDIO_PASS_THROUGH)) {
		FATAL("Invalid audio stream capabilities: %s", STR(tagToString(pCapabilities->audioCodecId)));
		return false;
	}
	if (pCapabilities->audioCodecId == CODEC_AUDIO_AAC) {
		_pAudioBuilder = new AACBuilder();
	} else if (pCapabilities->audioCodecId == CODEC_AUDIO_MP3) {
		_pAudioBuilder = new MP3Builder();
	} else if (pCapabilities->audioCodecId == CODEC_AUDIO_PASS_THROUGH) {
		_pAudioBuilder = new PassThroughBuilder();
	}

	return true;
}
wxIDirectFBSurfacePtr
wxIDirectFBSurface::CreateCompatible(const wxSize& sz, int flags)
{
    wxSize size(sz);
    if ( size == wxDefaultSize )
    {
        if ( !GetSize(&size.x, &size.y) )
            return NULL;
    }

    wxCHECK_MSG( size.x > 0 && size.y > 0, NULL, "invalid size" );

    DFBSurfaceDescription desc;
    desc.flags = (DFBSurfaceDescriptionFlags)(
            DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
    GetCapabilities(&desc.caps);
    GetPixelFormat(&desc.pixelformat);
    desc.width = size.x;
    desc.height = size.y;

    // filter out caps that don't make sense for a new compatible surface:
    int caps = desc.caps;
    caps &= ~DSCAPS_PRIMARY;
    caps &= ~DSCAPS_SUBSURFACE;
    if ( flags & CreateCompatible_NoBackBuffer )
    {
        caps &= ~DSCAPS_DOUBLE;
        caps &= ~DSCAPS_TRIPLE;
    }
    desc.caps = (DFBSurfaceCapabilities)caps;

    wxIDirectFBSurfacePtr snew(wxIDirectFB::Get()->CreateSurface(&desc));
    if ( !snew )
        return NULL;

    if ( desc.pixelformat == DSPF_LUT8 )
    {
        wxIDirectFBPalettePtr pal(GetPalette());
        if ( pal )
        {
            if ( !snew->SetPalette(pal) )
                return NULL;
        }
    }

    return snew;
}
Exemple #16
0
//-----------------------------------------------------------------------
void GraphicsContextGL4::SetSampler(int index, NativeSamplerState* sampler)
{
    POMDOG_ASSERT(index >= 0);
    POMDOG_ASSERT(sampler != nullptr);

#if defined(DEBUG) && !defined(NDEBUG)
    static const auto capabilities = GetCapabilities();
    POMDOG_ASSERT(index < static_cast<int>(capabilities.SamplerSlotCount));
#endif

    auto samplerStateGL = static_cast<SamplerStateGL4*>(sampler);

    POMDOG_ASSERT(samplerStateGL != nullptr);
    POMDOG_ASSERT(samplerStateGL == dynamic_cast<SamplerStateGL4*>(sampler));

    samplerStateGL->Apply(index);
}
Exemple #17
0
void BaseInStream::GetStats(Variant &info, uint32_t namespaceId) {
	BaseStream::GetStats(info, namespaceId);
	info["outStreamsUniqueIds"] = Variant();
	LinkedListNode<BaseOutStream *> *pIterator = _pOutStreams;
	LinkedListNode<BaseOutStream *> *pCurrent = NULL;
	while (pIterator != NULL) {
		pCurrent = pIterator;
		pIterator = pIterator->pPrev;
		info["outStreamsUniqueIds"].PushToArray(
				((((uint64_t) namespaceId) << 32) | pCurrent->info->GetUniqueId()));
	}
	StreamCapabilities *pCapabilities = GetCapabilities();
	if (pCapabilities != NULL)
		info["bandwidth"] = (uint32_t) (pCapabilities->GetTransferRate() / 1024.0);
	else
		info["bandwidth"] = (uint32_t) 0;
}
Exemple #18
0
std::vector<WSDocNonCom> DMSHelper::GetAllRelatedDocs(CStdStringW sDocID)
{
	LOG_WS_FUNCTION_SCOPE_MSG(sDocID);

	try
	{
		std::vector<WSDocNonCom> vRelations;

		if(GetCapabilities(sDocID) & WS_VERSION_INDEPENDENT_RELATED_DOCUMENTS)
		{
			vRelations = GetRelatedDocs(sDocID);
		}
		else
		{
			std::vector<WSDocumentVersionNoCom> vVersions = GetVersions(sDocID);

			for (unsigned int i=0; i<vVersions.size(); i++)
			{
				std::vector<WSDocNonCom> vSomeRelations = GetRelatedDocs(vVersions[i].GetWSDocument().GetDocId());
				vRelations.insert(vRelations.end(), vSomeRelations.begin(), vSomeRelations.end());
			}
		}

		return vRelations;
	}
	catch(_com_error& e)
	{
		LOG_WS_ERROR_RESULT(e);
		throw;
	}
	catch(std::exception& e)
	{
		LOG_WS_ERROR_RESULT(e);
		throw;
	}
	catch(TCHAR*& e)
	{
		CStdString sErr(e);
		sErr.append(_T("(TCHAR*): This exception was thrown"));
		LOG_WS_ERROR(sErr);
		throw;
	}
}
Exemple #19
0
std::vector<WSDocNonCom> DMSHelper::GetAllRelatedSynergyDocs(CStdStringW sDocID)
{
	if(GetCapabilities(sDocID) & WS_VERSION_INDEPENDENT_RELATED_DOCUMENTS)
	{
		return GetSynergyRelatedDocs(sDocID);
	}
	else
	{
		std::vector<WSDocumentVersionNoCom> vVersions = GetVersions(sDocID);

		std::vector<WSDocNonCom> vAllRelations;

		for (unsigned int i=0; i<vVersions.size(); i++)
		{
			std::vector<WSDocNonCom> vSomeRelations = GetSynergyRelatedDocs(vVersions[i].GetWSDocument().GetDocId());
			vAllRelations.insert(vAllRelations.end(), vSomeRelations.begin(), vSomeRelations.end());
		}

		return vAllRelations;
	}
}
Exemple #20
0
DInputDevice::DInputDevice(DInput *dinput, LPDIRECTINPUT8 di, DIDEVICEINSTANCE &device, HWND hwnd) :
	_did(nullptr), _instanceGuid(device.guidInstance), _productGuid(device.guidProduct), 
	_name(device.tszProductName), _instanceName(device.tszInstanceName), _dataPacket(nullptr),
	_dataPacketSize(0), _acquired(false), _hwnd(hwnd), _numAxes(0), _numButtons(0), _numPOVs(0),
	_dinput(dinput), _deviceId(dinput->GetGUIDId(device.guidInstance))
{
	HRESULT result;
	result = di->CreateDevice(device.guidInstance, &_did, nullptr);
	if (result != DI_OK) {
		Log(Error, "Could not create direct input 8 device interface: 0x%08x", result);
		return;
	}
	SetCooperativeLevel(false, true);
	GetCapabilities();
	EnumObjects();
	SetDataFormat();
	SetBufferSize(sizeof(DIJOYSTATE));

	Acquire();
	GetState(_lastState);
}
Exemple #21
0
bool DMSHelper::IsLFS()
{
	if (m_bIsLFS)
		return true;

	CStdString sLFS( _T("Local File Store") );
	if (sLFS.CompareNoCase( Workshare::OptionApi::GetString(L"DefaultDocumentProvider") ) == 0)
	{
		m_bIsLFS = true;
		return true;
	}
	
	long lCapabilities = 0;
	HRESULT hRes = GetCapabilities(_bstr_t(_T("")), 0, &lCapabilities);
	if (hRes == E_INVALID_PROVIDER_CLIENT)
	{
		m_bIsLFS = true;
		return true;
	}

	return false;
}
Exemple #22
0
//-----------------------------------------------------------------------
GraphicsContextGL4::GraphicsContextGL4(
    std::shared_ptr<OpenGLContext> const& openGLContextIn,
    std::weak_ptr<GameWindow> windowIn)
    : nativeContext(openGLContextIn)
    , gameWindow(std::move(windowIn))
    , needToApplyInputLayout(true)
    , needToApplyPipelineState(true)
{
    auto version = reinterpret_cast<char const*>(glGetString(GL_VERSION));
    Log::Stream(LogLevel::Internal) << "OpenGL Version: " << version;

    auto capabilities = GetCapabilities();
    if (capabilities.SamplerSlotCount > 0) {
        textures.resize(capabilities.SamplerSlotCount);
    }

    glFrontFace(GL_CW);
    POMDOG_CHECK_ERROR_GL4("glFrontFace");

    frameBuffer = CreateFrameBuffer();
    primitiveTopology = ToPrimitiveTopology(PrimitiveTopology::TriangleList);
}
bool OSVRInterface::HasPoseState() const
{
	return (GetCapabilities() & POSE_STATE_AVAILABLE) > 0;
}
Exemple #24
0
STDMETHODIMP CStreamSwitcherPassThru::GetCapabilities(DWORD* pCaps)
{
    CallPeerSeeking(GetCapabilities(pCaps));
}
Exemple #25
0
NTSTATUS
StartDevice(PDEVICE_OBJECT DeviceObject, PCM_PARTIAL_RESOURCE_LIST raw, PCM_PARTIAL_RESOURCE_LIST translated)
{
    PFDO_DEVICE_EXTENSION FdoDeviceExtension;
    PCM_PARTIAL_RESOURCE_DESCRIPTOR resource;
    DEVICE_DESCRIPTION DeviceDescription;
    PEHCI_HOST_CONTROLLER hcd;
    ULONG NumberResources;
    ULONG iCount;
    ULONG DeviceAddress;
    ULONG PropertySize;
    ULONG BusNumber;
    NTSTATUS Status;

    FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
    hcd = &FdoDeviceExtension->hcd;

    /* Sanity Checks */
    Status = IoGetDeviceProperty(FdoDeviceExtension->LowerDevice,
                                 DevicePropertyAddress,
                                 sizeof(ULONG),
                                 &DeviceAddress,
                                 &PropertySize);

    Status = IoGetDeviceProperty(FdoDeviceExtension->LowerDevice,
                                 DevicePropertyBusNumber,
                                 sizeof(ULONG),
                                 &BusNumber,
                                 &PropertySize);


    /* Get the resources the PNP Manager gave */
    NumberResources = translated->Count;
    DPRINT("NumberResources %d\n", NumberResources);
    for (iCount = 0; iCount < NumberResources; iCount++)
    {
        DPRINT("Resource Info %d:\n", iCount);
        resource = &translated->PartialDescriptors[iCount];
        switch(resource->Type)
        {
            case CmResourceTypePort:
            {
                DPRINT("Port Start: %x\n", resource->u.Port.Start);
                DPRINT("Port Length %d\n", resource->u.Port.Length);
                /* FIXME: Handle Ports */
                break;
            }
            case CmResourceTypeInterrupt:
            {
                DPRINT("Interrupt Vector: %x\n", resource->u.Interrupt.Vector);
                FdoDeviceExtension->Vector = resource->u.Interrupt.Vector;
                FdoDeviceExtension->Irql = resource->u.Interrupt.Level;
                FdoDeviceExtension->Affinity = resource->u.Interrupt.Affinity;
                FdoDeviceExtension->Mode = (resource->Flags == CM_RESOURCE_INTERRUPT_LATCHED) ? Latched : LevelSensitive;
                FdoDeviceExtension->IrqShared = resource->ShareDisposition == CmResourceShareShared;
                break;
            }
            case CmResourceTypeMemory:
            {
                PVOID ResourceBase = 0;

                DPRINT("Mem Start: %x\n", resource->u.Memory.Start);
                DPRINT("Mem Length: %d\n", resource->u.Memory.Length);

                ResourceBase = MmMapIoSpace(resource->u.Memory.Start, resource->u.Memory.Length, FALSE);
                DPRINT("ResourceBase %x\n", ResourceBase);
                if (ResourceBase  == NULL)
                {
                    DPRINT1("MmMapIoSpace failed!!!!!!!!!\n");
                }

                GetCapabilities(&FdoDeviceExtension->hcd.ECHICaps, (ULONG)ResourceBase);
                DPRINT1("hcd.ECHICaps.Length %x\n", FdoDeviceExtension->hcd.ECHICaps.Length);
                FdoDeviceExtension->hcd.OpRegisters = (ULONG)((ULONG)ResourceBase + FdoDeviceExtension->hcd.ECHICaps.Length);
                break;
            }
            case CmResourceTypeDma:
            {
                DPRINT("Dma Channel: %x\n", resource->u.Dma.Channel);
                DPRINT("Dma Port: %d\n", resource->u.Dma.Port);
                break;
            }
            case CmResourceTypeDevicePrivate:
            {
                /* Windows does this. */
                DPRINT1("CmResourceTypeDevicePrivate not handled\n");
                break;
            }
            default:
            {
                DPRINT1("PNP Manager gave resource type not handled!! Notify Developers!\n");
                break;
            }
        }
    }

    for (iCount = 0; iCount < hcd->ECHICaps.HCSParams.PortCount; iCount++)
    {
        hcd->Ports[iCount].PortStatus = 0x8000;
        hcd->Ports[iCount].PortChange = 0;
        
        if (hcd->ECHICaps.HCSParams.PortPowerControl)
            hcd->Ports[iCount].PortStatus |= USB_PORT_STATUS_POWER;
    }

    KeInitializeDpc(&FdoDeviceExtension->DpcObject,
                    EhciDefferedRoutine,
                    FdoDeviceExtension);

    RtlZeroMemory(&DeviceDescription, sizeof(DEVICE_DESCRIPTION));

    DeviceDescription.Version = DEVICE_DESCRIPTION_VERSION;
    DeviceDescription.Master = TRUE;
    DeviceDescription.ScatterGather = TRUE;
    DeviceDescription.Dma32BitAddresses = TRUE;
    DeviceDescription.DmaWidth = 2;
    DeviceDescription.InterfaceType = PCIBus;
    DeviceDescription.MaximumLength = EHCI_MAX_SIZE_TRANSFER;

    hcd->pDmaAdapter = IoGetDmaAdapter(FdoDeviceExtension->LowerDevice,
                                       &DeviceDescription,
                                       &hcd->MapRegisters);

    if (hcd->pDmaAdapter == NULL)
    {
        DPRINT1("Ehci: IoGetDmaAdapter failed!\n");
        ASSERT(FALSE);
    }

    DPRINT1("MapRegisters %x\n", hcd->MapRegisters);

    /* Allocate Common Buffer for Periodic Frame List */
    FdoDeviceExtension->PeriodicFrameList.VirtualAddr =
        hcd->pDmaAdapter->DmaOperations->AllocateCommonBuffer(hcd->pDmaAdapter,
                                                              sizeof(ULONG) * 1024,
                                                              &FdoDeviceExtension->PeriodicFrameList.PhysicalAddr,
                                                              FALSE);

    if (FdoDeviceExtension->PeriodicFrameList.VirtualAddr == NULL)
    {
        DPRINT1("Ehci: FdoDeviceExtension->PeriodicFramList is null\n");
        return STATUS_UNSUCCESSFUL;
    }

    /* Zeroize it */
    RtlZeroMemory(FdoDeviceExtension->PeriodicFrameList.VirtualAddr, sizeof(ULONG) * 1024);

    ExInitializeFastMutex(&FdoDeviceExtension->FrameListMutex);

    /* Allocate initial page for queueheads and descriptors */
    FdoDeviceExtension->hcd.CommonBufferVA[0] =
        hcd->pDmaAdapter->DmaOperations->AllocateCommonBuffer(hcd->pDmaAdapter,
                                                              PAGE_SIZE,
                                                              &FdoDeviceExtension->hcd.CommonBufferPA[0],
                                                              FALSE);

    if (FdoDeviceExtension->hcd.CommonBufferVA[0] == 0)
    {
        DPRINT1("Ehci: Failed to allocate common buffer!\n");
        return STATUS_UNSUCCESSFUL;
    }

    hcd->CommonBufferSize = PAGE_SIZE * 16;

    /* Zeroize it */
    RtlZeroMemory(FdoDeviceExtension->hcd.CommonBufferVA[0],
                  PAGE_SIZE);

    /* Init SpinLock for host controller device lock */
    KeInitializeSpinLock(&hcd->Lock);

    /* Reserved a Queue Head that will always be in the AsyncList Address Register. By setting it as the Head of Reclamation
       the controller can know when it has reached the end of the QueueHead list */
    hcd->AsyncListQueue = CreateQueueHead(hcd);

    hcd->AsyncListQueue->HorizontalLinkPointer = hcd->AsyncListQueue->PhysicalAddr | QH_TYPE_QH;
    hcd->AsyncListQueue->EndPointCharacteristics.QEDTDataToggleControl = FALSE;
    hcd->AsyncListQueue->Token.Bits.InterruptOnComplete = FALSE;
    hcd->AsyncListQueue->EndPointCharacteristics.HeadOfReclamation = TRUE;
    hcd->AsyncListQueue->Token.Bits.Halted = TRUE;
    hcd->AsyncListQueue->NextQueueHead = hcd->AsyncListQueue;
    hcd->AsyncListQueue->PreviousQueueHead = hcd->AsyncListQueue;
    
    /* Reserve a Queue Head thats only purpose is for linking completed Queue Heads.
       Completed QueueHeads are moved to this temporary. As the memory must still be valid
       up until the controllers doorbell is rang to let it know info has been removed from QueueHead list */
    hcd->CompletedListQueue = CreateQueueHead(hcd);
    hcd->CompletedListQueue->NextQueueHead = hcd->CompletedListQueue;
    hcd->CompletedListQueue->PreviousQueueHead = hcd->CompletedListQueue;
    
    /* Ensure the controller is stopped */
    StopEhci(hcd);
    
    SetAsyncListQueueRegister(hcd, hcd->AsyncListQueue->PhysicalAddr);

    /* FIXME: Implement Periodic Frame List */

    Status = IoConnectInterrupt(&FdoDeviceExtension->EhciInterrupt,
                                InterruptService,
                                FdoDeviceExtension->DeviceObject,
                                NULL,
                                FdoDeviceExtension->Vector,
                                FdoDeviceExtension->Irql,
                                FdoDeviceExtension->Irql,
                                FdoDeviceExtension->Mode,
                                FdoDeviceExtension->IrqShared,
                                FdoDeviceExtension->Affinity,
                                FALSE);

    StartEhci(hcd);
    FdoDeviceExtension->DeviceState = DEVICESTARTED;
    return STATUS_SUCCESS;
}
//------------------------------------------------------------------------------
//	FUNCTION NAME:	InitializeCamera()
//
//  RETURNS:				If the function terminates before entering the message loop,
//      						return FALSE.
//    							Otherwise, return the WPARAM value sent by the WM_QUIT
//									message.
//
//  LAST MODIFIED:	PMcK	11/11/98
//
//  DESCRIPTION:		calls initialization function, processes message loop
//
//                  Windows recognizes this function by name as the initial
//									entry point for the program.  This function calls the
//									application initialization routine, if no other instance of
//									the program is running, and always calls the instance
//									initialization routine.  It then executes a	message
//									retrieval and dispatch loop that is the top-level control
//    							structure for the remainder of execution.  The loop is
//									terminated when a WM_QUIT  message is received, at which
//									time this function exits the application instance by
//									returning the value passed by PostQuitMessage().
//
//    							If the function must abort before entering the message loop,
//									it returns the conventional value NULL.
//
//
//	ARGUMENTS: 			hInstance - The handle to the instance of this application
//									that is currently being executed.
//
//    							hPrevInstance - The handle to the instance of this
//									application that was last executed.  If this is the only
//									instance of this application executing, hPrevInstance is
//									NULL. In Win32 applications, this parameter is always NULL.
//
//    							lpCmdLine - A pointer to a null terminated string specifying
//									the command line of the application.
//
//    							nCmdShow - Specifies how the main window is to be diplayed.
//------------------------------------------------------------------------------
bool ANDOR885_Camera::InitializeCamera()
{
	AndorCapabilities	caps;
	char 				aBuffer[256];
	int					errorValue;
	bool				errorFlag = false;
//	int 				test,test2; //need to pause while camera initializes

	float				speed, STemp, gain;
	int					iSpeed, nAD, nAmp, nPreAmp, index, IsPreAmpAvailable;

	int i;


	caps.ulSize = sizeof(AndorCapabilities);

	long numCameras;
	GetAvailableCameras(&numCameras);

    GetCurrentDirectoryA(256,aBuffer);// Look in current working directory
                                    // for driver files. Note: had to override usual mapping of GetCurrentDirectory to
									// GetCurrentDirectoryW because of mismatch of argument types.

    errorValue=Initialize(aBuffer);  // Initialize driver in current directory
	printError(errorValue, "Initialize error", &errorFlag, ANDOR_ERROR);
	if (errorFlag)
		return true;

    // Get camera capabilities
    errorValue=GetCapabilities(&caps);
	printError(errorValue, "Get Andor Capabilities information Error", &errorFlag, ANDOR_ERROR);

    // Get Head Model
    errorValue=GetHeadModel(model);
	printError(errorValue, "Get Head Model information Error", &errorFlag, ANDOR_ERROR);

    // Get detector information
    errorValue=GetDetector(&imageWidth,&imageHeight);
	printError(errorValue, "Get Detector information Error", &errorFlag, ANDOR_ERROR);

	// Set frame transfer mode
	errorValue=SetFrameTransferMode((frameTransfer == ANDOR_ON) ? 1 : 0);
	printError(errorValue, "Set Frame Transfer Mode Error", &errorFlag, ANDOR_ERROR);

    // Set acquisition mode to required setting specified in xxxxWndw.c
    errorValue=SetAcquisitionMode(acquisitionMode);
	printError(errorValue, "Set Acquisition Mode Error", &errorFlag, ANDOR_ERROR);

	
	if(caps.ulGetFunctions > 32)
	{
		GetEMCCDGain(&EMCCDGain);
	}

	if(readMode == READMODE_IMAGE) {
    	// This function only needs to be called when acquiring an image. It sets
		// the horizontal and vertical binning and the area of the image to be
		// captured. In this example it is set to 1x1 binning and is acquiring the
		// whole image
  		SetImage(1,1,1,imageWidth,1,imageHeight);
	}

    // Set read mode to required setting specified in xxxxWndw.c
    errorValue=SetReadMode(readMode);
	printError(errorValue, "Set Read Mode Error", &errorFlag, ANDOR_ERROR);

    // Set Vertical speed to max
/*    STemp = 0;
    VSnumber = 0;
    GetNumberVSSpeeds(&index);
    for(iSpeed=0; iSpeed<index; iSpeed++){
      GetVSSpeed(iSpeed, &speed);
      if(speed > STemp){
        STemp = speed;
        VSnumber = iSpeed;
      }
    }
    errorValue=SetVSSpeed(VSnumber);
	printError(errorValue, "Set Vertical Speed Error", &errorFlag, ANDOR_ERROR);
*/
	
	if (!notDestructed){
		STemp = 0;
		GetNumberVSSpeeds(&index);
		for(iSpeed=0; iSpeed < index; iSpeed++){
			GetVSSpeed(iSpeed, &speed);
			verticalShiftSpeed_t.choices[iSpeed] = STI::Utils::valueToString(speed);
			if(speed > STemp){
				STemp = speed;
				verticalShiftSpeed = iSpeed;
			}
		}
		verticalShiftSpeed_t.initial = (--verticalShiftSpeed_t.choices.end())->second;
	}
    errorValue = SetVSSpeed(verticalShiftSpeed);
	printError(errorValue, "Set Vertical Speed Error", &errorFlag, ANDOR_ERROR);

	/* Set Vertical Clock Voltage; 
		note: only the fastest vertical shift speeds will benefit from the higher clock voltage;
			  increasing clock voltage adds noise.
	*/
	if (!notDestructed) {
		index = 0;
		errorValue = GetNumberVSAmplitudes(&index);
		if (errorValue == DRV_SUCCESS) {
			for (i = 0; i < index; i++){
				if (i == 0){
					verticalClockVoltage_t.choices[i] = "Normal";
				} else {
					verticalClockVoltage_t.choices[i] = STI::Utils::valueToString(i);
				}
			}
			verticalClockVoltage_t.initial = (verticalClockVoltage_t.choices.begin())->second;
		}
	}
	errorValue = SetVSAmplitude(0);
	printError(errorValue, "Set Vertical Clock Voltage Error", &errorFlag, ANDOR_ERROR);

    // Set Horizontal Speed to max and check bit depth
	//(scan over all possible AD channels; although, the 885 has only one 14-bit channel)
		STemp = 0;
	//    HSnumber = 0;
		ADnumber = 0;
	if (!notDestructed) {
		errorValue = GetNumberADChannels(&nAD);
		if (errorValue != DRV_SUCCESS){
		  std::cerr << "Get number AD Channel Error\n";
		  errorFlag = true;
		}
		else if (nAD != 1) {
			std::cerr << "Expect 1 AD channel for this camera. The following code will miss channels\n";
			errorFlag = true;
		}
		else {
			errorValue = GetNumberHSSpeeds(0, 0, &index);
			if(errorValue == DRV_SUCCESS){
				for (iSpeed = 0; iSpeed < index; iSpeed++) {
				  GetHSSpeed(0, 0, iSpeed, &speed);
				  horizontalShiftSpeed_t.choices[iSpeed] = STI::Utils::valueToString(speed);
				  if(speed < STemp){
					STemp = speed;
					horizontalShiftSpeed = iSpeed;
				  }
				}
				horizontalShiftSpeed_t.initial = horizontalShiftSpeed_t.choices.find(horizontalShiftSpeed)->second;
			}
			//getBitDepth
			if (DRV_SUCCESS != GetBitDepth(0, &bitDepth))
				return true;
		}

		errorValue = GetNumberAmp(&nAmp);
		printError(errorValue, "Get Number Amplifiers Error", &errorFlag, ANDOR_ERROR);

		errorValue = GetNumberPreAmpGains(&nPreAmp);
		printError(errorValue, "Get Number Preamplifiers Error", &errorFlag, ANDOR_ERROR);

		if (nAmp == 1 && nAD == 1) {
			for (i = 0; i < nPreAmp; i++) {
				errorValue = GetPreAmpGain(i, &gain);
				errorValue = IsPreAmpGainAvailable(0,0,horizontalShiftSpeed,i,&IsPreAmpAvailable);
				if (IsPreAmpAvailable == 1) {
					preAmpGain_t.choices[i] = STI::Utils::valueToString(gain);
				}
			}
			if (!preAmpGain_t.choices.empty()) {
				preAmpGain = preAmpGain_t.choices.begin()->first;
				//preAmpGainPos = 0;
				preAmpGain_t.initial = (preAmpGain_t.choices.begin())->second; // set the initial condition for the preamplifier gain
				errorValue = SetPreAmpGain(preAmpGain);
				printError(errorValue, "Set AD Channel Error", &errorFlag, ANDOR_ERROR);
			} else {
				std::cerr << "No gains available at this speed. Weird.";
				errorFlag = true;
			}
		} else {
			std::cerr << "Unexpected number of A/D's or output amps" << std::endl;
			std::cerr << "Expected A/D's:       1 \t Measured: " << nAD << std::endl;
			std::cerr << "Expected output Amps: 1 \t Measured: " << nAmp << std::endl;
			errorFlag = true;
		}
	}
	else {
		errorValue = SetPreAmpGain(preAmpGain);
		printError(errorValue, "Set AD Channel Error", &errorFlag, ANDOR_ERROR);
	}
	

    errorValue=SetADChannel(ADnumber);
	printError(errorValue, "Set AD Channel Error", &errorFlag, ANDOR_ERROR);


    errorValue=SetHSSpeed(0,horizontalShiftSpeed);
	printError(errorValue, "Set Horizontal Speed Error", &errorFlag, ANDOR_ERROR);

    if(errorFlag)
    	//MessageBox(GetActiveWindow(),aBuffer,"Error!",MB_OK); SMD
	    std::cerr<<aBuffer<<std::endl;


  // Wait for 2 seconds to allow MCD to calibrate fully before allowing an
  // acquisition to begin
//  test=GetTickCount();
//  do{
//  	test2=GetTickCount()-test;
//  }while(test2<2000);

	Sleep(2000);

	errorValue = SetExposureTime(exposureTime);
	printError(errorValue, "Exposure time error", &errorFlag, ANDOR_ERROR);

	// It is necessary to get the actual times as the system will calculate the
	// nearest possible time. eg if you set exposure time to be 0, the system
	// will use the closest value (around 0.01s)
	  GetAcquisitionTimings(&exposureTime,&accumulateTime,&kineticTime);
	  std::cerr << "Actual Exposure Time is " << exposureTime << " s.\n";

  // Set Shutter is made up of ttl level, shutter and open close time

  //Check Get open close time
	if(openTime==0)
		openTime=1;
	if(closeTime==0)
		closeTime=1;

	// Set shutter
	errorValue=SetShutter(ttl,shutterMode,closeTime,openTime);
	if(errorValue!=DRV_SUCCESS){
		std::cerr << "Shutter error\n";
		errorFlag = true;  
	}
	else
		std::cerr << "Shutter set to specifications\n";

	/*// Determine availability of trigger option and set trigger selection
	std::map<int,std::string>::iterator it;
	std::vector<int> triggerKeys;
	for (it = triggerMode_t.choices.begin(); it != triggerMode_t.choices.end(); it++)
	{
		errorValue = SetTriggerMode(it->first);
		if (errorValue != DRV_SUCCESS)
			triggerKeys.push_back(it->first);
	}
	for (int i = 0; i < triggerKeys.size(); i++)
		triggerMode_t.choices.erase(triggerKeys.at(i));

	if (triggerMode_t.choices.empty()) {
		std::cerr << "No triggerModes found" << std::endl;
		return true;
	}
	else if (triggerMode_t.choices.find(TRIGGERMODE_EXTERNAL_EXPOSURE) != 
		triggerMode_t.choices.end()) 
		triggerMode = TRIGGERMODE_EXTERNAL_EXPOSURE;
	else if (triggerMode_t.choices.find(TRIGGERMODE_EXTERNAL) != 
		triggerMode_t.choices.end())
		triggerMode = TRIGGERMODE_EXTERNAL;
	else
		triggerMode = triggerMode_t.choices.begin()->first;

	errorValue=SetTriggerMode(triggerMode);
	printError(errorValue, "Set Trigger Mode Error", &errorFlag, ANDOR_ERROR);
	triggerMode_t.initial = triggerMode_t.choices.find(triggerMode)->second;
*/

	// Determine availability of trigger option and set trigger selection
	std::map<int,std::string>::iterator it;
	std::vector<int> triggerKeys;
	for (it = triggerMode_t.choices.begin(); it != triggerMode_t.choices.end(); it++)
	{
		errorValue = SetTriggerMode(it->first);
		if (errorValue != DRV_SUCCESS)
			triggerKeys.push_back(it->first);
	}
	for (int i = 0; i < triggerKeys.size(); i++)
		triggerMode_t.choices.erase(triggerKeys.at(i));

	if (triggerMode_t.choices.empty()) {
		std::cerr << "No triggerModes found" << std::endl;
		return true;
	}
	else if (triggerMode_t.choices.find(TRIGGERMODE_EXTERNAL_EXPOSURE) != 
		triggerMode_t.choices.end()) 
		triggerMode = TRIGGERMODE_EXTERNAL_EXPOSURE;
	else if (triggerMode_t.choices.find(TRIGGERMODE_EXTERNAL) != 
		triggerMode_t.choices.end())
		triggerMode = TRIGGERMODE_EXTERNAL;
	else
		triggerMode = triggerMode_t.choices.begin()->first;

	errorValue=SetTriggerMode(triggerMode);
	printError(errorValue, "Set Trigger Mode Error", &errorFlag, ANDOR_ERROR);
	triggerMode_t.initial = triggerMode_t.choices.find(triggerMode)->second;


	errorValue = GetTemperatureRange(&minTemp, &maxTemp);
	if (errorValue != DRV_SUCCESS){
		std::cerr << "Error finding temperature range or camera is not on" << std::endl;
		errorFlag = true;
	}
	else {
		std::cerr << "Temperature must be between " << minTemp << " and " << maxTemp << std::endl;
		std::cerr << "Warning: Water cooling is required for temperatures < -58 deg C" << std::endl;

		//Set temperature
		if (coolerSetpt > maxTemp || coolerSetpt < minTemp) {
			std::cerr << "Chosen temperature out of range." << std::endl;
			if (coolerSetpt > maxTemp)
				coolerSetpt = maxTemp;
			else
				coolerSetpt = minTemp;
			std::cerr << "Resetting temp to nearest acceptable value " << std::endl;
		} 

		errorValue = SetTemperature(coolerSetpt);
		printError(errorValue, "Error setting cooler temperature", &errorFlag, ANDOR_ERROR);

		int i;
		errorValue = IsCoolerOn(&i);
		if (i == 0) {
			// if it's off and it's supposed to be on, turn it on
			if (coolerStat == ANDOR_ON) {
				std::cerr << "Turning on cooler." << std::endl;
				errorValue = CoolerON();
				printError(errorValue, "Error turning on cooler", &errorFlag, ANDOR_ERROR);
			}
			
		} else if (i == 1) {
			std::cerr << "Cooler is on." << std::endl;
			//if it's on and it's supposed to be off, turn it off
			if (coolerStat == ANDOR_OFF)
			{
				errorValue = CoolerOFF();
				printError(errorValue, "Error turning off cooler", &errorFlag, ANDOR_ERROR);
			} else {
				errorValue = GetTemperature(&i);
				switch(errorValue){
					case DRV_TEMP_STABILIZED:
						std::cerr << "Cooler temp has stabilized at " << i << " deg C" << std::endl;
						break;
					case DRV_TEMP_NOT_REACHED:
						std::cerr << "Cooler temp is " << i << " deg C" << std::endl;
						std::cerr << "Cooler setpoint has not been reached." << std::endl;
						std::cerr << "This may be because water cooling is required for setpoints < -58 deg C" << std::endl;
						std::cerr << "Either wait or try resetting cooler setpoint" << std::endl;
						break;
					case DRV_TEMP_DRIFT:
						std::cerr << "Cooler temp is " << i << " deg C" << std::endl;
						std::cerr << "Cooler temperature has drifted. Try resetting setpoint" << std::endl;
						break;
					case DRV_TEMP_NOT_STABILIZED:
						std::cerr << "Cooler temp is " << i << " deg C" << std::endl;
						std::cerr << "Temperature has been reached, but cooler has not stabilized" << std::endl;
						std::cerr << "Either wait or try resetting cooler setpoint" << std::endl;
						break;
					default:
						std::cerr << "Unrecognized error sequence. Camera may be off or acquiring" << std::endl;
						break;
				}
			}
		}
		
		
		if(!errorFlag){
			std::cerr << "Cooler temperature set to: " << coolerSetpt << std::endl;
		}
	
	}




	errorValue = SetSpool(0,0,NULL,10);  //Disable spooling
	printError(errorValue, "Spool mode error", &errorFlag, ANDOR_ERROR);

	// Returns the value from PostQuitMessage
	return errorFlag;
}
Exemple #27
0
int main(int argc, char **argv)
{
	int	status;
	int	bitdepth;
	int	width, height;
	int	min, max;
	int	i, j, numgains;
	float	gain;
	int	num_ad;
	int	num_vspeeds;
	int	num_hspeeds;
	float	speed;
	AndorCapabilities caps;
	at_32 lNumCameras;
	at_32 lCameraHandle;
	int	start_n, stop_n;
	int	npix;

	/* Check command line */

	npix = 90;

	if (argc > 1) sscanf(argv[1], "%d", &npix);
	
	/* FIRST, FIND OUT WHAT WE NEED TO KNOW ABOUT THIS CAMERA. */

	printf("Initializing Andor Camera.\n");

	/* How many cameras are connected */

	printf("GetAvailableCameras = %d\n", GetAvailableCameras(&lNumCameras));
	if (lNumCameras == 1)
		printf("There is %d camera connected.\n", lNumCameras);
	else
		printf("There are %d cameras connected.\n", lNumCameras);

	if (lNumCameras <= 0) exit(0);

	/* Get the camera we are working with. */

	printf("GetCameraHandle = %d\n", GetCameraHandle(0, &lCameraHandle));

	printf("SetCurrentCamera = %d\n", SetCurrentCamera(lCameraHandle));

	/* Initialize the CCD */

	printf("Initialize = %d\n", Initialize("/usr/local/etc/andor"));

	/* Wait for this to happen */

	sleep(2);

	/* What Capabilities do we have? */

	caps.ulSize = sizeof(caps);
	printf("GetCapabilities = %d\n", GetCapabilities(&caps));

	if (caps.ulCameraType & AC_CAMERATYPE_IXON)
		printf("Camera is an iXon.\n");
	else
		printf("Camera is not an iXon.\n");

	if (caps.ulAcqModes & AC_ACQMODE_FRAMETRANSFER)
		printf("Frame transfer is available.\n");
	else
		printf("Frame transfer is not available.\n");

	if (caps.ulSetFunctions & AC_SETFUNCTION_CROPMODE)
		printf("Crop mode is available.\n");
	else
		printf("Crop mode is not available.\n");

	/* Find out what the width and height are */

	printf("GetDetector = %d\n", GetDetector(&width, &height));
	printf("Andor full size %dx%d.\n", width, height);

	/* What is the allowable temperature range? */

	printf("GetTemperatureRange = %d\n", GetTemperatureRange(&min, &max));
	printf("Andor temperature range is %d to %d C.\n", min, max);
	
	/* How many preamp gains do we have? */

	printf("GetNumberPreAmpGains = %d\n", GetNumberPreAmpGains(&numgains));
	printf("Andor number of preamp gains is %d.\n", numgains);

	/* Let's find out what these gains are */

	for (i=0; i<numgains; i++)
	{
		printf("GetPreAmpGain = %d\n", GetPreAmpGain(i, &gain));
		printf("Andor Preamp Gain %d is %f.\n", i, gain);
	}

	/* How many vertical speeds do we have? */

	printf("GetNumberVSSpeeds = %d\n", GetNumberVSSpeeds(&num_vspeeds));
	printf("Andor number of Vertical Speeds is %d.\n", num_vspeeds);

	/* Let's find out what these VSpeeds are */

	for (i=0; i<num_vspeeds; i++)
	{
		printf("GetVSSpeed = %d\n", GetVSSpeed(i, &speed));
		printf("Andor Vertical Speed %d is %.2f uS.\n",
				i, speed);
	}

	for(j = 0; j < 1; j++)
	{
	    if (j == 0)
		    printf("For EMCCD output:\n");
	    else
		    printf("For CCD output:\n");

	    /* How many horizontal speeds do we have? */

	    printf("GetNumberHSSpeeds = %d\n",
		GetNumberHSSpeeds(0, j, &num_hspeeds));
	    printf("Andor number of Horizontal Speeds is %d.\n", num_hspeeds);

	    /* Let's find out what these speeds are */

	    for (i=0; i<num_hspeeds; i++)
	    {
		printf("GetHSSpeed = %d\n", GetHSSpeed(0, j, i, &speed));
		printf("Andor Horizontal Speed %d is %.2f MHz.\n", i, speed);
	    }

	}

	/* What is the range of gain settings - This is always wrong  */

	printf("GetEMGainRange = %d\n", GetEMGainRange(&min, &max));
	printf("Andor EM Gain range is %d to %d.\n", min, max);

	/* How many AD channels are there? */

	printf("GetNumberADChannels = %d\n", GetNumberADChannels(&num_ad));
	printf("Number of AD channels = %d\n", num_ad);

	/* What are the bit depths? */

	for(i=0; i < num_ad; i++)
	{
	    printf("GetBitDepth = %d\n", GetBitDepth(i, &bitdepth));
	    printf("AD channel %d has bit depth %d\n", i, bitdepth);
	}

	/* NOW WE START TO SET THINGS UP THE WAY WE WANT THEM */

	/* Turn on Cameralink mode */

	printf("SetCameraLinkMode = %d\n", SetCameraLinkMode(1));

	/* Put us in Frame Transfer Mode */

	printf( "Turning on Frame Transfer Mode.\n");
	printf("SetFrameTransferMode = %d\n", SetFrameTransferMode(1));

        /* Set output amplifier to EMCCD */

	printf("SetOutputAmplifier = %d\n", SetOutputAmplifier(0));

	/* Turn on advanced EM settings */

	printf("SetEMAdvanced = %d\n", SetEMAdvanced(1));

	/* Let's see if that worked... we should get 1000 as maximum */

	printf("GetEMGainRange = %d\n", GetEMGainRange(&min, &max));
	printf("Andor EM Gain range is %d to %d.\n", min, max);

	/* Set EM gain */

	printf("SetEMCCDGain = %d\n", SetEMCCDGain(300));

	/* Set our horizontal speed to the desired one. */

        printf("SetHSSpeed = %d\n", SetHSSpeed(0, 0));

	/* Set our vertical speed to the desired one. */

        printf("SetVSSpeed = %d\n", SetVSSpeed(0));

	/* Set our gain to the desired one. */

	printf("SetPreAmpGain = %d\n", SetPreAmpGain(2));

        /* Setup the read mode. I suspect this is the problem */

        printf("SetReadMode = %d\n", SetReadMode(4));

	/* Try to get frames like this */

        printf("SetAcquisitionMode = %d\n", SetAcquisitionMode(5));
	printf("PrepareAcquisition = %d\n", PrepareAcquisition());
	printf("StartAcquisition %d\n", StartAcquisition());
	sleep(1);
	printf("AbortAcquisition %d\n", AbortAcquisition());

	/* This sequence seemed to work with the server */

        //printf("SetHSSpeed = %d\n", SetHSSpeed(0, 1));

	/* DO we get the right gain range now? */

	printf("GetEMGainRange = %d\n", GetEMGainRange(&min, &max));
	printf("Andor EM Gain range is %d to %d.\n", min, max);

        /* We wish to use Cropped mode */

        printf("SetIsolatedCropMode = %d\n",
		SetIsolatedCropMode(1,npix,npix,1,1));

        /* Set the image to read the full area of cropped region */

        printf("SetImage = %d\n", SetImage(1, 1, 1, npix, 1, npix));

        /* Set exposure time to 1mS */

        printf("SetExposureTime = %d\n", SetExposureTime(0.001));

	/* Set Kinetic Cycle time to the smallest possible value */

	printf("SetKineticCycleTime = %d\n",SetKineticCycleTime(0.0));

	/* OK, let's see what the frame rate is */

        printf("SetAcquisitionMode = %d\n", SetAcquisitionMode(5));
	printf("StartAcquisition %d\n", StartAcquisition());
	sleep(1);
	printf("GetTotalNumberImagesAcquired = %d\n",
			GetTotalNumberImagesAcquired(&start_n));
	sleep(5);
	printf("GetTotalNumberImagesAcquired = %d\n",
			GetTotalNumberImagesAcquired(&stop_n));
	printf("Frame rate seems to be %.2f Hz\n",
			(double)(stop_n - start_n)/5.0);
	printf("AbortAcquisition = %d\n",AbortAcquisition());


	/* Get one frame... it seems things work better after this */

	GetStatus(&status);
	while(status==DRV_ACQUIRING) GetStatus(&status);
	printf("SaveAsFITS %d\n", SaveAsFITS("./image.fit", 4));

	/* That is all */

	printf("ShutDown = %d\n", ShutDown());

	exit(0);
}
bool OSVRInterface::HasAnalogState() const
{
	return (GetCapabilities() & ANALOG_STATE_AVAILABLE) > 0;
}
bool OSVRInterface::HasButtonState() const
{
	return (GetCapabilities() & BUTTON_STATE_AVAILABLE) > 0;
}
bool OSVRInterface::HasOrientationState() const
{
	return (GetCapabilities() & ORIENTATION_STATE_AVAILABLE) > 0;
}