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

📄 slusb.c

📁 包括EZ811和SL811的文档
💻 C
字号:
/*----------------------------------------------------------------------------------
 Copyright:  (c)2000 ScanLogic Corporation

 File name:
 
        - slusb.c

 Abstract:

        - This file include the Readfile and Writefile between SL11H or USB PC Host
          interface. If the SL11H does not existed, then the USB Host in the PC will
          be used.
Author:

        - create	SNguyen
History:
		- Apr/14/2000 			SNguyen
		- May/24/2000			Support slow-speed device
        - August/17/2000        support both SL11H and SL811H
----------------------------------------------------------------------------------*/
#include <windows.h>
#include "slusb.h"
#include "sl811h.c"

static int hDev=0;
HANDLE hUsbDev=0;

//***********************************************************************************
// uVendorCmdRd: control endpoint read
//         bCmd     Command Opcode
//         wValue   User 1st Parameter 
//         wIndex   User 2nd Parameter 
//         wLen     Length for pData
//         pData    User's data buffer pointer
// Return      :	BOOL	TRUE means successful, else FAIL
//***********************************************************************************
BOOL uVendorCmdRd(BYTE bCmd, WORD wValue, WORD wIndex, WORD wLen, PVOID pData)
{  DWORD cbRet;
   DevReq devreq;

   if (hDev==SL11H) return VendorCmd(0xc0, bCmd, wValue, wIndex, wLen, pData);
   devreq.ioBuff    = (PBYTE)pData;
   devreq.bmRequest = 0xc0;	//host read
   devreq.bRequest  = bCmd;
   devreq.wValue    = wValue;
   devreq.wIndex    = wIndex;
   devreq.wLength   = wLen;
   return DeviceIoControl((HANDLE)hDev,
	                     (DWORD)IOCTL_VENDOR_CONTROL,
	   					 (PVOID)&devreq,
						 (DWORD)sizeof(DevReq),
						 NULL,     
						 (DWORD)0, 
   						 &cbRet,
						 NULL);
}
//***********************************************************************************
// uVendorCmdWr	 control endpoint write
//         bCmd     Command Opcode
//         wValue   User 1st Parameter 
//         wIndex   User 2nd Parameter 
//         wLen     Length for pData
//         pData    User's data buffer pointer
// Return      :	BOOL	TRUE means successful, else FAIL
//************************************************************************************
BOOL uVendorCmdWr(BYTE bCmd, WORD wValue, WORD wIndex, WORD wLen, PVOID pData)
{  DWORD cbRet;
   DevReq devreq;

   if (hDev==SL11H) return VendorCmd(0x40, bCmd, wValue, wIndex, wLen, pData);
   devreq.ioBuff   = (PBYTE)pData;
   devreq.bmRequest=0x40;	//host write
   devreq.bRequest = bCmd;
   devreq.wValue   = wValue;
   devreq.wIndex   = wIndex;
   devreq.wLength  = wLen;
   return DeviceIoControl((HANDLE)hDev,
	                     (DWORD)IOCTL_VENDOR_CONTROL,
	   					 (PVOID)&devreq,
						 (DWORD)sizeof(DevReq),
						 NULL,     
						 (DWORD)0, 
   						 &cbRet,
						 NULL);
}

/***************************************************************************/
BOOL uFindUsbDev()
{ 
   HANDLE hUsbDev;
   if (hDev==0) FindUsbDev();
   if (hDev==0)
   { 
      if ((hUsbDev=CreateFile(SYSFILE,
                              GENERIC_WRITE|GENERIC_READ,
                              0,
                              NULL,
                              OPEN_EXISTING,
                              0,
                              NULL )) !=  INVALID_HANDLE_VALUE) 
      { 
         hDev = (int)hUsbDev;
         return TRUE;
      }
      hDev = 0;
      return FALSE;
   }
   return TRUE;
}


/***************************************************************************/
void uCloseUsbDev()
{ 
   if (hDev != SL11H)
   {  CloseHandle((HANDLE)hDev);
      hDev = 0;
   }
}


/***************************************************************************/
BOOL uDataRead(DWORD cData, PVOID pData)
{   
    DWORD dwRet;

    if (hDev==SL11H) return DataRead(cData, pData); 

    if (!ReadFile((HANDLE)hDev, pData, cData, &dwRet, NULL)) return FALSE;

    if (dwRet < cData) return FALSE;
    return TRUE;
}

/***************************************************************************/
BOOL uDataWrite(DWORD cData, PVOID pData)
{
    DWORD dwRet;
    if (hDev==SL11H) return DataWrite(cData, pData); 

    if (!WriteFile((HANDLE)hDev, pData, cData, &dwRet, NULL)) return FALSE;

    if (dwRet<cData) return FALSE;
    return TRUE;
}

⌨️ 快捷键说明

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