hi , i am new to this forum and i am using the same code as yours, when i run this code the output comes as:-
Found tikitag!
usb: open
Now Program RUN
usb_bulk_write: Operation not permitted
xchange: Illegal seek
closing
I have disabled the functions usb_claim_interface,usb_clear_halt,usb_detach_kernel_driver,
usb_set_configuration,As they are giving me the errors,
Also Can you please tell me what to fill in the ep field of write and read functions.
Also Can you please tell me is there any doc available for the libusb ,and if so can u please send me the link.
My email id is
byatin@gmail.com
/************Code*************************?
#include <usb.h>
#include <stdio.h>
/*
* ** tiki_get_dev()
* ** find the first tiki device connected
* */
struct usb_device *tiki_get_dev()
{
struct usb_bus *busses, *bus;
struct usb_device *dev;
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
for (bus = busses; bus; bus = bus->next)
{
for (dev = bus->devices; dev; dev = dev->next)
{
if (dev->descriptor.idVendor == 0x0d49 && /* ACS */
dev->descriptor.idProduct == 0x7450) /* Tiki (ACR122) */
{
printf("Found tikitag!\n");
break;
}
printf("Searching...\n");
}
if (dev)
break;
}
return(dev);
}
/*
* ** tiki_xchange(udp, *outp, out_len, *inp, in_len)
* ** send a command to the reader and gets the answer
* ** returns 0 if all goes well; -1 if not
* */
#define TIMEOUT 20*1000 /*HZ*/
int tiki_xchange(struct usb_dev_handle* udp, u_char *outp, int out_len, u_char *inp,
int in_len)
{
int bytes_sent;
int bytes_recv;
if ((bytes_sent=usb_bulk_write(udp, 0x02 /* EP_OUT */, (char *)outp, out_len,
TIMEOUT)) < 0)
{
perror("usb_bulk_write");
return(-1);
}
printf("bytes sent: %d\n\n", bytes_sent);
int i;
if ((bytes_recv=usb_bulk_read(udp, 0x82 /* EP_IN */, (char *)inp, in_len,
TIMEOUT)) < 0)
{
perror("usb_bulk_read");
return(-1);
}
printf("bytes recv: %d\n", bytes_recv);
for (i=0;i<bytes_recv;i++)
{
printf("input[i]: %d\n", inp[i]);
}
printf("\n");
/*
* if (inp[1])
{
printf("inp[1] error\n");
return(-1); // bad status -- should set errno
}
*/
return(0);
}
/*
* **Application
* */
int main()
{
struct usb_device *dev;
struct usb_dev_handle* tiki;
static u_char outp[] = {0xFF, 0x00, 0x40, 0xD0, 0x04, 0x05, 0x05, 0x03, 0x01};
static u_char buf_in[128];
if ((dev = tiki_get_dev()) == NULL)
{
printf("Didn't Find tikitag reader...\n");
exit(-1);
}
if ((tiki = usb_open(dev)) == NULL)
{
printf("Stopped at USB Open");
perror("usb_open");
exit(-1);
}
printf("usb: open\n");
/*if ((usb_claim_interface(tiki, 0))<0)
{
perror("usb_claim_interface");
exit(-1);
}
if ((usb_clear_halt(tiki, 0x82))<0)
{
perror("usb_clear_halt");
exit(-1);
}
if ((usb_detach_kernel_driver_np(tiki, 0))<0)
{
perror("usb_detach_kernel_driver_np");
exit(-1);
}
if ((usb_set_configuration(tiki, 1))<0)
{
perror("usb_set_configuration");
exit(-1);
}*/
printf("Now Program RUN\n\n");
if (tiki_xchange(tiki, outp, sizeof(outp), buf_in, sizeof(buf_in)) < 0)
{
perror("xchange");
//exit(-1);
}
printf("closing\n");
if (usb_close(tiki) < 0)
{
perror("usb_close");
exit(-1);
}
exit(0);
}