⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.h

📁 CYpress 7c68013的例子源码 示波器
💻 H
字号:

void EzSendMessage(CString& hDlg, int OpType, int* OtherOp, LPARAM pStr);
void ParseStringDescriptor(PVOID pvBuffer, CString& hOutputBox);

void EzSendMessage(CString& hDlg, int OpType, int* OtherOp, LPARAM pStr)
{
	TRACE("Send=%s\n", pStr);
	if(hDlg)
	{
		hDlg += (char*)pStr;
		hDlg += "\n";
	}
/*TPMTPMTPM
		int curCursorPos = hDlg->GetTextLength();
		if(curCursorPos)
			hDlg->SetSel(curCursorPos, curCursorPos);
		CString strOut;
		strOut.Format("%s\n", (char*)pStr);
		hDlg->ReplaceSel(strOut);
*/
}


/*CString STR_BOGUS_CRC_ERROR ="Data error (cyclic redundancy check)";
void ShowSystemError(CString& hOutputBox)
{
   DWORD LastErr;
   int test_int = 0;
  if(LastErr = GetLastError())
  {
	LPVOID lpMsgBuf;
	FormatMessage(     
	FORMAT_MESSAGE_ALLOCATE_BUFFER | 
	FORMAT_MESSAGE_FROM_SYSTEM |     
	FORMAT_MESSAGE_IGNORE_INSERTS,
	NULL,
	LastErr,
	MAKELANGID(LANG_NEUTRAL, 
	SUBLANG_DEFAULT), // Default language
	(LPTSTR) &lpMsgBuf,    
	0,    
	NULL 
	);// Process any inserts in lpMsgBuf.
	if( !memcmp((char *)lpMsgBuf, STR_BOGUS_CRC_ERROR, strlen(STR_BOGUS_CRC_ERROR)) )
	{// Supress bogus CRC error.
		EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Endpoint Error"); 
	}
	else
		EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)lpMsgBuf);
	LocalFree( lpMsgBuf );
  }
}
*/
/**************************************************
 * bOpenDriver proc                               *
 *                                                *
 * Purpose:                                       *  
 *      Opens the device driver using symbolic    *
 *      name provided                             *
 *                                                *
 * Input:                                         *
 *      phDeviceHandle:                           *
 *          Pointer to Device Driver handle where *
 *          the file handle is placed.            *
 *      devname:                                  *
 *          Null terminated string containing the *
 *          device name                           *
 *                                                *
 * Return Value:                                  *
 *      Boolean that indicates if the driver was  *
 *      successfully opened or not.               *
 *                                                *
 **************************************************/

BOOLEAN
bOpenDriver (HANDLE * phDeviceHandle, PCHAR devname)
{
    char completeDeviceName[64] = "";
    char pcMsg[64] = "";
	
    strcat (completeDeviceName,
		"\\\\.\\"
		);
	
    strcat (completeDeviceName,
		devname
		);

    *phDeviceHandle = CreateFile(   completeDeviceName,
		                            GENERIC_WRITE|GENERIC_READ,
		                            FILE_SHARE_WRITE|FILE_SHARE_READ,
		                            NULL,
		                            OPEN_EXISTING,
		                            0,
		                            NULL);

    if (*phDeviceHandle == INVALID_HANDLE_VALUE) {
        return (FALSE);
    } else {
        return (TRUE);
    } /*else*/


}//OpenDevice



typedef struct __usb_Dev_Descriptor__ {
    UCHAR bLength;
    UCHAR bDescriptorType;
    USHORT bcdUSB;
    UCHAR bDeviceClass;
    UCHAR bDeviceSubClass;
    UCHAR bDeviceProtocol;
    UCHAR bMaxPacketSize0;
    USHORT idVendor;
    USHORT idProduct;
    USHORT bcdDevice;
    UCHAR iManufacturer;
    UCHAR iProduct;
    UCHAR iSerialNumber;
    UCHAR bNumConfigurations;
} Usb_Device_Descriptor, *pUsb_Device_Descriptor;

/**************************************************
 * ParseDeviceDescriptor proc                     *
 *                                                *
 * Purpose:                                       *  
 *      Parses the device descriptor data and     *
 *      displays the interpretation to the        *
 *      windows specified                         *
 *                                                * 
 * Input:                                         *
 *      pvBuffer:                                 * 
 *          Pointer to a buffer that contains the *
 *          raw device descriptor data.           *
 *      hOutputBox:                               *
 *          Handle to the window where the        *
 *          resultant interpreted data is to go.  *
 *                                                *
 * Return Value:                                  *
 *          None                                  *
 **************************************************/
void
ParseDeviceDescriptor(PVOID pvBuffer, CString& hOutputBox)
{
    pUsb_Device_Descriptor pDevDescr = (pUsb_Device_Descriptor) pvBuffer;
    int                    nItems    = 0;
    char                   temp[64]  = "";

    //MAINTAIN_OUTPUT_BOX (hOutputBox, nItems);
    
    wsprintf (temp, "Device Descriptor:  ");
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "bLength:  %d", pDevDescr->bLength);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "bDescriptorType:  %d", pDevDescr->bDescriptorType);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "bcdUSB:  %d", pDevDescr->bcdUSB);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "bDeviceClass:  %#x", pDevDescr->bDeviceClass);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "bDeviceSubClass:  %#x", pDevDescr->bDeviceSubClass);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "bDeviceProtocol:  %#x", pDevDescr->bDeviceProtocol);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "bMaxPacketSize0:  %#x", pDevDescr->bMaxPacketSize0);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "idVendor:  %#x", pDevDescr->idVendor);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "idProduct:  %#x", pDevDescr->idProduct);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "bcdDevice:  %#x", pDevDescr->bcdDevice);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "iManufacturer:  %#x", pDevDescr->iManufacturer);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "iProduct:  %#x", pDevDescr->iProduct);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "iSerialNumber:  %#x", pDevDescr->iSerialNumber);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);

    wsprintf (temp, "bNumConfigurations:  %#x", pDevDescr->bNumConfigurations);
    EzSendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)temp);


}/* ParseDeviceDescriptor */ 

typedef PVOID USBD_PIPE_HANDLE;

typedef enum _USBD_PIPE_TYPE {
    UsbdPipeTypeControl,
    UsbdPipeTypeIsochronous,
    UsbdPipeTypeBulk,
    UsbdPipeTypeInterrupt
} USBD_PIPE_TYPE;

typedef struct _USBD_PIPE_INFORMATION {
    //
    // OUTPUT
    // These fields are filled in by USBD
    //
    USHORT MaximumPacketSize;  // Maximum packet size for this pipe
    UCHAR EndpointAddress;     // 8 bit USB endpoint address (includes direction)
                               // taken from endpoint descriptor
    UCHAR Interval;            // Polling interval in ms if interrupt pipe 
    
    USBD_PIPE_TYPE PipeType;   // PipeType identifies type of transfer valid for this pipe
    USBD_PIPE_HANDLE PipeHandle;
    
    //
    // INPUT
    // These fields are filled in by the client driver
    //
    ULONG MaximumTransferSize; // Maximum size for a single request
                               // in bytes.
    ULONG PipeFlags;                                   
} USBD_PIPE_INFORMATION, *PUSBD_PIPE_INFORMATION;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -