|
|
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;
}
|
ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.
Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.