• PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 65KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 38
    下载次数
  • 2005-08-25 05:30
    上传日期
code for debug usb printer cla
vcdebug.rar
  • Main.cpp
    4.2KB
  • www.pudn.com.txt
    218B
  • Usbdebug.rc
    3KB
  • USB DEBUG.ncb
    225KB
  • USB DEBUG.opt
    55.5KB
  • Functions.cpp
    7.6KB
  • usbdebug.h
    2.2KB
  • Main.ico
    766B
  • Usbdebug.aps
    32.3KB
  • USB DEBUG.dep
    302B
  • resource.h
    1017B
  • USB.cpp
    9.1KB
  • USB DEBUG.dsp
    4.3KB
  • USB DEBUG.dsw
    543B
  • USB DEBUG.mak
    5.2KB
  • USB DEBUG.plg
    2.3KB
内容介绍
#include "usbdebug.h" #define DBG_COMMAND_SIZE 64 #define DBG_PACKET_SIZE 64 //Follow is the leader for a command data #define DBG_COMMAND_START0 0xFF #define DBG_COMMAND_START1 0xAA #define DBG_COMMAND_START2 0x55 //follow is command #define DBG_RESET_DEVICE 0x01 //reset flash #define DBG_GET_PRINTFS 0x02 #define DBG_UPDATE_SDRAM 0x03 #define DBG_UPDATE_FLASH 0x04 #define DBG_DOWNLOAD_SDRAM 0x05 #define DBG_CHECK_VERSION 0x06 #define DBG_RESET_SDRAM 0x07 unsigned char DevicePortName[256]; unsigned char DM_buffer[256]; void Process_Device_Message(DWORD Msg_Size, unsigned char *Msg_buffer); DWORD Read_Device_Message(unsigned char *DataBuffer); bool Connect_Usb_Device(void); /************************************************************************* Check if USB device attach? *************************************************************************/ bool USB_Detecting_Device(void) { HDEVINFO hDev; SP_DEVICE_INTERFACE_DATA devIntData; SP_DEVICE_INTERFACE_DETAIL_DATA *devIntDetail; bool Printer_Detect_Flag; DWORD index,rv,cbNeeded,err; /* printer usb interface GUID */ GUID ObjGUID={0x28d78fad,0x5a12,0x11d1,0xae,0x5b,0x00,0x00,0xf8,0x03,0xa8,0xc2}; if(UsbM.CurrentStatus != ATTACH_STATUS) return true; devIntData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); devIntDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(256); devIntDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); // for(index=0,Printer_Detect_Flag = false;index<6;index++) { hDev = SetupDiGetClassDevs(&ObjGUID,NULL,NULL, DIGCF_PRESENT|DIGCF_INTERFACEDEVICE); if(hDev == INVALID_HANDLE_VALUE) break; rv = SetupDiEnumDeviceInterfaces(hDev, NULL, &ObjGUID, index, &devIntData); if(rv==0) break; rv = SetupDiGetDeviceInterfaceDetail(hDev, &devIntData, devIntDetail, 256, &cbNeeded, NULL); if(rv==0) break; else { strcpy((char *)DevicePortName,devIntDetail->DevicePath); UsbWrite((char *)DevicePortName); UsbWrite(" Obtained \r\n================================================================================= \r\n"); Printer_Detect_Flag = true; RW_Handle = INVALID_HANDLE_VALUE; SetupDiDestroyDeviceInfoList(hDev); } } free(devIntDetail); if(hDev != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(hDev); if(Printer_Detect_Flag == true) return true; else{ err = GetLastError(); //find in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp return false; } } /************************************************************************* Usb dectect device message (Comunicationing����) *************************************************************************/ bool USB_Conmunication(void) { DWORD R_Size; R_Size = 0; if((RW_Handle==INVALID_HANDLE_VALUE)||(RW_Handle==NULL)) RW_Handle = CreateFile( (char *)DevicePortName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL ); if(RW_Handle==INVALID_HANDLE_VALUE) { int werr=GetLastError(); return false; } if(Connect_Usb_Device() == false){ ResetDeviceHandle(); return false; } Sleep(100); R_Size = Read_Device_Message(DM_buffer); while(R_Size>0) { Process_Device_Message(R_Size, DM_buffer); R_Size = Read_Device_Message(DM_buffer); } return true; } /************************************************************************* Usb host(PC) send a command to device *************************************************************************/ bool Connect_Usb_Device(void) { OVERLAPPED ov; bool rv; DWORD cbRead,cbWrote; int timeout; unsigned char CmdRequest[64] = {DBG_COMMAND_START0, DBG_COMMAND_START1, DBG_COMMAND_START2, DBG_GET_PRINTFS }; cbWrote=0; memset(&ov, 0, sizeof(ov)); rv = WriteFile(RW_Handle, CmdRequest, 64, &cbWrote, &ov); int werr=GetLastError(); if(werr==ERROR_ACCESS_DENIED) return false; if(rv == true) return true; for(timeout=0; timeout<4; timeout++) { rv = GetOverlappedResult(RW_Handle, &ov, &cbRead, FALSE); if(rv == true) return true; Sleep(5); } return false; } /************************************************************************* Usb host(PC) Get message form printer device *************************************************************************/ DWORD Read_Device_Message(unsigned char *DataBuffer) { OVERLAPPED ov; BOOL rv; int timeout; DWORD cbRead; memset(&ov, 0, sizeof(ov)); cbRead = 0; rv = ReadFile(RW_Handle, DataBuffer, DBG_PACKET_SIZE, &cbRead, &ov); int werr=GetLastError(); if(werr==ERROR_ACCESS_DENIED) return 0; if(rv == true) return cbRead; for(timeout=0;timeout<6;timeout++) { rv = GetOverlappedResult(RW_Handle, &ov, &cbRead, FALSE); if(rv == true) return cbRead; Sleep(1); } if(cbRead == 0) //ResetDeviceHandle(); CancelIo(RW_Handle); return cbRead; } /************************************************************************* Process device message and ouput in windows *************************************************************************/ void Process_Device_Message(DWORD Msg_Size, unsigned char *Msg_buffer) { int i,j,Pindex,stringlen; char Newstring[100]; static DWORD BlockSize=0; Pindex=0; while(Msg_Size>0) { //check get Command head if(Msg_buffer[Pindex]==DBG_COMMAND_START0) { if(Msg_buffer[Pindex+1]==DBG_COMMAND_START1) if(Msg_buffer[Pindex+2]==DBG_COMMAND_START2) if(Msg_buffer[Pindex+3]==DBG_GET_PRINTFS) { BlockSize = Msg_buffer[4]; BlockSize += Msg_buffer[5]<<8; BlockSize += Msg_buffer[6]<<16; BlockSize += Msg_buffer[7]<<24; Msg_Size = Msg_Size - DBG_COMMAND_SIZE; Pindex=Pindex + DBG_COMMAND_SIZE; } } if((BlockSize>0)&&(Msg_Size>0)) { if(BlockSize>Msg_Size) { BlockSize-=Msg_Size; stringlen=Msg_Size; Msg_Size=0; } else { Msg_Size -= BlockSize; stringlen=BlockSize; BlockSize = 0; } /* make sure the line end*/ for(i=Pindex,j=0;i<stringlen;i++) if(((Msg_buffer[i]=='\n')&&(Msg_buffer[i-1]!='\r'))||(Msg_buffer[i]=='\0')) { Newstring[j++]='\r'; Newstring[j++]='\n'; } else Newstring[j++]=Msg_buffer[i]; Newstring[j]='\0'; UsbWrite(Newstring); Pindex=Pindex+stringlen; } else{ Msg_Size = 0; BlockSize = 0; } } return ; } void ResetDeviceHandle(void) { CloseHandle(RW_Handle); CancelIo(RW_Handle); RW_Handle==INVALID_HANDLE_VALUE; } bool UpdateFirmware(REQUESTTYPE Mode) { static TCHAR pstrFileName[MAX_PATH]; if(UsbM.CurrentStatus != WORKING_STATUS){ UsbWrite("Error, No any Device attach!!\r\n"); return false; } if((Mode == UPDATA_SDRAM)||(Mode == UPDATA_FLASH)) if(OpenAFile (pstrFileName) == false) return false; if(SendBinFileToFW(pstrFileName,Mode) == true) return true; else return false; } bool SendBinFileToFW(TCHAR pFileName[], REQUESTTYPE sMode) { bool rv; PBYTE BlcokBuf; HANDLE hFile,hDevice; DWORD dwBytesRead,BlockLen,iFileLength,SendLen,msecs; UsbWrite("\r\n\r\n ** "); UsbWrite(pFileName); if(sMode == UPDATA_FLASH) UsbWrite(" ** Flash Updating ...\r\n"); else UsbWrite(" ** SDRam Updating ...\r\n"); Disable_Muli_Thread(); hDevice = INVALID_HANDLE_VALUE; hFile = INVALID_HANDLE_VALUE; hDevice = CreateFile( (char *)DevicePortName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); i
评论
    相关推荐
    • printer.rar
      printer.c Printer gadget driver.
    • android usb
      用于电脑和android手机系统宽带共享!
    • printer.zip
      android通过USB打印机打印图文混排的小条,包括USB连接,打印。
    • stm32f407 USBD VCP+Printer 精简工程
      STM32F407 实现USB设备类(vcp+printer)驱动,该工程为精简工程,为初学者提供的精简工程(不包含其他无关驱动代码。开发工具:IAR7.4。
    • wechat_printer
      HP Deskjet 1010 printer (含墨盒),淘宝上最便宜的一款彩色喷墨打印机,174¥ 8寸1024*768 液晶屏显示器套件HDMI+VGA+2AV,278¥ 一条短hdmi线,5¥ A7相纸100张,10¥ 8cm散热风扇5V,10¥ 电源插板,变压器,一...
    • Brother MFC-7220 USB Printer_3.25.0.0_6.1_x86
      兄弟一体机驱动 Brother MFC-7220 USB Printer_3.25.0.0_6.1_x86
    • luci-app-usb-printer.rar
      usb打印很不方便,琢磨着用淘汰的703N刷上OPENWRT做个打印服务器,搞了一晚上,终于搞定了,其中这个文件很重要也是是很难找的,不敢私藏。
    • GL640USB
      GL640USB IEEE-1284 to USB Bridge
    • escpos-printer:nodejs usb热敏小票打印机驱动
      目前只针对佳博80mm系列印机和广州优库打印模组使用usb连接方式做了测试,确保能正常使用。 其它牌子的打印机没有做实测,不过理论上来说只要打印机支持escpos指令即可兼容,也有可能各家打印机在指令兼容上面各有...
    • USB.rar
      简单介绍usb