Example #1
1
irecv_error_t irecv_receive(irecv_client_t client) {
	unsigned char buffer[BUFFER_SIZE];
	memset(buffer, '\0', BUFFER_SIZE);
	if (client == NULL || client->handle == NULL) {
		return IRECV_E_NO_DEVICE;
	}

	int bytes = 0;
	while (libusb_bulk_transfer(client->handle, 0x81, buffer, BUFFER_SIZE, &bytes, 100) == 0) {
		if (bytes > 0) {
			if (client->received_callback != NULL) {
				irecv_event_t event;
				event.size = bytes;
				event.data = buffer;
				event.type = IRECV_RECEIVED;
				if (client->received_callback(client, &event) != 0) {
					return IRECV_E_SUCCESS;
				}
			}
		} else break;
	}

	return IRECV_E_SUCCESS;
}
int SickTimCommonUsb::get_datagram(unsigned char* receiveBuffer, int bufferSize, int* actual_length)
{
  int result = libusb_bulk_transfer(device_handle_, (1 | LIBUSB_ENDPOINT_IN), receiveBuffer, bufferSize - 1, actual_length,
                                USB_TIMEOUT);   // read up to bufferSize - 1 to leave space for \0
  if (result != 0)
  {
    if (result == LIBUSB_ERROR_TIMEOUT)
    {
      ROS_WARN("LIBUSB - Read Error: LIBUSB_ERROR_TIMEOUT.");
      diagnostics_.broadcast(diagnostic_msgs::DiagnosticStatus::ERROR, "LIBUSB - Read Error: LIBUSB_ERROR_TIMEOUT.");
      *actual_length = 0;
      return EXIT_SUCCESS; // return success with size 0 to continue looping
    }
    else
    {
      ROS_ERROR("LIBUSB - Read Error: %i.", result);
      diagnostics_.broadcast(diagnostic_msgs::DiagnosticStatus::ERROR, "LIBUSB - Read Error.");
      return result; // return failure to exit node
    }
  }

  receiveBuffer[*actual_length] = 0;
  return EXIT_SUCCESS;
}
Example #3
1
const char* lcd_get_version (struct libusb_device_handle* handle)
{
    static unsigned char buf[256];

    int r, gone;

    r = libusb_bulk_transfer (handle, 1 | LIBUSB_ENDPOINT_OUT, cmd_get_version, sizeof (cmd_get_version), &gone, 1000);
    if (r < 0) {
        printf ("Send error %d\n", r);
        return NULL;
    }
    printf ("%d bytes sent\n", gone);

    return NULL;

    r = libusb_interrupt_transfer (handle, 1 | LIBUSB_ENDPOINT_IN, buf, sizeof (buf), &gone, 1000);
    if (r < 0) {
        printf ("Receive error %d\n", r);
        return NULL;
    }
//    printf ("%d bytes got\n", gone);
    buf[gone] = 0;
    return buf;
}
Example #4
0
int transfer_bulk(struct sdp_dev *dev, int report, unsigned char *p, unsigned int cnt,
		unsigned int expected, int* last_trans)
{
	int err;
	struct libusb_device_handle *h = (struct libusb_device_handle *)dev->priv;
	if (cnt > dev->max_transfer)
		cnt = dev->max_transfer;
#ifdef DEBUG
	printf("report=%i\n", report);
	if (report < 3)
		dump_bytes(p, cnt, 0);
#endif
	*last_trans = 0;
	err = libusb_bulk_transfer(h, (report < 3) ? 1 : 2 + EP_IN, p, cnt, last_trans, 1000);

#ifdef DEBUG
	if (report >= 3)
		dump_bytes(p, cnt, 0);
#endif
	return err;
}
Example #5
0
SR_PRIV int gl_read_bulk(libusb_device_handle *devh, void *buffer,
			 unsigned int size)
{
	unsigned char packet[8] =
	    { 0, 0, 0, 0, size & 0xff, (size & 0xff00) >> 8,
	      (size & 0xff0000) >> 16, (size & 0xff000000) >> 24 };
	int ret, transferred = 0;

	ret = libusb_control_transfer(devh, CTRL_OUT, 0x4, REQ_READBULK,
				      0, packet, 8, TIMEOUT);
	if (ret != 8)
		sr_err("%s: libusb_control_transfer: %s.", __func__,
		       libusb_error_name(ret));

	ret = libusb_bulk_transfer(devh, EP1_BULK_IN, buffer, size,
				   &transferred, TIMEOUT);
	if (ret < 0)
		sr_err("%s: libusb_bulk_transfer: %s.", __func__,
		       libusb_error_name(ret));
	return transferred;
}
CommandTransaction::ResultCode CommandTransaction::send(const CommandBase& command)
{
  ResultCode code = Success;

  int transferred_bytes = 0;
  int r = libusb_bulk_transfer(handle_, outbound_endpoint_, const_cast<uint8_t *>(command.data()), command.size(), &transferred_bytes, timeout_);

  if(r != LIBUSB_SUCCESS)
  {
    LOG_ERROR << "bulk transfer failed: " << WRITE_LIBUSB_ERROR(r);
    code = Error;
  }

  if((size_t)transferred_bytes != command.size())
  {
    LOG_ERROR << "sent number of bytes differs from expected number! expected: " << command.size() << " got: " << transferred_bytes;
    code = Error;
  }

  return code;
}
	bool GlobalTrainer::do_write(unsigned char* buf, int size,
	                             const std::string &name) {
		int ecode;
		int transfered = 0;

		ecode = libusb_bulk_transfer(usb_handle, 
		                             GLOBAL_TRAINER_ENDPOINT_WRITE,
		                             buf, size, &transfered, 0);
		if (ecode) {
			std::cerr << "Error writing " << name << ": "
			          << libusb_error_name(ecode) << std::endl;
		} else {
			std::cerr << "Debug: " << name << " wrote " 
			          << transfered << "/" << size 
			          << " bytes." << std::endl;
			if ( transfered == size )
				return true;
		}

		return false;
	}
Example #8
0
int KSendCommand(libusb_device_handle *handle, cmd_header& cmd, int length)
{
  uint8_t endpoint = 0x2;
  int transferred = 0;
  int timeout = 1000;

  uint8_t* p_data = (uint8_t*) (&cmd);

  printf("Cmd seq %u func %#04x (%#x)\n", cmd.sequence, cmd.command, cmd.parameter);
  int r = libusb_bulk_transfer(handle, endpoint, p_data, length, &transferred, timeout);

  if (r != LIBUSB_SUCCESS)
  {
    perr("Cmd error: %d\n", r);
    return K_ERROR;
  }

  printf("Cmd sent, %u bytes sent\n", transferred);

  return K_SUCCESS;
}
Example #9
0
static int set_data(unsigned char* data, int size)
{
	int r;
	int transferred;

	wmlog_dumphexasc(3, data, size, "Bulk write:");

	r = libusb_bulk_transfer(devh, EP_OUT, data, size, &transferred, 0);
	if (r < 0) {
		wmlog_msg(1, "bulk write error %d", r);
		if (r == LIBUSB_ERROR_NO_DEVICE) {
			exit_release_resources(0);
		}
		return r;
	}
	if (transferred < size) {
		wmlog_msg(1, "short write (%d)", r);
		return -1;
	}
	return r;
}
	bool FalconCommLibUSB::readBlocking(uint8_t* buffer, unsigned int size)
	{
		LOG_DEBUG("Reading " << size << " bytes blocking");
		if(!m_isCommOpen)
		{
			LOG_ERROR("Device not open");
			m_errorCode = FALCON_COMM_DEVICE_NOT_VALID_ERROR;
			return false;
		}

		if((m_deviceErrorCode = libusb_bulk_transfer(m_falconDevice, 0x81, buffer, size+2, &m_lastBytesRead, 1000)) != 0)
		{
			LOG_ERROR("Cannot do blocking read - Device error " << m_deviceErrorCode);
			return false;
		}
		m_lastBytesRead -= 2;
		if(m_lastBytesRead != 0)
			memcpy(buffer, buffer+2, m_lastBytesRead);
		LOG_DEBUG("Read " << m_lastBytesRead << " bytes while blocking");
		return true;
	}
Example #11
0
gboolean
arv_uv_device_bulk_transfer (ArvUvDevice *uv_device, ArvUvEndpointType endpoint_type, unsigned char endpoint_flags, void *data,
			     size_t size, size_t *transferred_size, guint32 timeout_ms, GError **error)
{
	gboolean success;
	guint8 endpoint;
	int transferred = 0;
	int result;

	g_return_val_if_fail (ARV_IS_UV_DEVICE (uv_device), FALSE);
	g_return_val_if_fail (data != NULL, FALSE);
	g_return_val_if_fail (size > 0, FALSE);

	if (uv_device->priv->disconnected) {
		g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_STATUS_NOT_CONNECTED,
			     "Not connected");
		return FALSE;
	}


	endpoint = (endpoint_type == ARV_UV_ENDPOINT_CONTROL) ? uv_device->priv->control_endpoint : uv_device->priv->data_endpoint;
	result = libusb_bulk_transfer (uv_device->priv->usb_device, endpoint | endpoint_flags, data, size, &transferred,
				       MAX (uv_device->priv->timeout_ms, timeout_ms));

	success = result >= 0;

	if (!success)
		g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_STATUS_TRANSFER_ERROR,
			     "%s", libusb_error_name (result));

	if (transferred_size != NULL)
		*transferred_size = transferred;

	if (result == LIBUSB_ERROR_NO_DEVICE) {
		uv_device->priv->disconnected = TRUE;
		arv_device_emit_control_lost_signal (ARV_DEVICE (uv_device));
	}

	return success;
}
Example #12
0
static void* canusb_capture_thread(struct canusb_t *canusb)
{
    struct libusb_context *ctx;
    libusb_device_handle *dev;
    int i, n;  
    struct 
    {
      uint8_t rxsz, txsz;
    } status;
    char *serial;
  
    libusb_init(&ctx);
  
    serial = canusb->serial;
    dev = canusb_opendevice(ctx, serial);
  
    fcntl(canusb->wrpipe, F_SETFL, O_NONBLOCK);  

    while(*canusb->loop)
    {
        int sz, ret;
        struct CAN_Msg msg;
    
        libusb_interrupt_transfer(dev, 0x81, (unsigned char*)&status, sizeof(status), &sz, 100);
        //HACK!!!!! -> drop buffered data, read new one by reading twice.        
        ret = libusb_interrupt_transfer(dev, 0x81, (unsigned char*)&status, sizeof(status), &sz, 100);                                   

        for(i = 0; i<status.rxsz; i++)
        {
            libusb_bulk_transfer(dev, 0x85, (unsigned char*)&msg, sizeof(msg), &sz, 100);      
            n = write(canusb->wrpipe, &msg, sizeof(msg));
        }

    }
  
    libusb_close(dev);
    libusb_exit(ctx);
  
    return NULL;
}
Example #13
0
int usb_send(vfs_dev_t *dev, const unsigned char *data, int length)
{
	int transferred = 0;
	
	int r = libusb_bulk_transfer(
		dev->devh, VALIDITY_SEND_ENDPOINT, 
		(unsigned char *)data, length, &transferred, VALIDITY_DEFAULT_WAIT_TIMEOUT
	);

#ifdef DEBUG
	usb_print_packet(1, r, data, length);
#endif
	
	assert(r == 0);
	
	if (r < 0)
		return r;
	if (transferred < length)
		return r;
	
	return 0;
}
Example #14
0
int motorMove(unsigned char motor = 0xff, unsigned char speed = 50, unsigned char mode = 1, unsigned char regulation = 1, unsigned char turn = 0x90)
{
    unsigned char *data = new unsigned char[9];     //data to send
    int sendAmount = 9;                             //how many data to send
    int actual, r;

    data[0] = 0x00;
    data[1] = 0x04;
    data[2] = motor;                //motor
    data[3] = speed;                //speed
    data[4] = mode;                 //mode
    data[5] = regulation;           //regulation mode
    data[6] = turn;                 //turn
    data[7] = 0x20;                 //run state
    data[8] = 0x00;                 //tacho limit

    r = libusb_bulk_transfer(dev_handle, (1 | LIBUSB_ENDPOINT_OUT), data, sendAmount, &actual, 0);

    delete[] data;

    return r;
}
Example #15
0
/**********************************************
 函数说明:通过usb写c674x的EEPROM。成功返回0,返回其他
 值都是错误的!
**********************************************/
int usb_write_i2c(struct ys_usb_handle *handle,const unsigned char *data,unsigned char addr,unsigned char count)
{
    int actual_length,ret;
    unsigned int headersize;
    unsigned int *head_ptr;
    unsigned char *buffer,rxbuf[1];
    
    headersize = sizeof(struct usb_app_header);
    buffer = (unsigned char *)malloc(count+headersize+3);
    if(buffer==NULL){
        //ysprint();
        return -1;
    }
    memset(buffer,0,count+headersize+3);
    head_ptr = (unsigned int *)buffer;
        
    head_ptr[0] = CMD_WRITE_I2C;
    head_ptr[1] = 0;
    head_ptr[2] = 0;
    head_ptr[3] = 0;    
    
    buffer[headersize] = count;
    buffer[headersize+1] = addr;
    
    memcpy(buffer+headersize+2,data,count);
    usb_write(handle,buffer,count+headersize+3);  
    
    free(buffer);
    buffer = NULL;
    
    //等待dsp返回
	ret = libusb_bulk_transfer(handle->libusb_handle,handle->Endpoint_in,rxbuf,sizeof(rxbuf),&actual_length,0);
	if(ret<0){
		return ret;
	}else{
		usleep(20000); //延时20毫秒再返回,这是因为频繁调用读写函数会出问题!
		return rxbuf[0];
	}
}
Example #16
0
File: ll_i2c.c Project: FoxVK/DFMT
static Libdfmt_error usb_com(Libdfmt_device *dev, void *buf, size_t *size,
                             int send,unsigned int timeout)
{
    int transferred;
    enum libusb_error ret;

    if(!dev || !dev->lusb_handle) return LIBDFMT_DEVICE_CLOSED;

    ret = libusb_bulk_transfer( dev->lusb_handle,
                                send ? TUNNEL_EP_OUT : TUNNEL_EP_IN,
                                (unsigned char*)buf,
                                (int)*size,
                                &transferred,
                                timeout
                               );

    if(ret)
        return lusb_error_tr(ret);

    *size = transferred;
    return LIBDFMT_OK;
}
Example #17
0
// Send some data to the USB device.
Error UsbSend(libusb_device_handle* handle, const string& s, int timeout = 0)
{
	// Send in 4096 byte chunks. Not sure where I got this from, I'm not sure it is actually necessary.
	for (unsigned int i = 0; i < s.length(); i += 4096)
	{
		string data = s.substr(i, 4096);
		int transferred;
		unsigned char endpoint = '\x01';
		int ret = libusb_bulk_transfer(handle, endpoint, reinterpret_cast<unsigned char*>(const_cast<char*>(data.c_str())),
									 data.length(), &transferred, timeout);
		if (ret != 0)
		{
			cerr << "Error writing to device: " << UsbError(ret) << endl;
			return Error("Error writing to device: " + UsbError(ret));
		}
		if ((unsigned int)transferred != data.length())
		{
			cerr << "Warning, some data not transferred correctly." << endl;
			return Error("Some data not transfered. Attempted: " + ItoS(data.length()) + " Transferred: " + ItoS(transferred));
		}
	}
	return Success;
}
bool USBTransport::data_in(QByteArray &data) {
    int ret = libusb_control_transfer(m_device, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_ENDPOINT, RequestBulkSize,
                                      0, data.size() / 1024, NULL, 0, 250);

    if(ret < 0)
        goto libusb_error;

    int transferred;

    ret = libusb_bulk_transfer(m_device, LIBUSB_ENDPOINT_IN | 0x02, (unsigned char *) data.data(), data.size(), &transferred, 250);

    if(ret < 0)
        goto libusb_error;

    data.resize(transferred);

    return true;

libusb_error:
    m_errorString = USBTransportPlugin::translate_libusb(ret);

    return false;
}
Example #19
0
int atecard_dfu_enable_inner()
{
	int         ret;
	int         actlen = 0;
	DFU_CMD_S   streq;

	if (NULL == g_usbdevhandle)
	{
		return -1;
	}

	streq.cmd = IO_DFU_CMD;
	streq.error = 0;

	ret = libusb_bulk_transfer(g_usbdevhandle, USB_IO_SET_EP, (unsigned char *)&streq, sizeof(streq), &actlen, 2000);
	if (ret < 0)
	{
		printf("send set cmd fail ret=%d\r\n", ret);
		return -1;
	}

	return 0;
}
Example #20
0
static int usb_write(char *data, int len)
{
    int n;
    //count up
    n = sprintf(transferBuf, "%d\0",count++);
    //write transfer
    //probably unsafe to use n twice...
    const int ret = libusb_bulk_transfer(handle, USB_ENDPOINT_OUT, data, len,
			&n, USB_TIMEOUT);

//    const char *err_str = libusb_error_name(ret);

    //Error handling
    switch(ret){
        case 0:
            printf("send %d bytes to device\n", n);
            return 0;
        case LIBUSB_ERROR_TIMEOUT:
            printf("ERROR in bulk write: %d Timeout\n", ret);
            break;
        case LIBUSB_ERROR_PIPE:
            printf("ERROR in bulk write: %d Pipe\n", ret);
            break;
        case LIBUSB_ERROR_OVERFLOW:
            printf("ERROR in bulk write: %d Overflow\n", ret);
            break;
        case LIBUSB_ERROR_NO_DEVICE:
            printf("ERROR in bulk write: %d No Device\n", ret);
            break;
        default:
            printf("ERROR in bulk write: %d\n", ret);
            break;

    }
    return -1;

}
Example #21
0
void pump_gdb2icdi(int endpoint)
{
    int p = 0;
    int ch;

    do {
        ch = buf[p++] = fgetc(stdin);
        if (ch == -1) {
            libusb_close(lph);
            exit(0);
        }

        if (ch == 0x03 && p < 3)
            goto sendnow;

        if (p >= sizeof(buf) - 4) {
            fprintf(stderr, "ICDI ERROR: Line too long!!\n");
            exit(1);
        }
    } while (ch != '#');

    // Next two characters are the checksum
    buf[p++] = fgetc(stdin);
    buf[p++] = fgetc(stdin);

    buf[p] = 0;
    if (trace) fprintf(stderr, "ICDI <<- %s\n", buf);

sendnow: ;
    // Send it!
    int count = 0;
    int rc = libusb_bulk_transfer(lph, endpoint, (uint8_t *) buf, p, &count, 0);
    if (rc != 0 || count != p) {
        fprintf(stderr, "ICDI send error: %s\n", libusb_error_name(rc));
        exit(1);
    }
}
Example #22
0
int
FTDIDevice_Write(FTDIDevice *dev, FTDIInterface interface,
                 uint8_t *data, size_t length, bool async)
{
   int err;

   if (async) {
      struct libusb_transfer *transfer = libusb_alloc_transfer(0);

      if (!transfer) {
         return LIBUSB_ERROR_NO_MEM;
      }

      libusb_fill_bulk_transfer(transfer, dev->handle, FTDI_EP_OUT(interface),
                                malloc(length), length, WriteAsyncCallback, 0, 0);

      if (!transfer->buffer) {
         libusb_free_transfer(transfer);
         return LIBUSB_ERROR_NO_MEM;
      }

      memcpy(transfer->buffer, data, length);
      err = libusb_submit_transfer(transfer);

   } else {
      int transferred;
      err = libusb_bulk_transfer(dev->handle, FTDI_EP_OUT(interface),
                                 data, length, &transferred,
                                 FTDI_COMMAND_TIMEOUT);
   }

   if (err < 0)
      return err;
   else
      return 0;
}
Example #23
0
int jz_upload(libusb_device_handle *dev, const char *file, unsigned long length)
{
    if(g_verbose)
        printf("Upload %lu bytes...\n", length);
    void *data = malloc(length);
    int xfered;
    int ret = libusb_bulk_transfer(dev, LIBUSB_ENDPOINT_IN | 1, data, length,
        &xfered, 10000);
    if(ret != 0)
        printf("Cannot upload data from device: %d\n", ret);
    if(ret == 0 && xfered != length)
    {
        printf("Device did not send all the data\n");
        ret = -1;
    }
    if(ret == 0)
    {
        FILE *f = fopen(file, "wb");
        if(f != NULL)
        {
            if(fwrite(data, length, 1, f) != 1)
            {
                printf("Cannot write file\n");
                ret = -3;
            }
            fclose(f);
        }
        else
        {
            printf("Cannot open file for writing\n");
            ret = -2;
        }
    }
    free(data);
    return ret;
}
Example #24
0
static void run_mainloop(struct libusb_device_handle *devh)
{
	unsigned int msg_count, byte_count = 0;
	char buf[16*265];
	int xfer_len;
	int rc;

	printf("Entering main loop\n");
	apdu_split_reset(as);

	while (1) {
		rc = libusb_bulk_transfer(devh, SIMTRACE_IN_EP, buf, sizeof(buf), &xfer_len, 100000);
		if (rc < 0 && rc != LIBUSB_ERROR_TIMEOUT) {
			fprintf(stderr, "BULK IN transfer error; rc=%d\n", rc);
			return;
		}
		if (xfer_len > 0) {
			//printf("URB: %s\n", osmo_hexdump(buf, rc));
			process_usb_msg(buf, xfer_len);
			msg_count++;
			byte_count += xfer_len;
		}
	}
}
Example #25
0
static int usb_bulk_io(usb_dev_handle *dev, int ep, char *bytes,
	int size, int timeout)
{
	int actual_length;
	int r;
	usbi_dbg("endpoint %x size %d timeout %d", ep, size, timeout);
	r = libusb_bulk_transfer(dev->handle, ep & 0xff, bytes, size,
		&actual_length, timeout);
	
	/* if we timed out but did transfer some data, report as successful short
	 * read. FIXME: is this how libusb-0.1 works? */
	if (r == 0 || (r == LIBUSB_ERROR_TIMEOUT && actual_length > 0))
		return actual_length;

	switch (r) {
	case LIBUSB_ERROR_TIMEOUT:
		return -ETIMEDOUT;
	case LIBUSB_ERROR_PIPE:
		errno = EPIPE;
		return -EPIPE;
	default:
		return r;
	}
}
Example #26
0
void netmd_transfer_song_packets(netmd_dev_handle *dev,
                                 netmd_track_packets *packets)
{
    netmd_track_packets *p;
    unsigned char *packet, *buf;
    size_t packet_size;
    int error;
    int transferred = 0;

    p = packets;
    while (p != NULL) {
        /* length + key + iv + data */
        packet_size = 8 + 8 + 8 + p->length;
        packet = malloc(packet_size);
        buf = packet;

        /* build packet... */
        netmd_copy_quadword_to_buffer(&buf, p->length);
        memcpy(buf, p->key, 8);
        memcpy(buf + 8, p->iv, 8);
        memcpy(buf + 16, p->data, p->length);

        /* ... send it */
        error = libusb_bulk_transfer((libusb_device_handle*)dev, 2, packet, (int)packet_size, &transferred, 10000);
        netmd_log(NETMD_LOG_DEBUG, "%d %d\n", packet_size, error);

        /* cleanup */
        free(packet);
        buf = NULL;

        if (error >= 0) {
            p = p->next;
        }
        break;
    }
}
Example #27
0
int slogic_set_capture(struct slogic_ctx *handle){
struct libusb_transfer *transfer;
struct slogic_command command;	
int ret,transferred;
	
	transfer = libusb_alloc_transfer(0);

	if (transfer == NULL) {
		log_printf( ERR, "libusb_alloc_transfer failed\n");
		handle->recording_state = UNKNOWN;
		ret = 1;
		return ret;
	}

	command.command = SALEAE_LOGIC_COMMAND_SET_SAMPLE_DELAY;
	command.sample_delay = handle->sample_rate->sample_delay;	

	if((ret = libusb_bulk_transfer(handle->device_handle, SALEAE_COMMAND_OUT_ENDPOINT, (unsigned char *)&command, sizeof(command), &transferred, handle->transfer_timeout))){
		log_printf( ERR, "libusb_bulk_transfer (in): %s\n", usbutil_error_to_string(ret));
		return ret;
	}
	return 0;	
	
}
Example #28
0
void UsbWrap::Receive(uchar* data, int length) throw (UsbWrapException)
{
    int returnedValue;
    int transferred;
    int received = 0;

    //    do
    //    {
    returnedValue = libusb_bulk_transfer(_handleDevice, EpBulkIn,
                                         data + received, length,
                                         &transferred, 0);

    if (returnedValue < 0)
        throw UsbWrapException(libusb_error_name(returnedValue));

    cout << "In | Transferred: " << std::dec << transferred << " | Requested: " << std::dec << length << endl;

    //        received += transferred;

    //    } while(received < length);

    //    if (received != length)
    //        throw UsbWrapException("Not received all data");
}
Example #29
0
int irecv_bulk_transfer(irecv_client_t client,
							unsigned char endpoint,
							unsigned char *data,
							int length,
							int *transferred,
							unsigned int timeout) {
	int ret;

#ifndef WIN32
	ret = libusb_bulk_transfer(client->handle, endpoint, data, length, transferred, timeout);
	if (ret < 0) {
		libusb_clear_halt(client->handle, endpoint);
	}
#else
	if (endpoint==0x4) {
		ret = DeviceIoControl(client->handle, 0x220195, data, length, data, length, (PDWORD) transferred, NULL);
	} else {
		ret = 0;
	}
	ret==0?-1:0;
#endif

	return ret;
}
Example #30
0
void UsbWrap::Send(uchar *data, int length) const throw (UsbWrapException)
{
    int returnedValue;
    int transferred;
    int sent = 0;

    //    do
    //    {
    returnedValue = libusb_bulk_transfer(_handleDevice, EpBulkOut,
                                         data + sent, length,
                                         &transferred, 0);

    if (returnedValue < 0)
        throw UsbWrapException(libusb_error_name(returnedValue));

    cout << "Out | Transferred: " << std::dec << transferred << " | Requested: " << std::dec << length << endl;

    //        sent += transferred;

    //    } while(sent < length);

    //    if (sent != length)
    //        throw UsbWrapException("Not sent all data");
}