6 Replies Latest reply on Apr 9, 2010 4:54 PM by anand.srinivasan.asokan

    Problem with CY7C68013A

    ricardo.valle
              Dear all,   
         
         
      I need help to solve the follow problem:   
      - I have an external harware connected to a PC, and this hardware use the component CY7C68013A. I´ve written a delphi code to get the information from USB, the problem happened when I open and close de software between the seventh and nith time that I do that.   
      - To map de dll to Delphi I written the follow code:   
         
         
      Thanks,   
         
         
      #include "targetver.h"   
      #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers   
      // Windows Header Files:   
      #include        
      #include          
      #include            
            
      #define DLLEXPORT extern "C" __declspec(dllexport)      
            
      int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)      
      {      
      if(reason == DLL_PROCESS_ATTACH)      
      printf("Carregou DLL\n");      
      else if(reason == DLL_PROCESS_DETACH)      
      printf("Descarregou DLL\n");      
      return 1;      
      }      
            
      //---------------------------------------------------------------------------      
            
      //USBDevice-----------------------------------------------------------------      
      CCyUSBDevice* device = NULL;      
            
      DLLEXPORT bool USBDevice_new(HANDLE hnd){      
      //if (device) {      
      // return true;      
      //}      
      __asm int 3;      
            
      device = new CCyUSBDevice(hnd);      
            
      if (!device) {      
      return false;      
      }      
      return true;      
      }      
            
      DLLEXPORT bool USBDevice_Open(UCHAR d){      
      return device->Open(d);      
      }      
            
      DLLEXPORT int USBDevice_DeviceCount(){      
      return device->DeviceCount();      
      }      
            
      DLLEXPORT bool USBDevice_HighSpeed(){      
      return device->bHighSpeed;      
      }      
            
      DLLEXPORT int USBDevice_VendorID(){      
      return device->VendorID;      
      }      
            
      DLLEXPORT int USBDevice_ProductID(){      
      return device->ProductID;      
      }      
            
      DLLEXPORT int USBDevice_EndPointCount(){      
      return device->EndPointCount();      
      }      
            
      DLLEXPORT void USBDevice_Close(){      
      device->Close();      
      }      
            
      DLLEXPORT void USBDevice_ReConnect(){      
      device->ReConnect();      
      }      
            
            
      DLLEXPORT void USBDevice_Reset(){      
      device->Reset();      
      }      
            
      //Endpoint-----------------------------------------------------------------      
      long lastLen[4] = {0, 0, 0 ,0};      
            
      DLLEXPORT void USBEndPoint_SetTimeout(int ep, int timeout){      
      device->EndPoints[ep]->TimeOut = timeout;      
      }      
            
      DLLEXPORT bool USBEndPoint_XferData(unsigned char *buf, long len, int ep){ // Talvez de pau por causa da referencia...      
      bool ret;      
      long lenRef = len;      
      ret = device->EndPoints[ep]->XferData(buf, lenRef);      
      lastLen[ep] = lenRef;      
      return ret;      
      }      
            
      DLLEXPORT int USBEndPoint_LastLen(int ep){      
      return lastLen[ep];      
      }      
            
      DLLEXPORT unsigned char USBEndPoint_Attributes(int ep){      
      return device->EndPoints[ep]->Attributes;      
      }      
            
      DLLEXPORT unsigned char USBEndPoint_Address(int ep){      
      return device->EndPoints[ep]->Address;      
      }      
            
      DLLEXPORT int USBEndPoint_BulkOutEndPtNumber(){      
      CCyBulkEndPoint* b = device->BulkOutEndPt;      
      for (int i=0; i < device->EndPointCount(); i++) {      
      if (b == device->EndPoints       ) {
      return i;
      }
      }
      return -1;
      }

      DLLEXPORT int USBEndPoint_BulkInEndPtNumber(){
      CCyBulkEndPoint* b = device->BulkInEndPt;
      for (int i=0; i < device->EndPointCount(); i++) {
      if (b == device->EndPoints) {
      return i;
      }
      }
      return -1;
      }