home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / usbd0906.zip / usb_20020906.zip / usbcalls / test / TESTBULK.CPP next >
C/C++ Source or Header  |  2001-11-13  |  3KB  |  138 lines

  1. #define INCL_DOS
  2. #include <os2.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. #include "..\usbcalls.h"
  8.  
  9. #define BULK_IOCTL 1
  10.  
  11. int SenseDevice(USBHANDLE hUSBDev)
  12. {
  13.   int rc;
  14.   ULONG i,ulActual;
  15.   UCHAR ucCommandSense[8] = { 0x00, 0x01, 0x00, 0x00,
  16.                               0x00, 0xa0, 0xec, 0x01};
  17.   UCHAR ucData[512];
  18. #if BULK_IOCTL
  19.   rc = UsbBulkWrite( hUSBDev, 0x01, 0x00, 8, ucCommandSense, 0);
  20.   if(rc)
  21.   {
  22.     printf("Faild to write sense command rc=%d\r\n",rc);
  23.   }
  24.   else
  25.   {
  26.     memset(ucData,sizeof(ucData),0);
  27.     rc = UsbBulkRead(hUSBDev, 0x82, 0x00, 512, ucData, 0);
  28.     ulActual = 512;
  29.     if(rc)
  30.       printf("Faild to Read Sense Data rc=%d\r\n",rc);
  31.   }
  32. #else
  33.   rc = DosWrite(hDrv, ucCommandSense, 8, &ulActual);
  34.   printf("SenseDevice Command written rc=%d, bytes written %d\r\n",rc, ulActual);
  35.   rc = DosRead(hDrv, ucData, 512, &ulActual);
  36.   printf("SenseDevice Read data rc=%d, bytes read %d\r\n",rc, ulActual);
  37. #endif
  38.   //if(rc==0)
  39.   {
  40.     printf("Data : ");
  41.     for(i=0;i<ulActual;i++)
  42.     {
  43.       printf("%02X ",ucData[i]);
  44.       if(((i+1)%16)==0)
  45.        printf("\r\n       ");
  46.     }
  47.     printf("\r\n");
  48.   }
  49.   return rc;
  50. }
  51.  
  52. int ReadSector(USBHANDLE hUSBDev, ULONG ulSector)
  53. {
  54.   int rc;
  55.   ULONG i,ulActual;
  56.   UCHAR ucCommandRead[8] = { 0x00, 0x01, 0x00, 0x00,
  57.                              0x00, 0xe0, 0x20, 0x01};
  58.   UCHAR ucData[512];
  59.  
  60. #if BULK_IOCTL
  61.   rc = UsbBulkWrite( hUSBDev, 0x01, 0x00, 8, ucCommandRead, 0);
  62.   if(rc)
  63.   {
  64.     printf("Faild to write command rc=%d\r\n",rc);
  65.   }
  66.   else
  67.   {
  68.     rc = UsbBulkRead(hUSBDev, 0x82, 0x00, 512, ucData, 0);
  69.     ulActual = 512;
  70.     if(rc)
  71.       printf("Faild to Read Data rc=%d\r\n",rc);
  72.   }
  73. #else
  74.   rc = DosWrite(hDrv,ucCommandRead,8, &ulActual);
  75.   printf("ReadSector Command written rc=%d, bytes written %d\r\n",rc, ulActual);
  76.   rc = DosRead(hDrv, ucData, 512, &ulActual);
  77.   printf("ReadSector Read data rc=%d, bytes read %d\r\n",rc, ulActual);
  78. #endif
  79.   if(rc==0)
  80.   {
  81.     printf("Data : ");
  82.     for(i=0;i<ulActual;i++)
  83.     {
  84.       printf("%02X ",ucData[i]);
  85.       if(((i+1)%16)==0)
  86.        printf("\r\n       ");
  87.     }
  88.     printf("\r\n");
  89.   }
  90.   return rc;
  91. }
  92.  
  93. #define VENDOR_DATAFAB 0x07C4
  94. #define PRODUCT_MD2    0xA002
  95.  
  96. void main()
  97. {
  98.   int rc,i;
  99.   ULONG ulNumDevices;
  100.   USBHANDLE hUSBDevice;
  101.   UCHAR ucData[20];
  102.  
  103.   rc = UsbQueryNumberDevices(&ulNumDevices);
  104.   printf("Num devices = %d (rc=%d)\r\n",ulNumDevices,rc);
  105.  
  106.   rc = UsbOpen( &hUSBDevice,
  107.                 VENDOR_DATAFAB,
  108.                 PRODUCT_MD2,
  109.                 USB_ANY_PRODUCTVERSION,
  110.                 USB_OPEN_FIRST_UNUSED);
  111.  
  112.   if(!rc && hUSBDevice!=0)
  113.   {
  114.  
  115.     rc = UsbSetDeviceConfiguration(hUSBDevice, 1);
  116.     printf("DataFab MD-2 Opened\r\n SetConfiguration 1 %s\r\n",(rc==0)?"SUCCESSFUL":"FAILED");
  117.     memset(ucData,0,sizeof(ucData));
  118.     if(!rc)
  119.     {
  120.       printf("Checking Configuration Current Configuration ");
  121.       rc = UsbGetDeviceConfiguration(hUSBDevice, ucData);
  122.       if(rc)
  123.         printf("FAILED");
  124.       else
  125.       {
  126.         printf("SUCCESSFUL\r\n  Configuration is %d\r\nTrying to Sense Device\r\n",ucData[0]);
  127.         rc = SenseDevice(hUSBDevice);
  128.         if(!rc)
  129.         {
  130.           printf("Trying to Read Sector 0\r\n");
  131.           rc = ReadSector(hUSBDevice,0);
  132.         }
  133.       }
  134.     }
  135.     UsbClose(hUSBDevice);
  136.   }
  137. }
  138.