Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <sys/ioctl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <linux/input.h>
- #include <linux/ioctl.h>
- #include <errno.h>
- #include <sys/time.h>
- #include "iowarrior.h"
- #include "iowkit.h"
- #define USB_DEVICE_ID_CODEMERCS_IOW56 0x1503
- BOOLEAN WriteSimple(IOWKIT_HANDLE devHandle, DWORD value)
- {
- IOWKIT56_IO_REPORT rep56;
- // Init report
- memset(&rep56, 0xff, sizeof(rep56));
- rep56.ReportID = 0;
- rep56.Bytes[6] = (UCHAR) value;
- return IowKitWrite(devHandle, IOW_PIPE_IO_PINS,(PCHAR) &rep56, IOWKIT56_IO_REPORT_SIZE) == IOWKIT56_IO_REPORT_SIZE;
- }
- int main (int argc, char **argv) {
- struct iowarrior_info info;
- int fd = -1;
- int i, j;
- int ports=0; //the number depends on the product
- int numIows;
- //fd_set wrfds; /* the write-set for select */
- //fd_set rfds; /* the read-set for select */
- //struct timeval tv; /* the timeout for select */
- //unsigned char buffer[64];
- IOWKIT_SPECIAL_REPORT report;
- IOWKIT_HANDLE devHandle;
- IOWKIT_HANDLE iows[IOWKIT_MAX_DEVICES];
- IowKitSetLegacyOpenMode(IOW_OPEN_COMPLEX);
- //devHandle = IowKitOpenDevice(); // wegen dieser zeile stürzt es ab !!
- numIows = IowKitGetNumDevs();
- if(( fd = open( "/dev/usb/iowarrior1", O_RDWR)) < 0 )
- {
- printf( "iowarrior open failed %d\n",errno );
- exit( 1 );
- }
- /* lets see what product we have */
- if( ioctl( fd, IOW_GETINFO, &info)) {
- perror( "Unable to retrieve device info" );
- goto exit;
- }
- /* print the device information */
- printf("The device attached to /dev/usb/iowarrior1\n");
- printf("VendorId=%04x\n",info.vendor);
- printf("ProductId=%04x ",info.product);
- ports=7;
- printf("(IOWarrior56)\n");
- printf("Serial=0x%s\nRevision=0x%04x\n",info.serial, info.revision);
- printf("Speed=");
- info.speed = 2;
- printf("Full Speed (USB 1.1)\n");
- printf("Power=%dmA\nPacketSize=%d\n",info.power, info.packet_size);
- /* checking for the special-mode interface */
- if(info.if_num!=1) {
- printf("Opps, this is not the SpecialModes interface\n");
- printf("Can't go on\n");
- goto exit;
- }
- if (devHandle != NULL) {
- memset(&report, 0, sizeof(report));
- report.ReportID = 0x08;
- report.Bytes[0] = 0x01;
- report.Bytes[1] = 0x07;
- IowKitWrite(devHandle, IOW_PIPE_SPECIAL_MODE, (char *) &report, sizeof(report));
- usleep(1000000);
- }
- WriteSimple(iows[0], 0xfe);
- usleep(400);
- for (i = 0; i < numIows; i++) {
- printf("SPI enable\n");
- report.ReportID = 0x08;
- report.Bytes[0] = 0x01;
- report.Bytes[1] = 0x03;
- IowKitWrite(iows[i], IOW_PIPE_SPECIAL_MODE, (char *) &report, sizeof(report));
- IowKitSetWriteTimeout(iows[i], 1000);
- }
- for (j = 0; j < numIows; j++) {
- printf("programming enable\n");
- memset(&report, 0, sizeof(report));
- report.ReportID = 0x09;
- report.Bytes[0] = 0x46;
- report.Bytes[1] = 0x00;
- report.Bytes[2] = 0x00;
- report.Bytes[3] = 0x00;
- report.Bytes[4] = 0x00;
- report.Bytes[5] = 0x00;
- report.Bytes[6] = 0x00;
- IowKitWrite(iows[j], IOW_PIPE_SPECIAL_MODE, (char *) &report, IOWKIT_SPECIAL_REPORT_SIZE);
- IowKitRead(iows[j], IOW_PIPE_SPECIAL_MODE, (char *) &report, IOWKIT_SPECIAL_REPORT_SIZE);
- usleep(500);
- }
- printf("success\n");
- exit : close( fd );
- exit(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement