1

I am trying to communicate with a galil motion controler DMC2070 through its USB interface. The USB interface of the DMC2070 is made with a NET2888 chip but it is not supported by windows 7 or 10. I currently load the winusb driver and try to communicate with it with libusb-1.0 (statically linked 32bit version) and compile with mingw32-gcc under windows 10 (64bit). I managed to claim the interface but could not send or receive messages. Here is my test program :

#include <cstring>
#include <stdio.h>
#include "libusb/libusb.h"

int main(){
 char entry;
 libusb_context *context = nullptr;
 int status, nwrite;
 unsigned char buffer[64] = "TP\0";
 libusb_device_handle *handle = nullptr;

 printf("start usb test (y/n) ?");
 scanf("%c", &entry);
 if(entry=='n') return 0;

 libusb_init(&context);
 handle = libusb_open_device_with_vid_pid(context, 0x06B3, 0x07D1);
 if(handle){
    printf("Device %04x:%04x opened with success\n",0x06B3,0x07D1);
 }
 else {
    libusb_exit(nullptr);
    printf("device %04x:%04x not found\n",0x06B3,0x07D1);
    system("pause");
    return 1;
 }

 libusb_set_auto_detach_kernel_driver(handle, 1);
 status = libusb_claim_interface(handle,0);
 if(status!=0){
    libusb_close(handle);
    libusb_exit(nullptr);
    fprintf(stderr, "usb_claim_interface error %d\n", status);
    system("pause");
    return 2;
 }
 printf("Interface claimed successfully\n");

 status = libusb_bulk_transfer(handle, USB_ENDPOINT_OUT,
        buffer, 64, &nwrite, TIMEOUT);
 if(status==0) printf("send %d bytes to device\n", nwrite);
 else printf("error %d, writing to device\n", status);

 libusb_release_interface(handle,0);
 libusb_close(handle);
 libusb_exit(nullptr);

 system("pause");
 return 0;
}

Here is the resulting output :

start usb test (y/n) ?y
Device 06b3:07d1 opened with success
Interface claimed successfully
error -5, writing to device

Error -5 corresponds to LIBUSB_ERROR_NOT_FOUND which means "Entity not found".

I am not used to deal with USB interface directly, and hope someone with far more experience could enlighten my path. I am thinking about installing a vm with windows xp and try reverse the driver.

user2019716
  • 587
  • 4
  • 13
  • You have not checked the return value of `libusb_set_auto_detach_kernel_driver` which is `int`. It returns `0` on success and `LIBUSB_ERROR` code on failure. See [this](https://nxmnpg.lemoda.net/3/libusb_open_device_with_vid_pid). – kiner_shah Feb 28 '20 at 07:40

1 Answers1

0

you have to set the configuration before claim interface.

SRAK
  • 91
  • 1
  • 5