<< bulk_read_timeout BULK Basic's commands bulk_write >>

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

bulk_write

Write or transfer a buffer to an USB Device

Calling Sequence

write_success=bulk_write(txBuff,_size);

Parameters

txBuff
: Buffer to be write 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 write into the USB Device. The type of _size has to be unsigned integer of 8 bits
write_success
: retun 0 if device has been written and -1 if the device can not be written. Check the USB device is properly connected to the host computer and properly opened.

Description

Write USB Device

Thi function write or tranfers a buffer to the HID USB Device. The device has te be conncted and properly open before the writting.

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);
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
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_timeout BULK Basic's commands bulk_write >>