Advertisement
Guest User

funzt nicht :-(

a guest
Sep 19th, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.51 KB | None | 0 0
  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <sys/ioctl.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <fcntl.h>
  9. #include <unistd.h>
  10. #include <linux/input.h>
  11. #include <linux/ioctl.h>
  12. #include <errno.h>
  13. #include <sys/time.h>
  14.  
  15. #include "iowarrior.h"
  16. #include "iowkit.h"
  17.  
  18. #define USB_DEVICE_ID_CODEMERCS_IOW56   0x1503
  19.  
  20.  BOOLEAN WriteSimple(IOWKIT_HANDLE devHandle, DWORD value)
  21.  {
  22.    IOWKIT56_IO_REPORT rep56;
  23.  
  24.    // Init report
  25.       memset(&rep56, 0xff, sizeof(rep56));
  26.       rep56.ReportID = 0;
  27.       rep56.Bytes[6] = (UCHAR) value;
  28.     return IowKitWrite(devHandle, IOW_PIPE_IO_PINS,(PCHAR) &rep56, IOWKIT56_IO_REPORT_SIZE) == IOWKIT56_IO_REPORT_SIZE;
  29.  }
  30.  
  31.  int main (int argc, char **argv) {
  32.      struct iowarrior_info info;
  33.      int fd = -1;
  34.      int i, j;
  35.      int ports=0;   //the number depends on the product
  36.      int numIows;
  37.      //fd_set wrfds;    /* the write-set for select */
  38.      //fd_set rfds; /* the read-set for select */
  39.      //struct timeval tv;   /* the timeout for select */
  40.      //unsigned char buffer[64];    
  41.      IOWKIT_SPECIAL_REPORT report;  
  42.      IOWKIT_HANDLE devHandle;
  43.      IOWKIT_HANDLE iows[IOWKIT_MAX_DEVICES];
  44.      IowKitSetLegacyOpenMode(IOW_OPEN_COMPLEX);
  45.      //devHandle = IowKitOpenDevice();      // wegen dieser zeile stürzt es ab !!
  46.      numIows = IowKitGetNumDevs();
  47.  
  48.      if(( fd = open( "/dev/usb/iowarrior1", O_RDWR)) < 0 )
  49.      {
  50.     printf( "iowarrior open failed %d\n",errno );
  51.     exit( 1 );
  52.      }
  53.      /* lets see what product we have */
  54.      if( ioctl( fd, IOW_GETINFO, &info)) {
  55.     perror( "Unable to retrieve device info" );
  56.     goto exit;
  57.      }
  58. /* print the device information */
  59.     printf("The device attached to /dev/usb/iowarrior1\n");
  60.     printf("VendorId=%04x\n",info.vendor);
  61.     printf("ProductId=%04x ",info.product);
  62.     ports=7;
  63.     printf("(IOWarrior56)\n");
  64.     printf("Serial=0x%s\nRevision=0x%04x\n",info.serial, info.revision);
  65.     printf("Speed=");
  66.     info.speed = 2;
  67.     printf("Full Speed (USB 1.1)\n");
  68.     printf("Power=%dmA\nPacketSize=%d\n",info.power, info.packet_size);
  69.     /* checking for the special-mode interface */
  70.   if(info.if_num!=1) {
  71.     printf("Opps, this is not the SpecialModes interface\n");
  72.     printf("Can't go on\n");
  73.     goto exit;
  74.   }
  75.  
  76.   if (devHandle != NULL) {
  77.     memset(&report, 0, sizeof(report));
  78.     report.ReportID = 0x08;
  79.     report.Bytes[0] = 0x01;
  80.     report.Bytes[1] = 0x07;
  81.     IowKitWrite(devHandle, IOW_PIPE_SPECIAL_MODE, (char *) &report, sizeof(report));
  82.     usleep(1000000);
  83.   }
  84.  
  85.   WriteSimple(iows[0], 0xfe);
  86.   usleep(400);
  87.  
  88.   for (i = 0; i < numIows; i++) {
  89.      printf("SPI enable\n");
  90.      report.ReportID = 0x08;
  91.      report.Bytes[0] = 0x01;
  92.      report.Bytes[1] = 0x03;
  93.      IowKitWrite(iows[i], IOW_PIPE_SPECIAL_MODE, (char *) &report, sizeof(report));
  94.      IowKitSetWriteTimeout(iows[i], 1000);
  95.    }
  96.   for (j = 0; j < numIows; j++) {
  97.      printf("programming enable\n");
  98.       memset(&report, 0, sizeof(report));
  99.       report.ReportID = 0x09;
  100.       report.Bytes[0] = 0x46;
  101.       report.Bytes[1] = 0x00;
  102.       report.Bytes[2] = 0x00;
  103.       report.Bytes[3] = 0x00;
  104.       report.Bytes[4] = 0x00;
  105.       report.Bytes[5] = 0x00;
  106.       report.Bytes[6] = 0x00;
  107.       IowKitWrite(iows[j], IOW_PIPE_SPECIAL_MODE, (char *) &report, IOWKIT_SPECIAL_REPORT_SIZE);
  108.       IowKitRead(iows[j], IOW_PIPE_SPECIAL_MODE, (char *) &report, IOWKIT_SPECIAL_REPORT_SIZE);
  109.       usleep(500);
  110.   }
  111.   printf("success\n");
  112.  
  113. exit :   close( fd );
  114.          exit(0);
  115.      return 0;
  116.  
  117.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement