Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 12 of 12
You might want to describe your case in detail. - Which embedded linux board? - What linux distribution, version and architecture are you using? - connected to what and how? ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,356

    You might want to describe your case in detail.
    - Which embedded linux board?
    - What linux distribution, version and architecture are you using?
    - connected to what and how?
    - which device is the host, which is the mass storage device?
    - is there a filesystem on that storage device? If yes: which. If no: Do you intend to use one?
    - what is the purpose of your program
    - can you provide documented code examples of what you already have done with libusb?
    - etc
    You must always face the curtain with a bow.

  2. #12
    Just Joined!
    Join Date
    Aug 2012
    Posts
    7
    atngw100(atmel linux)
    kernel version is 2.6.35.4
    connected to with usart and ethernet
    pc is host and myboard is device
    yes-ext2
    my purpose is send file to sdcard of board that connect via usb to pc
    my code is:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <string.h>
    #include <libusb-1.0/libusb.h>
    int main (int argc, char *argv)
    {
    libusb_device **devList = NULL;
    libusb_device *devPtr = NULL;
    libusb_device_handle *devHandle = NULL;
    struct libusb_device_descriptor devDesc;
    libusb_context *ctx = NULL;

    //fclose(fp);
    unsigned char strDesc[256];
    ssize_t numUsbDevs = 0; // pre-initialized scalars
    ssize_t idx = 0;
    int retVal = 0;
    printf ("*************************\n USB Experiment Program:\n*************************\n");
    retVal = libusb_init (NULL);
    if(retVal!=0 )
    return;
    libusb_set_debug(ctx, 3);
    numUsbDevs = libusb_get_device_list (NULL, &devList);
    while (idx < numUsbDevs)
    {
    printf ("\n[%d]\n",(int)idx+1);
    devPtr = devList[idx];

    retVal = libusb_get_device_descriptor (devPtr, &devDesc);

    printf("VendorID:%d \n",(int)devDesc.idVendor) ;
    printf("ProductID:%d\n ",(int)devDesc.idProduct);
    struct libusb_config_descriptor *config;
    libusb_get_config_descriptor(devPtr, 0, &config);
    printf("Interfaces:%d\n", (int)config->bNumInterfaces);
    int r1;
    /* if((int)devDesc.idVendor==1256 && (int)devDesc.idProduct==2664
    {
    printf("device exist\n");
    devHandle=NULL;
    devHandle = libusb_open_device_with_vid_pid(ctx,(ssize_t)1256, (ssize_t)2664;
    //r1=libusb_open(devPtr,&devHandle);
    if(devHandle==NULL)
    printf("opening faild\n");
    }*/

    const struct libusb_interface *inter;
    const struct libusb_interface_descriptor *interdesc;
    const struct libusb_endpoint_descriptor *epdesc;
    int i=0;
    for(i; i<(int)config->bNumInterfaces; i++) {
    inter = &config->interface[i];
    printf("Number of alternate settings:%d \n",(int)inter->num_altsetting);
    int j=0;
    for(j; j<inter->num_altsetting; j++) {
    interdesc = &inter->altsetting[j];
    printf("Interface Number:%d \n",(int)interdesc->bInterfaceNumber);
    printf("Number of endpoints:%d\n ",(int)interdesc->bNumEndpoints);
    int k=0;
    for( k; k<(int)interdesc->bNumEndpoints; k++) {
    epdesc = &interdesc->endpoint[k];
    printf("Descriptor Type: %d\n",(int)epdesc->bDescriptorType);
    printf("EP Address: %d\n",(int)epdesc->bEndpointAddress);
    printf("max packet size is:%d \n",epdesc->wMaxPacketSize);


    }
    }
    }
    printf("\n \n \n");
    printf("end of while loop\nssize_t\n");

    devHandle = NULL;
    idx++;
    } // end of while loop
    printf("end of while loop2\n");
    //printf("bbbbbj");

    devHandle = libusb_open_device_with_vid_pid(ctx,(ssize_t)1423, (ssize_t)25479);
    if(devHandle==NULL){
    printf("bbbbbj");
    }

    libusb_free_device_list(devList, 1);


    unsigned char data[20];
    int f=0;
    }
    data[0]='a';
    data[1]='b';
    data[2]='c';
    data[3]='d';
    int actual,r;
    unsigned char rd_tmp[1000];
    libusb_detach_kernel_driver(devHandle,0);
    r = libusb_claim_interface(devHandle, 0);
    printf("%d\n",r);
    if(r==0)
    {
    r = libusb_bulk_transfer(devHandle,1,data,4, &actual, 0);
    if(r == 0) //we wrote the 4 bytes successfully
    printf("Writing Successful!\n");
    else
    printf("Write Error\n");
    /*r = libusb_bulk_transfer(devHandle,(uint8_t)129,rd_tmp , 100,&actual, 500);

    if (r < 0)
    {
    //printf("error reading:\n%s\n", usb_strerror());
    printf("Bulk Read Failure%d\n",r);
    }
    else
    printf("Bulk Read Success\n");
    }
    printf("%d",rd_tmp[0]);*/
    }
    if (devHandle != NULL)
    {


    libusb_close (devHandle);
    }

    libusb_exit (NULL);

    printf ("\n*************************\n Done\n*************************\n");
    return 0;
    }

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •