#64 Data rate issues

v1.0_(example)
open
nobody
None
1
2014-10-05
2012-08-06
Nicolas Roudel
No

Hello,

I'm trying to use libusb to use an USB2 controller from cypress (CY7C68013A). I currently used bulk_read & write and i have a datarate issue. On the attached picture, you can see the differences between the read request with libusb & CyAPI. So, how can i get same speed with libusb than with cyapi ?

regards,

N1co.

My C code is as the following:

include <stdio.h>

include <windows.h>

include <stdlib.h>

include "ihm.h"

//#include <lusb0_usb.h>

include "lusb0_usbv2.h"

include "CImg.h"

// DEVICE SETUP (User configurable)

// Device vendor and product id.

define MY_VID 0x04B4

define MY_PID 0x1003

// Device configuration and interface id.

define MY_CONFIG 1

define MY_INTF 0

// Device endpoint(s)

define EP6 0x86

define EP2 0x02

// Device of bytes to transfer.

define BUF_SIZE 512

using namespace cimg_library;

//////////////////////////////////////////////////////////////////////////////
usb_dev_handle *open_dev(void);

usb_dev_handle open_dev(void)
{
struct usb_bus
bus;
struct usb_device *dev;

for (bus = usb_get_busses(); bus; bus = bus->next)
{
    for (dev = bus->devices; dev; dev = dev->next)
    {
        if (dev->descriptor.idVendor == MY_VID
                && dev->descriptor.idProduct == MY_PID)
        {
            return usb_open(dev);
        }
    }
}
return NULL;

}

int main(int argc, char* argv[])
{
int ret,i,j=0,imr=0;
int lig,col;
int periph= 0;
short read_data[BUF_SIZE];
short signal_depart[1];

lig = 480;
col = 752;

FILE * res;
res = fopen ("res.txt","w");

CImg<unsigned char>imgres(col,lig,1,1);
unsigned char *ptrRaw = imgres.ptr(0, 0, 0);

CImgDisplay main_dispres(imgres, "Image 1", 0, 3, false, false);

signal_depart[0]=0xABCD;

usb_dev_handle *dev = NULL; /* the device handle */

usb_init();
usb_find_busses();
// -----------------------------------------------------------------------------------------------------------------------------------
// Initialisation des périphériques USB
// -----------------------------------------------------------------------------------------------------------------------------------
while(periph == 0){
    periph=usb_find_devices();
    if(periph > 0 )
        periph = 1;
    else
        periph = 0;
}
dev = open_dev();
// -----------------------------------------------------------------------------------------------------------------------------------
// On test la présence d'un composant USB
// -----------------------------------------------------------------------------------------------------------------------------------
if (!(dev = open_dev()))
{
    printf("error opening device: \n%s\n", usb_strerror());
    return 0;
}
else
{
    printf("success: device %04X:%04X opened\n", MY_VID, MY_PID);
}
// -----------------------------------------------------------------------------------------------------------------------------------
// On charge le configuration du composant USB - la valeur de MY_CONFIG doit correspondre au registre bConfigurationValue
// -----------------------------------------------------------------------------------------------------------------------------------
if (usb_set_configuration(dev, MY_CONFIG) < 0)
{
    printf("error setting config #%d: %s\n", MY_CONFIG, usb_strerror());
    usb_close(dev);
    return 0;
}
else
{
    printf("success: set configuration #%d\n", MY_CONFIG);
}
// -----------------------------------------------------------------------------------------------------------------------------------
// On charge l'interface du composant USB - a valeur de MY_INTF doit correspondre au registre bInterfaceNumber
// -----------------------------------------------------------------------------------------------------------------------------------
if (usb_claim_interface(dev, MY_INTF) < 0)
{
    printf("error claiming interface #%d:\n%s\n", MY_INTF, usb_strerror());
    usb_close(dev);
    return 0;
}
else
{
    printf("success: claim_interface #%d\n", MY_INTF);
}
// -----------------------------------------------------------------------------------------------------------------------------------
// Debut de l'application
// -----------------------------------------------------------------------------------------------------------------------------------
printf("Debut de l application \n Appuyer sur 1 \n");
scanf("%d",&i);
if(i == 1){
    printf("Envoye du signal de depart \n");
    ret=usb_bulk_write(dev, EP2, signal_depart, sizeof(signal_depart),0);
       if (ret < 0)
        {
            printf("error writing:\n%s\n", usb_strerror());
        }
        else
        {
            printf("success: Envoye du signal de depart\n");
        }
}
else
{
    printf("valeur incorrecte \n");
    return 0;
}
while(1){
    usb_bulk_read(dev, EP6, read_data, sizeof(read_data),0);
    for(i=0;i< BUF_SIZE;i++){
       *(ptrRaw+j) = read_data[i];
       //fprintf(res,"%x \n", read_data[i]);
       j++;

       if(j == lig*col){
        if(imr==0)
            imgres.save("Res.bmp");

        imr++;
        main_dispres.display(imgres);
        //printf("im %d\n",imr);
        j = 0;
        }
    }
  }
imgres.save("Res.bmp");
system("PAUSE");
if (dev)
{
    usb_release_interface(dev,MY_INTF);
    usb_close(dev);
    fclose(res);
}

printf("Done.\n");
return 0;

}

1 Attachments

Discussion

  • Xiaofan Chen
    Xiaofan Chen
    2013-02-19

    You will have to use the async API.