분광계에서 데이터를 얻기 위해 WinUSB 프로젝트를 작성했습니다.이 코드는 몇 주 전에 작동하는 것 같습니다. 나중 단계에서이 프로젝트를 CUDA와 연결하려고 시도했지만 몇 번의 시련 끝에 CUDA 링커 오류를 해결했습니다. 불행히도 내 메인 프로그램 (Winusb 프로젝트)에서 "오류 LNK2019 : 해결되지 않은 외부 기호"이 발생했습니다. 처음에는 .cu 파일 때문이라고 생각하고 모든 .CU (CUDA) 파일을 프로젝트에서 제외하기로 결정했지만 여전히 동일한 오류 (LNK2019)를 받고있었습니다. 은 다음 Winusb 프로젝트에 대한 내 코드입니다 (다시 완벽하게 몇 주간 작업했지만, 지금은 완전히 잃고 도움이 필요 해요)하여 Main.cppWinusb 연결 오류를 해결하는 방법은 무엇입니까?
을
#include "pch.h"
#include <cstdio>
LONG __cdecl _tmain(LONG Argc, LPTSTR * Argv)
{
FILE *output_file1 = fopen("output_file2.txt", "w");
//FILE *output_file2 = fopen("output_file3.txt", "w");
DEVICE_DATA deviceData;
HRESULT hr;
USB_DEVICE_DESCRIPTOR deviceDesc;
BOOL bResult;
BOOL noDevice;
ULONG lengthReceived;
BOOL wrResult = TRUE;
BOOL wr1Result = TRUE;
BOOL RQResult = 0;
UNREFERENCED_PARAMETER(Argc);
UNREFERENCED_PARAMETER(Argv);
//////////////////////Open device ///////////////
hr = OpenDevice(&deviceData, &noDevice);
if (FAILED(hr)) {
if (noDevice) {
printf(_T("Device not connected or driver not installed\n"));
} else {
printf(_T("Failed looking for device, HRESULT 0x%x\n"), hr);
}
std::getchar();
return 0;
}
/////////////////////Get descriptor//////////////////
bResult = WinUsb_GetDescriptor(deviceData.WinusbHandle,
USB_DEVICE_DESCRIPTOR_TYPE,
0,
0,
(PBYTE) &deviceDesc,
sizeof(deviceDesc),
&lengthReceived);
if (FALSE == bResult || lengthReceived != sizeof(deviceDesc)) {
printf(_T("Error among LastError %d or lengthReceived %d\n"),
FALSE == bResult ? GetLastError() : 0,
lengthReceived);
CloseDevice(&deviceData);
return 0;
}
bool sResult = FALSE;bool syResult;
bool sResult1 = FALSE;bool syResult1;
//Initialize
UCHAR Intialize[] = {0x01};
ULONG cbISize = strlen((char*)Intialize);
ULONG InSent = 0;
wrResult = WinUsb_WritePipe(deviceData.WinusbHandle, 0x01, Intialize, 1, &InSent, 0);
//Integration time - 700ms
UCHAR Inttime[] = {0x0200100000};
ULONG cbITSize = strlen((char*)Inttime);
ULONG InttimeSent = 0;
wrResult = WinUsb_WritePipe(deviceData.WinusbHandle, 0x01, Inttime, 5, &InttimeSent, 0);
//strobe signal
UCHAR strobe1[] = {0x030001};
ULONG strobeSize1 = strlen((char*)strobe1);
ULONG strobeSent1 = 0;
wr1Result = WinUsb_WritePipe(deviceData.WinusbHandle, 0x01, strobe1, 3, &strobeSent1, 0);
//Request spectra
UCHAR Rqspectra[] = {0x09};
ULONG RqSize = strlen((char*)Rqspectra);
ULONG RqSent = 0;
RQResult = WinUsb_WritePipe(deviceData.WinusbHandle, 0x01, Rqspectra,1, &RqSent, 0);
//Pixel Values
UCHAR szBuffer[15][512];
UCHAR sz1Buffer[1];
UCHAR tBuffer[1];
ULONG tReadx;
ULONG cbReadx[16];
USHORT newbuf[15][512];
short specbu[7860];
for (int i=0;i<16;i++)
{
if (i<4)
{
sResult = WinUsb_ReadPipe(deviceData.WinusbHandle, 0x86, szBuffer[i], 512, &cbReadx[i], 0);
}
else if (i>=4 && i<15)
{
sResult = WinUsb_ReadPipe(deviceData.WinusbHandle, 0x82, szBuffer[i], 512, &cbReadx[i], 0);
}
else if (i = 15)
{
syResult = WinUsb_ReadPipe(deviceData.WinusbHandle, 0x82, sz1Buffer, 1, &cbReadx[i], 0);
}
}
int pon=0;
for (int k=0;k<15;k++)
{
for (int l=0;l<512;l+=2)
{
newbuf[k][l] = (szBuffer[k][(l+1)]<<8|szBuffer[k][l]);
specbu[pon]= (szBuffer[k][(l+1)]<<8|szBuffer[k][l]);
fprintf(output_file1,"%d\t\n",specbu[pon]);
pon++;
}
}
std::getchar();
CloseDevice(&deviceData);
return 0;
}
내 Pch.h
#include <Windows.h>
#include <tchar.h>
#include <strsafe.h>
#include <winusb.h>
#include <usb.h>
#include "device.h"
내 device.h 사용법 #include
//
// Device Interface GUID.
// Used by all WinUsb devices that this application talks to.
// Must match "DeviceInterfaceGUIDs" registry value specified in the INF file.
// 390a138c-f867-4538-8fd4-46063b842d2b
//
DEFINE_GUID(GUID_DEVINTERFACE_USBApplication2,
0x390a138c,0xf867,0x4538,0x8f,0xd4,0x46,0x06,0x3b,0x84,0x2d,0x2b);
typedef struct _DEVICE_DATA {
BOOL HandlesOpen;
WINUSB_INTERFACE_HANDLE WinusbHandle;
HANDLE DeviceHandle;
TCHAR DevicePath[MAX_PATH];
}
DEVICE_DATA, *PDEVICE_DATA;
HRESULT
OpenDevice(
_Out_ PDEVICE_DATA DeviceData,
_Out_opt_ PBOOL FailureDeviceNotFound
);
VOID
CloseDevice(
_Inout_ PDEVICE_DATA DeviceData
);
OpenDevice
CloseDevice
: 510,403,210 내 빌드 로그
1>------ Build started: Project: USB Application2, Configuration: Win7 Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol "long __stdcall OpenDevice(struct _DEVICE_DATA *,int *)" ([email protected]@[email protected]@[email protected]) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "void __stdcall CloseDevice(struct _DEVICE_DATA *)" ([email protected]@[email protected]@@Z) referenced in function _main
1>C:\Users\bel1\Documents\Visual Studio 2012\Projects\USB Application2\Win7Debug\USBApplication2.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
device.h는 OpenDevice와 CloseDevice (device.h를 추가했습니다)의 정의를 가지고 있으며 또한 사용자 정의 INF를 작성했습니다. 이전에 같은 프로그램이 작동 중이 었는데, 나는 마이크로 소프트 링크를 따라 갔다. (http://msdn.microsoft.com/en-us/library/windows/hardware/ff540283(v=vs.85).aspx) – Cedric
그러나' OpenDevice 함수? 어디에서 잡았 니? 일부 .CPP 파일이나 일부 라이브러리에 있어야합니다. 문서화 된 곳은 어디입니까? – Ajay
맞습니다. 실수로 device.cpp를 제거했습니다. 감사 – Cedric