<< bulk_read BULK Basic's commands bulk_write >>

USB Comunication Toolbox for Scilab >> BULK with libusb-1.0 Library > BULK Basic's commands > bulk_read_timeout

bulk_read_timeout

Read or receive a buffer from an USB Device with timeout

Calling Sequence

[rxBuff,read_success]=bulk_read_timeout(_size,_timeout);

Parameters

rxBuff
: Buffer to be read or transfer to the USB Device. The type of the data in the buffer has to be unsigned integer of 8 bits
_size
: Size of the buffer to be read into the USB Device. The type of _size has to be unsigned integer of 8 bits
_timeout
: milliseconds timeout in milliseconds or -1 for blocking wait. The type of _size has to be integer of 32 bits
read_success
: retun 0 if device has been read and -1 if the device can not be read. Check the USB device is properly connected to the host computer and properly opened.

Description

Read an USB Device

Read the data buffer sent by the USB Device

Keep in mind that USB 2.0 and older are a master/slave protocol. The USB device will send data only if the master (the host, its mean the computer), asked for it.

Examples

n=5;
txBuff=init_buff(n);
for i=1:n
    txBuff=setBuffValue(txBuff,i,i);
end
VendorID="04D8";
ProductID="0204";
VendorID=uint16(hex2dec(VendorID));
ProductID=uint16(hex2dec(ProductID));
enpIn=1;
enpOut=1;
enpIn=uint16(enpIn);
enpOut=uint16(enpOut);
timeout=100;
timeout=int32(timeout);
n=uint8(n)
init_success=bulk_init();
if ( init_success < 0 ) then
   disp("unable to initialize the Libusb-1.0 Library");
   return
else
   disp("Libusb-1.0 Library initialized");
end
open_success=bulk_open(VendorID,ProductID);
if ( open_success < 0 ) then
   disp("unable to open device");
   return
else
   disp("device open");
end
endP_success=bulk_set_endpoint(enpIn,enpOut);
if ( endP_success < 0 ) then
   disp("unable to set end points");
else
   disp("end points has been set");
end
write_success=bulk_write(txBuff,n);
if ( write_success < 0 ) then
   disp("unable to write device");
else
   disp("device have been  written");
end
[rxBuff,read_success]=bulk_read(n,timeout);
if ( read_success < 0 ) then
   disp("unable to read device");
else
   disp("device have been read");
   disp(rxBuff);
end
close_success=bulk_close();  
if ( close_success < 0 ) then
   disp("unable to closed device");
else
   disp("device closed");
end
exit_success=bulk_exit();
if ( init_success < 0 ) then
   disp("unable to free static data associated with Libusb-1.0 Library");
   return
else
   disp("Libusb-1.0 Library have been freed all of the static data associated");
end

See Also

Authors

<< bulk_read BULK Basic's commands bulk_write >>