2

Good day.
I'm progrmming interface for "MGX Analog Signal Generator N5181B" with libusb.
For a starting I have to init device, so next step is send data. For example I wanna change frequency that will displayed in generator.
My code:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <libusb.h>


using namespace std;
int main(int argc, char *argv[]) {

    if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG) != 1){
        cout<<"This platform hasn't support for hotplug callback notification"<<endl;
        return 0;
    }

    libusb_device_handle* dev_handle;
    libusb_device* dev;
    libusb_context* ctx = NULL;
    int r;

    r = libusb_init(&ctx);
    if (r < 0) {
        cout<<"Init error "<<r<<endl;
    }
    libusb_set_debug(ctx, 3);

    dev_handle = libusb_open_device_with_vid_pid(ctx, 1266, 45940);
    unsigned char data[15] = {':', 'F', 'R', 'E', 'Q', ' ', '5', '0', '0', '0', '0', ' ', 'K', 'H', 'Z'};
    int actual_length;
    r = libusb_bulk_transfer(dev_handle, LIBUSB_ENDPOINT_IN, data, sizeof(data), &actual_length, 0);

    libusb_exit(ctx);

    return 0;
}

Compile this get me follow:
libusb: error [submit_bulk_transfer] submiturb failed error -1 errno=2

Please, What I do wrong?
Thx for your attention.

Denny
  • 103
  • 8

2 Answers2

0

use libusb_detach_kernel_driver and libusb_claim_interface if you want to make bulk transfer on current device. After transaction release_inerface and close device

Simon L.
  • 21
  • 1
  • status = libusb_open2(device, &devh, fd); if (status != LIBUSB_SUCCESS) return status; if (libusb_kernel_driver_active(devh, 0) == 1) { if (!libusb_detach_kernel_driver(devh, 0)) { status = libusb_claim_interface(devh, 0); – Simon L. Mar 20 '17 at 18:04
  • Thx you, look like it helped, but I don't have device right now. May you tell pls, Have to I use 0 like second argument every time? – Denny Mar 20 '17 at 18:10
  • 0 is interface number – Simon L. Mar 20 '17 at 19:13
0

You forgot putting your device endpoint in bulk transfer it will be something like:

libusb_bulk_transfer(dev_handle, (0x81 | LIBUSB_ENDPOINT_IN), response, 24, &actual, 0);

note : 0x81 is endpoint of my device

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Sharofiddin
  • 340
  • 2
  • 14