S
S
Slavka2015-12-02 06:41:44
Microcontrollers
Slavka, 2015-12-02 06:41:44

Transfer and read data from microcontroller using libusb?

QMessageBox *msg = new QMessageBox(this);
 
    
    unsigned char input[] = {0x10};
 
    libusb_init(NULL);
    libusb_device_handle *dev = libusb_open_device_with_vid_pid(NULL, device->getVID(), device->getPID());
 
    if(dev == NULL) {
 
        msg->setText("Device no Find");
        msg->show();
 
        return; }
 
    int transferred;
    int ret;
    if (libusb_kernel_driver_active(dev,0))
            libusb_detach_kernel_driver(dev,0);
        if ((ret = libusb_set_configuration(dev, 1)) < 0)
        {
            msg->setText("Ошибка");
            msg->show();
        }
        if (libusb_claim_interface(dev, 0) < 0)
        {
            msg->setText("Ошибка");
            msg->show();
        }
 
     
   ret = libusb_interrupt_transfer(dev, 0x01, input, sizeof(input), &transferred, 1000);
 
    if (ret < 0){
 
        msg->setText("Ошибка");
        msg->show();
    }
 
     libusb_attach_kernel_driver(dev, 0);
     libusb_release_interface(dev, 0);
     libusb_close(dev); 
     libusb_exit(NULL); 
 
 
     msg->setText(QString(input[0]));
     msg->show();

here is the code for sending data, the code works and does not give any error, but the data does not come, I try to change the breakpoint to IN to get the data, the reaction is the same. Although Keil's trivial example of lighting the LEDs on this device works

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
monah_tuk, 2015-12-02
@monah_tuk

Study this guide: habrahabr.ru/post/261955
And in fact, it’s difficult to talk about something without USB descriptors (on Linux: lsusb -v, on Windows: UsbView). Well, check that you really use interrupt transfer and that the code on the device itself is correct.
And so, I don’t see any crime: transfer to the device, which means EP OUT, you have it EP1, which means 0x01. So most likely the problem is on the device. Try, for a start, control transfering.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question