]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blob - fx2lib/examples/bulkloop/test.cpp
Import fx2lib into fx2lafw directly.
[sigrok-firmware-fx2lafw.git] / fx2lib / examples / bulkloop / test.cpp
1 /**
2  * Copyright (C) 2009 Ubixum, Inc. 
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  **/
18 #include <cstdio>
19 #include <cassert>
20 #include <libusb-1.0/libusb.h>
21
22 int main(int argc, char* argv[]) {
23
24  libusb_context* ctx;
25  libusb_init(&ctx);
26
27  libusb_device_handle* hndl = libusb_open_device_with_vid_pid(ctx,0x04b4,0x1004);
28  libusb_claim_interface(hndl,0);
29  libusb_set_interface_alt_setting(hndl,0,0);
30  
31  unsigned short buf[100];
32  for (int i=0;i<100;++i) {
33   buf[i]=i;
34  }
35  int transferred;
36  int rv=libusb_bulk_transfer(hndl,0x02,(unsigned char*)buf,sizeof(buf),&transferred,100);
37  if(rv) {
38   printf ( "OUT Transfer failed: %d\n", rv );
39   return rv;
40  }
41
42  unsigned short buf2[100];
43  rv=libusb_bulk_transfer(hndl,0x86,(unsigned char*)buf2,sizeof(buf2),&transferred,100); 
44  if(rv) {
45   printf ( "IN Transfer failed: %d\n", rv );
46   return rv;
47  }
48  for (int i=0;i<100;++i) {
49   printf ( "%d ", buf2[i] );
50  }
51  printf("\n");
52
53  return 0;
54 }