usbcom = new UsbCom();
connect(usbcom,
SIGNAL(dataRecieved
(QString)),
SLOT(usbDataRecieved
(QString)));
usbcom->start();
usbcom = new UsbCom();
connect(usbcom, SIGNAL(error(QString)), SLOT(usbError(QString)));
connect(usbcom, SIGNAL(dataRecieved(QString)), SLOT(usbDataRecieved(QString)));
usbcom->start();
To copy to clipboard, switch view to plain text mode
#include "usbcom.h"
#include <QtGui>
#include "/usr/local/include/libusb-1.0/libusb.h"
#include "dataemit.h"
#include <QApplication>
#define idVENDOR 0x0483
#define idPRODUCT 0x5750
#define EP_INTR_OUT ( 1 | LIBUSB_ENDPOINT_OUT)
#define EP_INTR_IN ( 1 | LIBUSB_ENDPOINT_IN )
UsbCom::UsbCom()
{
}
void UsbCom::run()
{
int r;
int transf;
unsigned char data[2]={2,5};
r = libusb_init(NULL);
if (r < 0)
{
emit error("Failed to initialize USB!");
exit(1);
}
libusb_device_handle *devh = libusb_open_device_with_vid_pid(NULL, idVENDOR, idPRODUCT);
if(!devh)
{
emit error("Could not locate device");
exit();
}
r = libusb_kernel_driver_active (devh, 0);
if (r != 0)
{
if(r==1)
{
r = libusb_detach_kernel_driver(devh, 0);
if (r > 0)
{
emit error
("some other random error:"+ QString::number(r
));
exit(1);
}
}
}
r = libusb_claim_interface(devh, 0);
if (r < 0)
{
emit error
("usb_claim_interface error"+ QString::number(r
));
}
r = libusb_interrupt_transfer(devh, EP_INTR_OUT, data, sizeof(data), &transf,50);
emit error
("did it work? r:" + QString::number(r
));
irq_transfer = libusb_alloc_transfer(0);
unsigned char irqbuf[2];
libusb_fill_interrupt_transfer(irq_transfer, devh, EP_INTR_IN, irqbuf,sizeof(irqbuf), ep_irq_in_cb, NULL, 0);
r = libusb_submit_transfer(irq_transfer);
while(1)
{
r = libusb_handle_events(NULL);
}
}
void UsbCom::dataRecieve()
{
}
void ep_irq_in_cb(libusb_transfer *transfer)
{
if(transfer->status != LIBUSB_TRANSFER_COMPLETED)
{
// fprintf(stderr, "uncompleted transter\n");
}
//[COLOR="red"]dont know what code goes here, try to call UsbCom::DataRecieve[/COLOR]
if (libusb_submit_transfer(transfer) < 0){
fprintf(stderr,"couldnot resubmit irq \n");
exit(1);
}
}
#include "usbcom.h"
#include <QtGui>
#include "/usr/local/include/libusb-1.0/libusb.h"
#include "dataemit.h"
#include <QApplication>
#define idVENDOR 0x0483
#define idPRODUCT 0x5750
#define EP_INTR_OUT ( 1 | LIBUSB_ENDPOINT_OUT)
#define EP_INTR_IN ( 1 | LIBUSB_ENDPOINT_IN )
UsbCom::UsbCom()
{
}
void UsbCom::run()
{
int r;
int transf;
unsigned char data[2]={2,5};
r = libusb_init(NULL);
if (r < 0)
{
emit error("Failed to initialize USB!");
exit(1);
}
libusb_device_handle *devh = libusb_open_device_with_vid_pid(NULL, idVENDOR, idPRODUCT);
if(!devh)
{
emit error("Could not locate device");
exit();
}
r = libusb_kernel_driver_active (devh, 0);
if (r != 0)
{
if(r==1)
{
r = libusb_detach_kernel_driver(devh, 0);
if (r > 0)
{
emit error("some other random error:"+ QString::number(r));
exit(1);
}
}
}
r = libusb_claim_interface(devh, 0);
if (r < 0)
{
emit error("usb_claim_interface error"+ QString::number(r));
}
r = libusb_interrupt_transfer(devh, EP_INTR_OUT, data, sizeof(data), &transf,50);
emit error("did it work? r:" + QString::number(r));
irq_transfer = libusb_alloc_transfer(0);
unsigned char irqbuf[2];
libusb_fill_interrupt_transfer(irq_transfer, devh, EP_INTR_IN, irqbuf,sizeof(irqbuf), ep_irq_in_cb, NULL, 0);
r = libusb_submit_transfer(irq_transfer);
while(1)
{
r = libusb_handle_events(NULL);
}
}
void UsbCom::dataRecieve()
{
}
void ep_irq_in_cb(libusb_transfer *transfer)
{
if(transfer->status != LIBUSB_TRANSFER_COMPLETED)
{
// fprintf(stderr, "uncompleted transter\n");
}
//[COLOR="red"]dont know what code goes here, try to call UsbCom::DataRecieve[/COLOR]
if (libusb_submit_transfer(transfer) < 0){
fprintf(stderr,"couldnot resubmit irq \n");
exit(1);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks