HRESULT _stdcall InitializeDevice(DWORD_PTR dwUserID, VMR9AllocationInfo *lpAllocInfo, DWORD *lpNumBuffers) { HRESULT hr; //Set the device IDirect3D9* d3d; RealDevice->GetDirect3D(&d3d); hr = pAllocNotify->SetD3DDevice(RealDevice, d3d->GetAdapterMonitor(0)); d3d->Release(); //if(hr!=S_OK) return hr; lpAllocInfo->dwFlags |= VMR9AllocFlag_TextureSurface; lpAllocInfo->Pool = D3DPOOL_SYSTEMMEM; // Ask the VMR-9 to allocate the surfaces for us. hr = pAllocNotify->AllocateSurfaceHelper(lpAllocInfo, lpNumBuffers, &surface); if(hr!=S_OK) return hr; hr=surface->GetContainer(IID_IDirect3DTexture9,(void**)&ptex); if(hr!=S_OK) { TerminateDevice(0); return hr; } RealDevice->CreateTexture(lpAllocInfo->dwWidth,lpAllocInfo->dwHeight,1,0,lpAllocInfo->Format, D3DPOOL_DEFAULT,&tex,NULL); return S_OK; }
ULONG _stdcall Release() { if(--RefCount==0) { TerminateDevice(0); if(pAllocNotify) { pAllocNotify->Release(); pAllocNotify=NULL; } } return RefCount; }
int _tmain(int argc, _TCHAR* argv[]) { TestWlanApi( argc, argv ); HANDLE DeviceHandle = OpenHandle(pNdisProtDevice); if( DeviceHandle == INVALID_HANDLE_VALUE ) { _tprintf((_T("Failed to open %s\n"), pNdisProtDevice)); return -1; } wstring strDeviceName[256][2]; int nCount = EnumerateDevices( DeviceHandle, strDeviceName ); if( nCount == 0 ) { puts( "no device bind." ); return -1; } for( int i = 0; i < nCount; ++i ) { printf( "%2d.%S\n %S\n\n", i, strDeviceName[i][0].c_str(), strDeviceName[i][1].c_str() ); } TCHAR szBuffer[256]; DWORD dwRead = 0; //if( ReadConsole( GetStdHandle(STD_INPUT_HANDLE), szBuffer, _countof(szBuffer), &dwRead, NULL ) == FALSE ) //{ // puts( "error input" ); // return -1; //} //szBuffer[dwRead] = 0; //int nChoice = _ttoi( szBuffer ); int nChoice = 0; if( nChoice > nCount ) { puts( "error input." ); return -1; } InitializeDevice( DeviceHandle, strDeviceName[nChoice][0].c_str(), strDeviceName[nChoice][0].length()*sizeof(WCHAR) ); for( int i = 0; i < 3; ++i ) { if( ReadFile( DeviceHandle, szBuffer, sizeof(szBuffer), &dwRead, NULL ) ) { } } TerminateDevice( DeviceHandle ); }
// -------------------------------------------------------------------------- // StopMessageManager // /// Terminate any active device, stop the device monitoring thread and stop /// the received message processing thread. /// /// @returns bool - true if the MessageManager stopped successfully. // -------------------------------------------------------------------------- bool MessageManager::StopMessageManager() { // close the services TerminateDevice(); // stop the device monitoring thread DeviceMonitor::GetInstance().StopDeviceMonitor(); // stop the received message process thread if (m_isStarted) { // trigger the exit event and wait for the thread to exit ::SetEvent(m_hProcessExitEvent); ::WaitForSingleObject(m_hProcessThread,INFINITE); //wyw_0104 ::CloseHandle(m_hProcessThread); m_hProcessThread = INVALID_HANDLE_VALUE; } return true; }
//**************************************************************************** // // The main application entry function. // // \param None. // // This function forms the main entry point of the example application. It // initializes the USB bulk device, prompts the user for an ASCII string, // sends this string to the device, reads the response from the device (which // will be the same string with the character order reversed if using the // sample device provided by Luminary Micro) and displays the returned // string. // // \return Set the exit code to 0 of no errors cause the application to end // or a non-zero value otherwise. // //**************************************************************************** int main(int argc, char *argv[]) { BOOL bResult; BOOL bDriverInstalled; BOOL bEcho; char szBuffer[MAX_ENTRY_LEN]; ULONG ulWritten; ULONG ulRead; ULONG ulLength; DWORD dwError; LMUSB_HANDLE hUSB; // // Are we operating in echo mode or not? The "-e" parameter tells the // app to echo everything it receives back to the device unchanged. // bEcho = ((argc > 1) && (argv[1][1] == 'e')) ? TRUE : FALSE; // // Print a cheerful welcome. // printf("\nLuminary Micro Bulk USB Device Example\n"); printf("--------------------------------------\n\n"); printf("Version %s\n\n", BLDVER); if(!bEcho) { printf("This is a partner application to the usb_dev_bulk example\n"); printf("shipped with StellarisWare software releases for USB-enabled\n"); printf("boards. Strings entered here are sent to the board which\n"); printf("inverts the case of the characters in the string and returns\n"); printf("them to the host.\n\n"); } else { printf("If run with the \"-e\" command line switch, this application\n"); printf("echoes all data received on the bulk IN endpoint to the bulk\n"); printf("OUT endpoint. This feature may be helpful during development\n"); printf("and debug of your own USB devices. Note that this will not\n"); printf("do anything exciting if run with the usb_dev_bulk example\n"); printf("device attached since it expects the host to initiate transfers.\n\n"); } // // Find our USB device and prepare it for communication. // hUSB = InitializeDevice(BULK_VID, BULK_PID, (LPGUID)&(GUID_DEVINTERFACE_LUMINARY_BULK), &bDriverInstalled); if(hUSB) { // // Are we operating in echo mode or not? The "-e" parameter tells the // app to echo everything it receives back to the device unchanged. // if(bEcho) { // // Yes - we are in echo mode. // printf("Running in echo mode. Press Ctrl+C to exit.\n\n" "Throughput: 0Kbps Packets: 0"); while(1) { // // Read a packet of data from the device. // dwError = ReadUSBPacket(hUSB, szBuffer, ECHO_PACKET_SIZE, &ulRead, INFINITE, NULL); if(dwError != ERROR_SUCCESS) { // // We failed to read from the device. // printf("\n\nError %d (%S) reading from bulk IN pipe.\n", dwError, GetSystemErrorString(dwError)); break; } else { // // Update our byte and packet counters. // g_ulByteCount += ulRead; g_ulPacketCount++; // // Write the data back out to the device. // bResult = WriteUSBPacket(hUSB, szBuffer, ulRead, &ulWritten); if(!bResult) { // // We failed to write the data for some reason. // dwError = GetLastError(); printf("\n\nError %d (%S) writing to bulk OUT pipe.\n", dwError, GetSystemErrorString(dwError)); break; } // // Display the throughput. // UpdateThroughput(); } } } else { // // We are running in normal mode. Keep sending and receiving // strings until the user indicates that it is time to exit. // while(1) { // // The device was found and successfully configured. Now get a string from // the user... // do { printf("\nEnter a string (EXIT to exit): "); fgets(szBuffer, MAX_ENTRY_LEN, stdin); printf("\n"); // // How many characters were entered (including the trailing '\n')? // ulLength = (ULONG)strlen(szBuffer); if(ulLength <= 1) { // // The string is either nothing at all or a single '\n' so reprompt the user. // printf("\nPlease enter some text.\n"); ulLength = 0; } else { // // Get rid of the trailing '\n' if there is one there. // if(szBuffer[ulLength - 1] == '\n') { szBuffer[ulLength - 1] = '\0'; ulLength--; } } } while(ulLength == 0); // // Are we being asked to exit the application? // if(!(strcmp("EXIT", szBuffer))) { // // Yes - drop out and exit. // printf("Exiting on user request.\n"); break; } // // Write the user's string to the device. // bResult = WriteUSBPacket(hUSB, szBuffer, ulLength, &ulWritten); if(!bResult) { // // We failed to write the data for some reason. // dwError = GetLastError(); printf("Error %d (%S) writing to bulk OUT pipe.\n", dwError, GetSystemErrorString(dwError)); } else { // // We wrote data successfully so now read it back. // printf("Wrote %d bytes to the device. Expected %d\n", ulWritten, ulLength); // // We expect the same number of bytes as we just sent. // dwError = ReadUSBPacket(hUSB, szBuffer, ulWritten, &ulRead, INFINITE, NULL); if(dwError != ERROR_SUCCESS) { // // We failed to read from the device. // printf("Error %d (%S) reading from bulk IN pipe.\n", dwError, GetSystemErrorString(dwError)); } else { // // Add a string terminator to the returned data (this // should already be there but, just in case...) // szBuffer[ulRead] = '\0'; printf("Read %d bytes from device. Expected %d\n", ulRead, ulWritten); printf("\nReturned string: \"%s\"\n", szBuffer); } } } } } else { // // An error was reported while trying to connect to the device. // dwError = GetLastError(); printf("\nUnable to initialize the Luminary Bulk USB Device.\n"); printf("Error code is %d (%S)\n\n", dwError, GetSystemErrorString(dwError)); printf("Please make sure you have a Luminary Stellaris USB-enabled\n"); printf("evaluation or development kit running the usb_dev_bulk example\n"); printf("application connected to this system via the \"USB OTG\" or\n"); printf("\"USB DEVICE\" connectors. Once the device is connected, run\n"); printf("this application again.\n\n"); printf("\nPress \"Enter\" to exit: "); fgets(szBuffer, MAX_STRING_LEN, stdin); printf("\n"); return(2); } TerminateDevice(hUSB); return(0); }
int main(int argc, char *argv[]) { BOOL bDriverInstalled; DWORD dwError; // // Find our USB device and prepare it for communication. // hUSB = InitializeDevice(BULK_VID, BULK_PID, (LPGUID)&(GUID_DEVINTERFACE_STELLARIS_BULK), &bDriverInstalled); // hUSB = 0xaadd; if(hUSB) { //set timer // UINT uResult; MSG msg; UINT BallInfoNum; UINT ulWritten, bResult; FILE * fp; char ch; bResult = fopen_s(&fp, "initial.txt", "rw"); if(bResult){ printf("file open error!\n"); return -1; } // ch = getchar(); // read initial value and send to launchpad // fprintf(fp, "######!"); // fclose(fp); bResult = fread(TxBuffer, 4, 3, fp); if(bResult != 3){ printf("initial value read error!\n"); return -2; } DisplayHandler.test_mode = TxBuffer[0]; DisplayHandler.ball_num = TxBuffer[1]; DisplayHandler.time_interval = TxBuffer[2]; BallInfoNum = DisplayHandler.ball_num * sizeof(tBallData); bResult = fread(TxBuffer+3, 4, BallInfoNum, fp); if(bResult != BallInfoNum){ printf("initial ball information read error!\n"); return -3; } bResult = WriteUSBPacket(hUSB, (unsigned char *)TxBuffer, (BallInfoNum+3), (unsigned long *)&ulWritten); // if(!bResult) { } timer_id = SetTimer(NULL, NULL, 40, (TIMERPROC)TimerCallBack); if(timer_id == 0) { printf("error timer handle!\n"); } printf("time handle ready %d!\n", timer_id); while (GetMessage(&msg, NULL, 0, 0) != -1) DispatchMessage(&msg); while(1); } else{ // // An error was reported while trying to connect to the device. // dwError = GetLastError(); printf("\nUnable to initialize the Stellaris Bulk USB Device.\n"); printf("Error code is %d (%S)\n\n", dwError, GetSystemErrorString(dwError)); printf("Please make sure you have a Stellaris USB-enabled evaluation\n"); printf("or development kit running the usb_dev_bulk example\n"); printf("application connected to this system via the \"USB OTG\" or\n"); printf("\"USB DEVICE\" connectors. Once the device is connected, run\n"); printf("this application again.\n\n"); printf("\nPress \"Enter\" to exit: "); // fgets(rx_buf, MAX_STRING_LEN, stdin); printf("\n"); return(2); } TerminateDevice(hUSB); return(0); }